开发者

Apache Camel - Routing messages to JPA endpoint - keeping orders but splitting into pools based on a category header

We have simple project which takes a number of messages from a number of endpoints(agents). These agents all output the same format message (an entity object to be placed in a database). All the agents write to the one queue and we consume these and send them to a database via JPA.

So essentially the system has a collection of producers writing messages to one queue. The queue is single threaded and just takes the messages as they come and dumps them into the database.

The issue here is this method is slow. Is there any functionality in Camel (like re-sequencing) that we could use to split out these messages based on their source. So while the messages from Agent1 need to be persisted in the order they are created, the messages from Agent2 are separate so they should not wait on the order of Agent1's messages. For two agents this is an easy problem as we just create two queues, one for each agent. We have a number of agents, so we need a solution that can scale.

Are there any patterns to accomplish this natively in camel? We could write our own holdout queue which syncs on the Agent name and only ever puts one message through to a multi-threaded JPA write queue, but this would be a bit of a round-about way to do things as we would need to either setup a callback from the queue to jpa camel route or we would not use camel an开发者_StackOverflowd just do it via our own manager (not that this would be complex, but it would be great if we could do this all using Camel or something else out there and not have to reinvent the wheel so to speak).


If you source is a JMS message queue, then take a look at message groups

Apache ActiveMQ documents about this here: http://activemq.apache.org/message-groups.html

And this FAQ http://activemq.apache.org/how-do-i-preserve-order-of-messages.html

Basically you can use the JMSXGroupID JMS property to mark the agent id, eg agent1, agent2, etc.

Then you can have concurrent consumers on the JMS message queue, which can run in parallel based on the JMSXGroupID. But still preserve ordering within each group. That means you can in parallel write to JPA agent1, agent2, ... agentN.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜