2

假设我尝试发送到经过身份验证的事务队列,

通过调用 msg.send(object,MessageQueueTransactionType.Single),消息不会在事务队列中接收,不会抛出异常

我想要完成的是发送后,如果消息发送失败,执行一些功能并中止事务,但它不会抛出异常,所以我无法处理它。

我正在从本地的 Web 应用程序向本地消息队列发送对象。

我的 Web 应用程序中的代码如下:

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
}
4

1 回答 1

2

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.

于 2013-07-15T03:13:28.450 回答