MQ Queue with multiple consumers but only one active

杀马特。学长 韩版系。学妹 提交于 2019-12-04 09:02:12

Create a second queue, we'll call it the "control queue." Into this queue, put a single message, we'll call it the "token." Change application processing as follows:

  1. Listen on the control queue for a message.
  2. Get the token from the control queue under syncpoint.
  3. Put the same token message back on the control queue, also under syncpoint.
  4. Process a transaction from the normal input queue, also under syncpoint.
  5. COMMIT the messages.
  6. Loop.

The COMMIT completes the transaction on the input queue and makes the token available to the other MDBs. No processing of the input queue can occur except by the MDB that has the token under syncpoint. However you can have any number of MDBs waiting on the token. A failure of any one of them allows the others to take over instantly.

No need to use XA, by the way. WMQ's single-phase COMMIT works great with this.

When applications are trying to use the queue through their MDB listeners, we can restrict them by defining the queue with DEFSOPT(Exclusive). This will make sure that only one application can consume messages from that queue.

If we wish to restrict to only one instance of the application, define it as NOSHARE. So that, one instance of one application can get hold of messages on the queue at a time. Others will get their turn when current one releases the lock.

in my opinion synchronizing multiple consumers is not a big problem and is the most efficient solution. I don't know where processing result have to be recorded (maybe JMS queue again ? ), but i would try to use a lightweitght agent before that point. You can use timestamps or implement a counter over JMS to preserve order. Consumers could execute in parallel and then post in a support queue. Than the single agent can order them using a queuebrowser and then a transaction. This agent should be "wathdogged".

Alessandro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!