Hi

See https://issues.apache.org/jira/browse/CAMEL-3790 and
http://camel.apache.org/using-camelproxy.html

If you use Camel proxy (eg to use a pojo as facade to send messages to
Camel) then we didn't support Future as return types,
in the sense Camel will be able to "detect" this and and process the
invocation asynchronous. What happens is that Camel
process synchronous and return back the Future when the message is done.

So I have experimenting adding support for detecting Future in the
return type of the client proxy interface. And be able
to process the message using a thread pool, and return back a Future
handle to the client.

For example this interface

    public static interface Echo {
        Future<String> asText(int number);
    }


Will now pass this unit test

    public void testFutureEcho() throws Exception {
        Echo service =
ProxyHelper.createProxy(context.getEndpoint("direct:echo"),
Echo.class);

        Future future = service.asText(4);
        log.info("Got future");
        assertFalse("Should not be done", future.isDone());
        log.info("Waiting for future to be done ...");
        assertEquals("Four", future.get(5, TimeUnit.SECONDS));
    }


As without the Future support it will not pass the unit test. What
happens instead is that this call
        Future future = service.asText(4);
Will happen synchronously so the future handle returned is when the
processing is already done.


However I wonder if we should add this support in the code base, as
how many people develop client interfaces using Future API from the
JDK?
But nevertheless its still cool that we can support this.

The ProducerTemplate API has plenty of APIs for asynchronous
processing. So end users can use that. However the Camel proxy allows
to hide
all that behind a simple interface the client can use. And then Future
in the return type makes sense to indicate its an asynchronous
invocation.

Any thoughts?






-- 
Claus Ibsen
-----------------
FuseSource
Email: cib...@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Reply via email to