JMS Message Processing and Maintaining Message Order


General J2EE: JMS Message Processing and Maintaining Message Order

  1. For a particular application, it is important that JMS messages are processed in the order that they were produced. It appears upon initial inspection, that by using message beans, it is possible for processing order to be indeterminate. If you have a message bean pool size > 1, messages will be processed concurrently, and it is possible for the processing of a later message to complete before the processing of an earlier one, thus changing the order of the intended actions associated with the messages.

    Am I misisng something here, are there other alternatives ? Any solutions ?
  2. You right, the only way to ensure that messages are processed in the same order as they are created is to ensure you only have one Message Producer and one Message Consumer.

    Basically the messages will only maintain the order they are put on and taken off the queue, after that its a bun fight as to which Message Consumer runs. If you worried about performance then the only solution is to have multiple message streams, it's probably easier if I give an example.

    I once developed an Order processor that required each order for the same customer to be processed sequencially so I create 10 queues (you can have any number) with 10 Message Consumers, one bound to each queue. Unfortunately you can still only have one Message Producer which does a hash on the Customer Id to ensure that all the messages for same Customers went onto the same queue.

    Hope this helps

  3. You may want to take a look at Collaxa's orchestration server that deals with asynchronous interactions and control flow of JMS using the Scenario Bean abstraction.