Announcement Announcement Module
No announcement yet.
spring jms message ordering when multiple MDB cosumes from the same queue Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • spring jms message ordering when multiple MDB cosumes from the same queue


    Can anyone post your comments on how to implement the message consuming order using spring jms for the below scenerio.

    1. Joe clicks the order button from his shopping cart.
    2. The order message (message A) is placed on Queue1.
    3. Joe cancels the order.
    4. The cancel order (message B) is placed on Queue1.
    5. MdbX takes message A from Queue1.
    6. MdbY takes message B from Queue1.
    7. MdbY writes the cancel message to the database. Because there is no corresponding order message, there is no order message to remove from the database.
    8. MdbX writes the order message to the database.
    9. An application responsible for shipping books reads the database, sees the order message, and initiates shipment to Joe’s home.

    Where multiple MDB's are pointing to the same queue and consumes the message as and whne it comes. So it will ends up issuing the order and its doesn't aware of cancellation. Valuable suggestions most welcome.

  • #2
    You can't make assumptions about ordering unless you serialize puts and gets from the queue. Serialization will guarantee correctness but it doesn't scale terribly well.

    There are several ways to handle the scenario that you are looking at. One is to put logic in your message handling that will throw an exception if a message purports to make an illegal state change (e.g. cancelling an order that hasn't been placed yet). Typically, you can have the handler (MDB) throw an exception in this case so the message will be redelivered, hopefully after the 'place order' message is received and processed. Various containers and JMS providers provide different control of message redelivery semantics so you'll have to look into this for your situation.


    • #3
      Can you use the JMSXGroupID property to guarantee that the cancellation isn't processed until the order is acknowledged? You'd need to provide a unique group ID for that customer's session, and within that session provide a numerical ordering to the actions.