Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read messages in an order from the Queue using MDB?

I have a MDB which listens to WebSphere MQ. It does not picks up the messages in the order that has been received by the Queue. How can i make it read it in that order? Is it possible? Should i not use a MDB.

like image 328
Vijayakumar G Avatar asked Nov 30 '10 07:11

Vijayakumar G


People also ask

How do I check my message queue?

In the Content view, right-click the local queue Q1, then click Put Test Message. The Put test message dialog opens. In the Message data field, type some text, for example this is a test message , then click Put message. The Message data field is cleared and the message is put on the queue.

What is message queue channel?

Channels are objects that provide a communication path from one queue manager to another. Channels are used in distributed queuing to move messages from one queue manager to another and they shield applications from the underlying communications protocols.


2 Answers

In general, WMQ delivers messages in the order that they were received. However, several things can impact that...

  1. If the queue is set to priority instead of FIFO delivery and messages arrive in different priorities, they will be delivered "out of order".
  2. Distinguish between order produced and order delivered. If the messages are produced on a remote QMgr and there are multiple paths to the local QMgr, messages may arrive out of order.
  3. Difference in persistence - if messages are produced on a remote QMgr and are of different persistences, the non-persistent messages may arrive faster than the persistent ones, especially with channel NPMSPEED(FAST) set.
  4. Multiple readers/writers - Any dependency on sequence implies a single producer sending to a single consumer over a single path. Any redundancy in producers, consumers or paths between them can result in messages delivered out of sequence.
  5. Syncpoint - To preserve sequence, ALL messages must be written and consumed under syncpoint or else ALL must be written and consumed outside of syncpoint.
  6. Selectors - These specifically are intended to deliver messages out of order with respect to the context of all messages in the queue.
  7. Message groups - Retrieval of grouped messages typically waits until the entire group is present. If groups are interleaved, messages are delivered out of sequence.
  8. DLQ - if the target queue fills, messages may be delivered to the DLQ. As the target queue is drained, messages start going back there. With a queue near capacity, messages can alternate between the target queue and DLQ.

So when an MDB is receiving messages out of order any of these things, or even several of them in combination, may be at cause. Either eliminate the dependency on message sequence (best choice) or else go back over the design and reconcile all the factors that may lead to out-of-sequence processing.

like image 127
T.Rob Avatar answered Dec 28 '22 07:12

T.Rob


To add to T.Rob's list, MDBs use the application server WorkManager to schedule message delivery, so message order is also dependent on the order in which the WorkManager starts Work items. This is outside the control of WMQ. If you limit the MDB ServerSessionPool depth to one, then this limit is removed as there will only ever be one in-flight Work instance, but at the cost of reducing maximum throughput.

If you're running in WebSphere application server, then non-ASF mode with ListenerPorts can preserve message order subject to some transactional/backout caveats. There's a support technote here:

http://www-01.ibm.com/support/docview.wss?uid=swg21446463

like image 43
strmqm Avatar answered Dec 28 '22 06:12

strmqm