0

I'm trying to write MQ client which will be resistant to unexpected situation. I have created client with client_acknowledge mode:

ISession session = conn.CreateSession(false, AcknowledgeMode.ClientAcknowledge);

In the XMS documentation there is information for CLIENT_ACKNOWLEDGE:

The application can acknowledge the receipt of each message individually, or it can receive a batch of messages and call the Acknowledge method only for the last message it receives. When the Acknowledge method is called all messages received since the last time the method was called are acknowledged.

The client fetches for example 10 messages from queue and writes them to DB.

The question is how to setup this mode with acknowledge every single message ( for ensuring message delivery )?

JoshMc
  • 10,239
  • 2
  • 19
  • 38
moniuh
  • 1
  • Are you trying to do something like this: You received 10 messages but you want to ack only one message of the batch, say 5th or 8th? If so that is not possible. As doc says, XMS will ack all messages received. – Shashi Jan 22 '16 at 11:20
  • In the current implementation I ACK every single message from collection of received. I need to be sure of not getting lost any message. If the 5th message will be acked and something goes wrong and for example we lost 3rd (it would be acked with the 5th message and not redeliver ) Is there any way to be sure of order of sequence? – moniuh Jan 22 '16 at 11:30

1 Answers1

1

When a message is delivered to your application, how is it lost?

Since you are dealing with two resources, why not go for a transacted session or a XA transacted session. If there is an issue with updating DB, you could do a Rollback so that messages get redelivered.

Update

In a transacted session, acknowledge mode has no significance. Messages are acknowledged when a commit is called or rolled back when rollback is called.

If connection to IBM MQ queue manager is lost, all uncommitted messages are automatically rolled back by the queue manager. So no messages are lost.

Shashi
  • 14,980
  • 2
  • 33
  • 52
  • A transaction based session with auto acknowledge seems to be the solution to that problem. See this documentation (it is for Java, but the general idea is the same): http://www-01.ibm.com/support/knowledgecenter/SSFKSJ_8.0.0/com.ibm.mq.dev.doc/q032220_.htm?lang=en If anything goes wrong during message processing or writing to the database, just do a rollback. And if everything worked, commit the transaction. – MuhKuh Jan 22 '16 at 19:31
  • But is it secure to auto acknowledge messages? When I'm fetching messages in packages of 10-50, if something happened with connection to MQ when message is consumed by client (waiting or nowait mode), how to handle all unexpected situations to be sure that none of messages are lost? – moniuh Jan 22 '16 at 21:54