Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Effective JMS processing

We have a JMS queue which receives a very large number of messages.

Listener has to save message in database using a database transaction and then commit JMS transaction.

So how can i do it more effectively where i don't have to do database & JMS commit on each message.

like image 301
changed Avatar asked Mar 08 '11 22:03

changed


People also ask

What is JMS processing?

JMS is the standard Java™ EE messaging API for building enterprise messaging applications. IBM® App Connect Enterprise provides built-in input and output nodes for its supported protocols.

Does JMS define the order of message reception?

JMS does not define order of message receipt across destinations or across a destination's messages sent from multiple sessions. This aspect of a session's input message stream order is timing-dependent. It is not under application control.


1 Answers

Don't do it on each message, do it in batches. JMS supports transactions just like your DB does; start a JMS transaction, read N messages. Start DB transaction, insert N messages. Commit to JMS, commit to DB.

This obviously introduces a window for a race to occur (crash happens between the two commits). You have that now, but only for a single message. If you want to solve that problem you're faced with either looking at XA transactions (two phased commit) or at the very least some sort of duplicate detection scheme. For some intro to that, take a look at: http://activemq.apache.org/should-i-use-xa.html

like image 60
Brian Roach Avatar answered Oct 05 '22 23:10

Brian Roach