Since we're on a major migration process of this website, some component documents here are out of sync right now. In the meantime you may want to look at the early version of the new website
https://camel.apache.org/staging/
We would very much like to receive any feedback on the new site, please join the discussion on the Camel user mailing list.
ToAsyncAvailable as of Camel 2.1 To be removed Unfortunately this feature did not work out, and is going to be replaced with a new fully asynchronous routing engine in Camel 2.4. BackgroundToAsync is a new feature build into the core of Camel 2.1. It sets the foundation base for non blocking asynchronous Request Reply messaging with Camel. By foundation we mean that it has the moving pieces that makes Camel Components leverage this in case they natively supports non blocking request reply. At this time of writing its only the Jetty component that offers this. Over time we will incorporate this into other components. However don't despair as Camel have fallback support for simulating asynchronous request/reply in the Camel core, in cases where its not supported natively in the Camel component used. May change in the future How does it work?Camel now has a new DSL named The route below is from a unit test in Camel. Notice the new from("direct:start").to("mock:a").toAsync("direct:bar", 5).to("mock:result"); from("direct:bar").to("mock:b").transform(constant("Bye World")); This unit test is using the direct endpoint when sending using By using a component that truly supports non blocking Request Reply such as Jetty, its in fact Jetty itself that handles the Request Reply so the internal thread pool in Camel is not used. The HTTP Async ExampleIn this example we use the following route: <route> <!-- we route from a direct endpoint --> <from uri="direct:start"/> <!-- log the request --> <to uri="log:+++ request +++"/> <!-- then doing a non blocking async request/reply to the http server with a pool of 10 threads --> <to uri="jetty://http://0.0.0.0:9123/myapp" async="true" poolSize="10"/> <!-- the reply from the server is logged --> <to uri="log:+++ reply +++"/> <!-- and to our mock so we can assert we got all responses --> <to ref="result"/> </route> Notice how we have specified How this works inside CamelCamel uses the void process(Exchange exchange, AsyncCallback callback) throws Exception; The idea is that you invoke the callback when the reply is ready. The void onTaskCompleted(Exchange exchange); which is the method to invoke when the reply is ready. All the other moving parts is build directly into the core of Camel. So you do not have to worry about that. JettyHttpProducerThis class is currently the only implementation of this feature. Basically you do implement the public class JettyHttpProducer extends DefaultProducer implements AsyncProcessor And then invoke the callback when the reply is ready and populated on the Exchange. What if a Component does not support non blocking?Many components does not naturally support non blocking Request Reply. The ones that does need to be improved in Camel to support the Configuring thread poolingYou configure the thread pool on the from("direct:start").to("mock:a").toAsync("direct:bar").executorServiceRef("mySharedPool").to("mock:result"); In the Spring XML there is an attribute to refer to the thread pool <to uri="jetty://http://0.0.0.0:9123/myapp" async="true" executorServiceRef="mySharedPool"/> See also
|