Hi I have uploaded a 2nd patch at CAMEL-1572 - (the b patch) I got the async API prototype also.
On Thu, Apr 30, 2009 at 5:39 PM, Claus Ibsen <[email protected]> wrote: > On Thu, Apr 30, 2009 at 4:00 PM, Willem Jiang <[email protected]> wrote: >> How about introducing Async requestBody API to the template? >> It just return a Future object, then we can turn the value of Future >> into what we want. > Good idea. In fact I have done that already. > > Future<Object> requestAsyncBody(String endpoint, Object body); > > But I wanted to start with a "raw" Exchange at first. > The idea is to have similar methods as the regular producer template, > so you can shoot in headers as well. > > There is though something to think a bit more about is the exchange > patterns for inOnly how that can still have the need to return the > Future object as you might want to know when or if the task is done, > even thought there is no response for you. > > So instead of void as return its probably gonna be something like Future. > > I will later add another patch at the CAMEL-1572 ticket so you can > take a closer look at my experiments. > > > > > >> >> Willem >> >> Claus Ibsen wrote: >>> Hi >>> >>> Its me again. Yeah I am due for a run in due time, but just wanted to >>> demo something that is either powerful or scary >>> >>> The code below uses the same route. But as we request a body and we >>> have declared we want the response as a String.class (the last >>> parameter) >>> Then Camel is "clever" or "scary" to use the Future to wait and get >>> the result and convert the body to the desired type, eg a String. >>> >>> So the routing is really divided into sync/async but the end user sees >>> it as a single sync. >>> >>> public void testAsyncRouteWithTypeConverted() throws Exception { >>> MockEndpoint mock = getMockEndpoint("mock:result"); >>> mock.expectedBodiesReceived("Bye World"); >>> >>> // send a request reply to the direct start endpoint, but will use >>> // future type converter that will wait for the response >>> String response = template.requestBody("direct:start", >>> "Hello", String.class); >>> assertEquals("Bye World", response); >>> >>> assertMockEndpointsSatisfied(); >>> } >>> >>> So whats next is that you can just pass in the Future<String.class> to >>> instruct Camel that you want the future handle back >>> and that it should return a String as the response. >>> >>> Then Camel should be able to take it from there. With the future >>> handle the caller gets back in control when the routes hits the >>> async() DSL. >>> And can do other work as he like. >>> >>> And when he want the response, he just: >>> Future<String> future = template.requestBody("direct:start", "Hello", >>> Future<String>.class); >>> >>> String response = future.get(); >>> >>> But then I guess this is impossible due to type erasure in java generics :( >>> No its not!!! >>> >>> Okay time to hit the streets >>> >>> >> >> > > > > -- > Claus Ibsen > Apache Camel Committer > > Open Source Integration: http://fusesource.com > Blog: http://davsclaus.blogspot.com/ > Twitter: http://twitter.com/davsclaus > Apache Camel Reference Card: > http://refcardz.dzone.com/refcardz/enterprise-integration > -- Claus Ibsen Apache Camel Committer Open Source Integration: http://fusesource.com Blog: http://davsclaus.blogspot.com/ Twitter: http://twitter.com/davsclaus Apache Camel Reference Card: http://refcardz.dzone.com/refcardz/enterprise-integration
