WebSphere MQ .NET client - Backout queue not working - ibm-mq

I am not familiar with MQ so forgive me if I'm not explaining myself properly. We have received a message on a queue that is failing when being read with a 2110 MQRC_FORMAT_ERROR. It would seem that the problem is it doesn't have a 'Format' specified, e.g. we are expecting 'MQSTR'. The client code (C#) is catching the MQException and doing a MQQueueManager.Backout() however the message is just going back onto the queue and being read and rejected again by the client.
Looking at the queue I saw that it did not have a backout queue or backout threshold set. The queue manager also did not have a dead letter queue set. So what I've done is setup the DLQ and set the queue's backout queue to it with a backout threshold of 5. However the message is still stuck on the queue being continually read and put back. The backout count for the message is currently approaching 20 million.
I would like to get the backout and DLQ working but if there is another method to just manually delete or move this message that would help for now. It is just a test message so it doesn't matter if we lose it.
EDIT: I've had to clear the queue to get things moving so unfortunately might not be able to test any solutions until it happens again.

MQ native clients do not automatically move erroneous message to BackoutQ or DLQ. Application has to write additional code to move the messages to DLQ or Backout queue. However XMS .NET and JMS clients do this job. XMS .NET is a JMS specification implementation in C# language. XMS .NET comes bundled with MQ Clients package.
Coming to your case:
MQRC_FORMAT_ERROR is not actually an error, it's a warning telling the application that MQ client was not able to convert the incoming message and it delivered an unconverted message to the application. The application must handle this exception and should not rollback such messages. You will need to investigate the application that is sending such messages and fix any issues.
Please see the documentation here.

Related

IBMMQDotnetClient deat letter queue .net6

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 ?
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

How to do an explicit ACK when receiving Websphere MQ messages?

I have an application listening to messages on an IBM Websphere MQ queue.
Once a message is consumed, the application performs some processing logic.
If the processing completed OK, I would like the application to acknowledge the message and have it removed from the queue.
If an error occurred while processing, I would like the message to remain in the queue.
How is this implemented? (I'm using the .NET API)
Thanks.
MQ supports a single-phase commit protocol. You specify syncpoint when you get the message, then issue COMMIT or ROLLBACK as required. The default action if the connection is lost is ROLLBACK and if the program deliberately ends without resolving the transaction a COMMIT is assumed. (This is platform dependent so the customary advice is to explicitly call COMMIT and not rely on the class destructors to do it for you.)
This works whether the message is persistent or not. However if the message has an expiry specified and expires after being rolled back there's a chance it won't be seen again.
Of course, if the program issues a ROLLBACK the message will normally be seen again since it goes back to the same spot int he queue and for a FIFO queue that's the top. If the problem with the message is not transient then this causes a poison message loop of read/rollback/repeat. To avoid that the app can check the backout count and if it exceeds some threshold requeue the message to an exception queue.
When using JMS or XMS this is done for you by the class libraries. If the input queue's BOQNAME and BOQTHRESH attributes are set the requeue is to the queue names in BOQNAME. Otherwise a requeue to the Dead Queue is attempted. IF that fails (as it should if the system is properly secured) the listener will stop receiving messages.
The usual advice is to always specify a backout queue and either let the classes use it or code the app to use it.
Please see Usage Notes for MQGET in the MQAPI Reference and the MQGetMessageOptions.NET page in the .Net class reference.
You may want to look at the MQ Reporting Options.
Expiry, Confirmation of Arrival and Confirmation of Delivery can be requested and sent via a response queue back to the sending application by the receiving Queue Manager.
Positive and Negative Acknowledgements can also be generated by the receiving application provided they use the related reporting attributes found in the Message Descriptor.
Exception can be requested and sent via a response queue back to the sending application by any Queue Manager in the transmission chain or generated by the receiving application.
1 Read the message using MQC.MQGMO_SYNCPOINT,
2 process it
3 call MQQueueManager.Commit()
If Commit() is not called explicitly, or implicitly (eg exception is thrown), all messages that have been de-queued will be re-enqueued.

How to go about messages in Dead Letter Queue

We are using WebLogic 10.3.6.0 and IBM MQ 7.5.
Application design is to send messages to a dead letter queue (in WebLogic) on re-delivery. The re-delivery happens as the first delivery has failed due to some network issue or database data source failure.
My Client wants a way to browse the messages in the dead letter queue from the application GUI and pull them for processing when the network issue or data source issue has been resolved.
What is the best way to go about this?
I cam across QueueBrowser coupled with activemq or some other implementation. Is QueueBrowser possible with WebLogic? Please suggest on best ways to achieve this requirement.
Kindly pardon if my question is too naive. I am only a PL/SQL programmer.
Valerie is referring to the SYSTEM DLQ and application should never ever write to it. Application's should have there own DLQ.
i.e. If your application queue is called 'TEST.Q1' then your application DLQ should be called 'TEST.Q1.DLQ'.
There is a whole long list of MQ tools here to view messages and manage your MQ environment.
Is the application actually designed to write to the DLQ? If so, that is a very poor design. The DLQ is for the queue manager and MQ software to place messages which can not be delivered. The application should not be writing to the DLQ.
As for how to view messages on DLQ, that can be done with the MQ Explorer GUI. Or to write a script, use the DLQ handler (runmqdlq) with a rules table for processing messages.

Automatically clear messages from queue in IBM MQ

I was wondering if there is a way for you to configure a queue to automatically clear messages? We are striving to partially implement a component of our architecture and want to be able to send to the queue, but have the queue automatically remove the messages that are being sent so that we don't have to run scripts, etc to perform the clean-up.
So far the only thing I have been able to find is to run CLEAR QLOCAL or set the messages to expire from the publishing application.
For you use case there are a few options in IBM MQ:
Create a QALIAS that points to a TOPIC object which has a topic string with no subscribers, messages put to the QA will just disappear.
Have the sending application set message expiry.
Use the IBM MQ CAPEXPRY feature to administratively force message expiry at the queue level.
Run a script to issue CLEAR QLOCAL against the queue. There can not be open handles on the queue for this to work.
Programmatically issue the equivalent PCF command to CLEAR QLOCAL against the queue. There cannot be open handles on the queue for this to work.
Run the IBM MQ dmpmqmsg utility against the queue to read and discard the messages.

JMS p2p failover pattern in order to guarantee delivery

Im a web developer ended up in some j2ee development (newbie). I sincerely need this theory confirmed.
I been given the privilege to deliver a message from our system (producer) to the SOA Enterprice service bus (consumer) when the user hits the save button. The information can not be missed or not delivered and the delivery order must be kept.
Environment:
Jboss eap 5.1 as the producer.
JNDI server is the ESB (maybe standard).
Jboss ESB as the consumer.
My weapon of choice is JMS, p2p, due to the asynchronous nature.
When the producer is abut to send the message some problems can occur:
ESB is down causing JNDI exception
Queue manager is for some reason not awake or wrongly configured. This should cause some JMS exception.
Network hickup, causing a JMS error.
So Im looking for some failover pattern. Here is my suggestion:
Add a internal JMS queue to which the message is initially added.
Add a MDB that listen to the internal queue and tries to send it to the target queue (ESB).
If failing in any way log fatal and send email to cool support people.
This should generate a reliable pattern where a message remains on the internal que until processed by the MDB.
Please advice.
Best Regards
ds
Well a 'temporary' queue is not a totally bad idea, but during the time from moving data from one queue to putting it on another you'll have a potential window of risk. Even though that window is close to nothing, what would happen if you got some failure right there and then? -You'd have to put the message back on the queue (and there you'd get into the problem with getting it in the correct order - nasty stuff!) or hold on to it in some way until you put it the other queue (which in turn can be cumbersome if you'd e g get into some failure-situaton.
A more stable solution would be to put data in a db with a queue-order column. You can then select your data in the correct order, send it to the new queue, and finally flag it as 'done' or something or even (better?) remove the data in the db.

Resources