Hi again - sorry to reply to myself but just for completeness...
Having caught up with one of my colleagues who I gather you've been talking with directly, I understand more of the issues specific to your application now - we have one or two possible additional suggestions, but as this is very specific to your environment they probably aren't worth discussing on this thread!
Regards
Original Message:
Sent: Mon September 12, 2022 11:46 AM
From: Anthony Beardsmore
Subject: IBM MQ delete a message from queue using XMS library
Hi Balaji
Unless I am misunderstanding something significant, a far better approach might be use of transactions (syncpoint) and let MQ deal with the 'delete message when work completed' aspect for you. This would usually be the way to acheive the kind of pattern you seem to be describing.
I'm not that familiar with the XMS interfaces to be honest (someone else may be able to point you to an example/exact spelling) but I believe you would enable this via the MQGetMessageOptions class, and then Commit or Rollback (on the session object possibly?) when you know whether or not you want to permanently remove the message.
Regards
Anthony
------------------------------
Anthony Beardsmore
IBM MQ Development
IBM
Original Message:
Sent: Mon August 29, 2022 10:27 AM
From: Balaji Patil
Subject: IBM MQ delete a message from queue using XMS library
IBM MQ Team,
Greetings of the day.
Please help on the below requirement:
Requirement:
1. We want to delete message from MQ only after it is processed successfully.
2. Use event based message detection technique and avoid loop
So, to achieve above:
1. I have created message listener and consumer class below:
sessionIn = connectionIn.CreateSession(false, AcknowledgeMode.ClientAcknowledge);
// Create message listener and assign it to consumer
messageListener = new MessageListener(OnMessageCallback);
consumerAsync.MessageListener = messageListener;
Console.WriteLine("Message Listener set. Starting the connection now.");
// Start the connection to receive messages.
connectionWMQ.Start();
2. Reading the message from the call back event and push the message into other system:
OnMessageCallback(Message) {
if (xmsMessage is IBytesMessage)
{
IBytesMessage bytesMessage = (IBytesMessage)xmsMessage;
byte[] arrayMessage = new byte[bytesMessage.BodyLength];
bytesMessage.ReadBytes(arrayMessage);
string message = System.Text.Encoding.Default.GetString(arrayMessage);
}
}
Once the message processed, external system will fire the below over ride method:
3. Response method override:
protected override Task<bool> OnResponse(ReponseMessage message)
{
//Read the message and get the message id and correlation id.
//Delete the message from the queue.
//I am trying to do like this, but Its not working:
messageConsumerDelete = sessionDelete.CreateConsumer(destinationDelete, query);
if (messageConsumerDelete != null)
{
IMessage m = messageConsumerDelete.Receive(1000);
LogWrite("Receive Message=" + m);
m.Acknowledge();
}
}
Please suggest a best solution for this requirement.
I am trying to find a solution for this since weeks, but no breakthrough.
Thanks,
Balaji
------------------------------
Balaji Patil
------------------------------