Reputation: 715
I have a scenario where we have two MQ listeners in our application. One of them is doing some added processing(database tables update), day queue A and the other one is not, say queue B. The issue is we just have one thread(the main thread for both of these) and message is sent to the A first. So by the time the code reaches the point where it’s going to process/update message received on A, message on B arrives and hence the update never goes through. How can I make sure that the processing occurs for messages on A even while B received messages?
Thanks
Upvotes: 1
Views: 322
Reputation: 1157
If you must use one thread to process all messages you should use synchronous api calls like this:
long timeoutForA, timeoutForB ...
MessageConsumer consumerA, consumerB ....
while (true) {
Message msgFromA = consumerA.receive(timeout);
if (msgFromA == null)
break;
... do something with message from A ...
}
while (true) {
Message msgFromB = consumerB.receive(timeout);
if (msgFromB == null)
break;
... do something with message from B ...
}
However I would not recommend this approach to business logic as in general. Properly designed messaging system should be able process unrelated messages asynchronously.
Upvotes: 1
Reputation: 305
It depends on language that you use.
If you use C you can try to use callbacks.
https://www.ibm.com/support/knowledgecenter/SSFKSJ_9.0.0/com.ibm.mq.dev.doc/q023050_.htm
Upvotes: 0