I am reviewing a client-server application written in Java. The server receives JMS messages and processes them but the messages can come in an unexpected order, and a cancel can arrive before an order message. How do you handle such a case? Do you do it in the mdb?
What are some strategies or patterns for this kind of scenario?
So far I know, this is refereed to as “out-of-order” delivery and is part of the quality of service (QoS) attributes of the JMS system. I don’t think it’s part of the JMS specification, but some provider support it maybe. That will depend on the particular JMS implementation you use.
Note however that JMS is meant to distribute messages to several consumers in a way to distribute the load. If message have to be delivered in an ordered fashion this is not possible — it basically lead to serialization of the message delivery and message could not be processed concurrently.
The wikipedia says it better than me:
Out-of-band cancel request is not easy to achieve with JMS then. Two ideas:
Otherwise, have maybe a look at the message store pattern. It’s anyway worth checking the EAI website.