0

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:

  1. 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

b_patil
  • 1
  • 2
  • Do you have a single application reading the queue and handing off the messages into MES, or do you have multiple applications? Does MES interact with MQ, i.e it can get the message off (destructively) when it is done? – Morag Hughson Aug 23 '22 at 10:37
  • @MoragHughson: Yes, I have single application reading the messages. Its basically FIFO. MES won't interact with MQ, there is an adapter between these two systems which reads the msg, push into MES, and delete. – b_patil Aug 23 '22 at 11:00
  • @MoragHughson: Since we can't achieve as stated above.. we stepped back. We are trying to use QueueBrowser along with message consumer with selector for delete. We are able to browse the queue, but while creating the consumer with selector its throwing an error below:XMSException =IBM.XMS.IllegalStateException: Failed to open MQ queue XXX. XMS attempted to perform an MQOPEN, but IBM MQ reported an error. at IBM.XMS.Client.Impl.XmsSessionImpl.CreateConsumer(IDestination dest, String selector) – b_patil Sep 19 '22 at 10:31
  • What is the exception you are getting - the linked exception should have an MQRC in it which will indicate the problem – Morag Hughson Sep 20 '22 at 06:04

0 Answers0