1

I had a problem in implementation of dead letter queue in IBM MQ in .net6. I am using IBMMQDotnetClient library from nuGet. The problem is that when we face to any message which is not successfully commited, the message from queue continues in while(true). I want to get the message to dead letter queue and continue to next messages from the queue. how can I use dead letter queue for this issue in .net6 project ?

  • If I remember correctly, you have to handle poison messages on your on in plain MQ .NET API. I highly recommend to use the MQ .NET **XMS** API, which handles poison messages out of the box if the queue is configured correctly, see [Poison messages in XMS](https://www.ibm.com/docs/en/ibm-mq/9.3?topic=consumers-poison-messages-in-xms). – Daniel Steinmann Jan 18 '23 at 08:50
  • do you have an example of code for you claim ? can you share here ? – Hafizullah Ozgur Jan 18 '23 at 11:44
  • Follow the link to the IBM MQ documentation from my first comment. In the IBM MQ XMS documentation chapters you find more example code. – Daniel Steinmann Jan 18 '23 at 13:39

1 Answers1

2

When you use XMS you get the IBM MQ XMS library handling of backout threshold and backout.

See https://www.ibm.com/docs/en/ibm-mq/latest?topic=consumers-poison-messages-in-xms

You need to set BOTHRESH and BOQUEUE for your queue. This will be an MQ admin job. Then when read attempts for any message exceed the threshold the message is requeued to the backout queue. If the requeuing fails for any reason, the message is removed from the input queue and either requeued to the dead-letter queue, or discarded.

The only code change needed is to signal when a message can't be processed. You will need to transaction enable the session.

sessionWMQ = connectionWMQ.CreateSession(true, AcknowledgeMode.SessionTransacted);

commit good messages

sessionWMQ.Commit();

rollback (and signal a read failure) bad messages

sessionWMQ.Rollback();

To get you started there is a set of XMS samples that don't have transactions enabled at https://github.com/ibm-messaging/mq-dev-patterns/tree/master/dotnet

chughts
  • 4,210
  • 2
  • 14
  • 27
  • Thank you a lot, I am evaluating the codes in the link. as soon as I come to a solution with this I will resolve the issue putting a tick by the name of you. – Hafizullah Ozgur Jan 20 '23 at 11:10