Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Wiki Markup
{snippet:id=e3|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanProxyTest.java}

Isn't this cool?

Asynchronous using Future

Available as of Camel 2.8

By default the Camel Proxy invocation is synchronous when invoked from the client. If you want this to be asynchronous you define the return type to be of java.util.concurrent.Future type. The Future is a handle to the task which the client can use to obtain the result.

For example given this client interface

Wiki Markup
{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ProxyReturnFutureTest.java}

The client can use this with a Camel Proxy as shown from the following snippet from an unit test:

Wiki Markup
{snippet:id=e2|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ProxyReturnFutureTest.java}

This allows you to fully define your client API without any Camel dependency at all, and decide whether the invocation should be synchronous or asynchronous.

If the Client is asynchronous (return type is Future) then Camel will continue processing the invocation using a thread pool which is being looked up using the key CamelInvocationHandler. Its a shared thread pool for all Camel Proxy in the CamelContext. You can define a thread pool profile with the id CamelInvocationHandler to configure settings such as min/max threads etc.

See also