user1663380
user1663380

Reputation: 1013

Message Queue(MSMQ) does not throw exception when message is not received on the other end

Let's say I try to send to an authenticated transactional queue,

by calling msg.send(object,MessageQueueTransactionType.Single), message does not receive in transactional queue, no exception thrown.

What I want to accomplish is after sending, if message fail to send, perform some function and abort transaction, yet it doesn't throw exception, so I am unable to process it.

I am sending object from Web Application in local to local message queue.

My code is as follows in my web application:

MessageQueueTransaction mqTran=new MessageQueueTransaction();

try
{
  using(System.Messaging.Message msg=new System.Messaging.Message(){
  mqTran.Begin();

  MessageQueue adminQ = new MessageQueue(AdminQueuePath);
  MessageQueue msgQ = new MessageQueue(queuePath);
  msgQ.DefaultPropertiesToSend.Recoverable = true;

  msg.body = object;
  msg.Recoverable=true;
  msg.Label="Object";
  msg.TimeToReachQueue=new TimeSpan(0,0,30);
  msg.AcknowledgeType=AcknowledgeTypes.FullReachQueue;
  msg.ResponseQueue=adminQ;
  msg.AdministrationQueue=adminQ;
  msgQ1.Send(msg,MessageQueueTransactionType.Single);
  mqTran.Commit();
}
catch(Exception e)
{
  mqTran.Abort();
  //Do some processing if fail to send
}

Upvotes: 2

Views: 3176

Answers (1)

devlord
devlord

Reputation: 4164

It's not going to throw an exception for failure to deliver, only for failure to place on the queue. One of the points of message queueing is that the messages are durable so that you can take appropriate measures if delivery fails. This means you need to program another process to read the dead letter queue. The image below is taken from MSDN.

Image

Because the entire process is asynchronous, your code flow is not going to be exception-driven the way your code block would like. Your transaction is simply the "sending transaction" in this workflow.

Recommendation: Check your message queue to find the messages, either in the outgoing queue or the transactional dead-letter queue.

Upvotes: 2

Related Questions