简体   繁体   English

MassTransit Publisher 无异常抛出

[英]MassTransit Publisher no exception thrown

I have a MassTransit Producer / Publisher developed in Asp.Net Web API.我有一个用 Asp.Net Web API 开发的 MassTransit Producer/Publisher。

The producer simply sends message to the Exchange -> Queue.生产者只是将消息发送到 Exchange -> 队列。

public async Task<bool> AddToQueue(int msgId, Message message)
{
     var endpoint = await _bus.GetSendEndpoint(new Uri("exchange:testExchange?bind=true&queue=MessageQueue"));
     await endpoint.Send(new Message()
     {
         Id = msgId,
         Text = message.Text
     });
     return true;
}

However, the above would not return any exception (even if I had some sort of handling in place) if for instance queue was not found or there was an issue with binding etc. Message will simply get lost with no sign of it creating an error queue?但是,如果例如未找到队列或绑定等存在问题,则上述内容不会返回任何异常(即使我进行了某种处理)。消息只会丢失而没有任何迹象表明它会创建错误队列?

I understand it will create a queue if one was not found but am sure if there was an issue between with the Message broker and producer how would you handle that?我知道如果找不到队列,它将创建一个队列,但我确定消息代理和生产者之间是否存在问题,您将如何处理?

To get an exception from task operation you need to assign result of your method execution to Task variable, like this:要从任务操作中获取异常,您需要将方法执行的结果分配给 Task 变量,如下所示:

Task<bool> myTask = AddToQueue(42, "Some message");

And than you can get your exception from Exception property of Task:然后你可以从 Task 的 Exception 属性中获取你的异常:

if (myTask.Exception != null) 
    Console.WriteLine(myTask.Exception.InnerException.Message);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM