You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by arthurs <ar...@nytimes.com> on 2015/01/20 17:12:12 UTC

How to handle requests sequentially for a given item

I need to only execute one route request at a time for a given item (ie
object processed by the route).  So, if the second request with same item id
comes in, it waits until the first one completes before continuing with
processing.

I understand that I can use onCompletion and thread libraries to implement
this, but was wondering if there is a more elegant solution.



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-handle-requests-sequentially-for-a-given-item-tp5761955.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to handle requests sequentially for a given item

Posted by arthurs <ar...@nytimes.com>.
We're already using activemq as our incoming destination.  The issue is that
we also set concurrentConsumers > 1 and asyncConsumer=true.  Would Message
groups still work?  Or do we need to set asyncConsumer=false?



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-handle-requests-sequentially-for-a-given-item-tp5761955p5761961.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to handle requests sequentially for a given item

Posted by Jakub Korab <ja...@gmail.com>.
If you have access to ActiveMQ you could try putting the requests onto a
JMS queue, and using Message Groups
(http://activemq.apache.org/message-groups.html). Putting the item id in
the JMSXGroupId header will ensure that only one JMS consumer processes
the total set of messages for that item id sequentially.

The Camel code is then really straightforward.

from(...)
    .setHeader("JMSXGroupId", simple("${body.itemId}"))
    .to("jms:items");

from("jms:items")...

Jakub

On 20/01/15 16:12, arthurs wrote:
> I need to only execute one route request at a time for a given item (ie
> object processed by the route).  So, if the second request with same item id
> comes in, it waits until the first one completes before continuing with
> processing.
>
> I understand that I can use onCompletion and thread libraries to implement
> this, but was wondering if there is a more elegant solution.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-to-handle-requests-sequentially-for-a-given-item-tp5761955.html
> Sent from the Camel - Users mailing list archive at Nabble.com.