Greetings of the day.
Please help on the below requirement:
Requirement:
We want to delete message from MQ only after it is processed successfully.
Use event based message detection technique and avoid loop
So, to achieve above:
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(); }
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:
Response method override:
protected override Task 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