You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by mortalisk <mo...@gmail.com> on 2017/05/10 07:46:16 UTC

Async bean method

Hi, I am trying to return CompletableFuture from my bean method in order to
be able to consume more messages while processing while processing previous
ones. However, I see no difference in behaviour. I seems the consumer thread
is waiting for the future to complete.

What is the purpose of the ability to return CompletableFuture from bean
methods? Am I seeing the expected behaviour?

See the headline Asynchronous processing here:
http://camel.apache.org/bean-binding.html



--
View this message in context: http://camel.465427.n5.nabble.com/Async-bean-method-tp5799201.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Async bean method

Posted by mortalisk <mo...@gmail.com>.
I found that the queue can not be transacted=true to have async processing.
When I turned this off, messages are consumed asynchronously. Thanks for you
help :)



-----
Morten Bendiksen
--
View this message in context: http://camel.465427.n5.nabble.com/Async-bean-method-tp5799201p5799303.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Async bean method

Posted by mortalisk <mo...@gmail.com>.
I added the "?asyncConsumer=true", and saw no difference. Still only one
message is picked at a time per queue. "concurrentConsumers" would add more
actual threads listening to the queue, right? I would prefer to simply pick
messages with one thread, and hand of work to be processed asynchronously in
a separate thread pool.



-----
Morten Bendiksen
--
View this message in context: http://camel.465427.n5.nabble.com/Async-bean-method-tp5799201p5799275.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Async bean method

Posted by Zoran Regvart <zo...@regvart.com>.
Hi Morten,
are you using the JMS component? Take a look at `concurrentConsumers`
and `asyncConsumer` properties[1],

zoran

[1] https://camel.apache.org/jms.html#JMS-ConcurrentConsuming

On Wed, May 10, 2017 at 4:20 PM, mortalisk <mo...@gmail.com> wrote:
> Guess I am mistaken about whenComplete blocking the thread. I thought that
> was the difference of *Async and not in the CompletableFuture, so never mind
> that.
>
> However I still see this behaviour where only one message is processed at a
> time, even though all the code is running in a separate thread pool.
>
>
>
> -----
> Morten Bendiksen
> --
> View this message in context: http://camel.465427.n5.nabble.com/Async-bean-method-tp5799201p5799235.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Zoran Regvart

Re: Async bean method

Posted by mortalisk <mo...@gmail.com>.
Guess I am mistaken about whenComplete blocking the thread. I thought that
was the difference of *Async and not in the CompletableFuture, so never mind
that. 

However I still see this behaviour where only one message is processed at a
time, even though all the code is running in a separate thread pool.



-----
Morten Bendiksen
--
View this message in context: http://camel.465427.n5.nabble.com/Async-bean-method-tp5799201p5799235.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Async bean method

Posted by mortalisk <mo...@gmail.com>.
My route:


In the executor bean (only message type was changed to :


It definitely seems to only run the "process" method one by one. I added a
sleep in "preProcess" (which is inside the "thenApplyAsync" so it should not
block the camel thread, which would make it wait for that much longer until
next message would start. I would expect it to call the "process" for each
item in the queue immediately.

I looked at the camel code and found this line:
https://github.com/apache/camel/blob/master/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java#L324

I'm not sure if this is the code that is involved, but that would block the
thread if I'm not mistaken.








--
View this message in context: http://camel.465427.n5.nabble.com/Async-bean-method-tp5799201p5799233.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Async bean method

Posted by Zoran Regvart <zo...@regvart.com>.
Hi Morten,
are you sure about this? Could it be that your own code is blocking
the consumer.

I just run a simple example with the file consumer and an bean
processor returning CompletionStage.
From what I observe is that the consumer thread keeps polling the
filesystem even if I sleep in the thread that the producer bean
started for the CompletionStage.

Can you share your route and the code of the bean that's performing
the processing?

zoran

On Wed, May 10, 2017 at 9:46 AM, mortalisk <mo...@gmail.com> wrote:
> Hi, I am trying to return CompletableFuture from my bean method in order to
> be able to consume more messages while processing while processing previous
> ones. However, I see no difference in behaviour. I seems the consumer thread
> is waiting for the future to complete.
>
> What is the purpose of the ability to return CompletableFuture from bean
> methods? Am I seeing the expected behaviour?
>
> See the headline Asynchronous processing here:
> http://camel.apache.org/bean-binding.html
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Async-bean-method-tp5799201.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Zoran Regvart