Requeue Ibm MQ Message

Viewed 57

We are running multiple instances of a windows service that reads messages from a Topic, runs a report, then converts the results into a PDF and emails them to a user. In case of exceptions we simply log the exception and move on.

The use case we want to handle is when the service is shut down we want to preserve the jobs that are currently running so they can be reprocessed by another instance of the service or when the service is restarted.

Is there a way of requeueing a message? The hacky solution would be to just republish the message from the consuming service, but there must be another way.

When incoming messages are processed, their data is put in an internal queue structure (not a message queue) and processed in batches of parallel threads, so the IbmMq transaction stuff seems hard to implement. Is that what I should be using though?

2 Answers

Your requirement seems to be hard to implement if you don't get rid of the "internal queue structure (not a message queue)" if this is not based on a transaction oriented middleware. The MQ queue / topic works well for multi-threaded consumers, so it is not apparent what you gain from this intermediate step of moving the data to just another queue. If you start your transaction with consuming the message from MQ, you can have it being rolled back when something goes wrong.

If I understood your use case correctly, you can use Durable subscriptions:

Durable subscriptions continue to exist when a subscribing application's connection to the queue manager is closed.

The details are explained in DEFINE SUB (create a durable subscription). Example:

DEFINE QLOCAL(THE.REPORTING.QUEUE) REPLACE DEFPSIST(YES)

DEFINE TOPIC(THE.REPORTING.TOPIC) REPLACE +
   TOPICSTR('/Path/To/My/Interesting/Thing') DEFPSIST(YES) DURSUB(YES)

DEFINE SUB(THE.REPORTING.SUB) REPLACE +
   TOPICOBJ(THE.REPORTING.TOPIC) DEST(THE.REPORTING.QUEUE)

Your service instances can consume now from THE.REPORTING.QUEUE.

Related