Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSMQ via C# - ACK that message received?

Tags:

c#

.net-4.5

msmq

I'm sending a message to a private queue via c# :

MessageQueue msgQ = new MessageQueue(@".\private$\aaa");
msgQ.Formatter = new XmlMessageFormatter(new[] { typeof (String) });
msgQ.Send(msg);

It does work and I do see the message in the queue.

However, is there any way to get an ACK whether the message got to the queue with success ?

ps

BeginPeek and PeekCompleted is an event which is raised when a message becomes available in the queue or when the specified interval of time has expired. it is not helping me because I need to know if the message that I sent was received by msmq. BeginPeek will be raised also if someone else entered a message to the queue. and the last thing I want is to check via BeginPeek - from who this message comes from.

How can I do that?

ps2

Or maybe I don't have to worry since msgQ.Send(msg); will raise an exception if a message wasn't inserted....?

like image 653
Royi Namir Avatar asked Oct 01 '22 01:10

Royi Namir


1 Answers

I think what you are trying to do should not be handled in code. When you send the message, it is placed in the outgoing queue. There are numerous reasons why it would not reach the destination, such as a network partition or the destination queue being full. But this should not matter to your application - as far as it is concerned, it sent the message, it committed transaction, it received no error. It is a responsibility of the underlying infrastructure to do the rest, and that infrastructure should be monitored to make sure there are no technical issues.

Now what should really be important to your application is the delivery guarantees. I assume from the scenario that you are describing that you need durable transactional queues to ensure that the message is not lost. More about the options available can be read here

Also, if you need some identifier to display to the user as a confirmation, a common practice is to generate it in the sending code and place it in the message itself. Then the handling code would use the id to do the required work.

like image 55
Vytautas Mackonis Avatar answered Oct 13 '22 09:10

Vytautas Mackonis