如何解决MassTransit RespondAsync() 抛出 Microsoft.Azure.ServiceBus.MessagingEntityNotFoundException
具有以下启动配置的 Web API:
services.AddMassTransit(
x =>
{
x.AddBus(provider => this.CreateBus(provider));
string queueName = settings.InputQueueName;
var serviceBusUri = new Uri($"{settings.ServiceBusUri}/{queueName}");
CommandEndpointConvention.MapAll(serviceBusUri);
x.AddRequestClient<CreateThingCommand>(serviceBusUri);
});
将请求客户端注入控制器:
IRequestClient<CreateThingCommand> requestClient;
..构造一个命令并将命令放在 Azure 服务总线上并等待响应:
var busResponse = await this.requestClient.GetResponse<CommandResponse>(command);
Azure 函数被触发并处理请求,然后调用 RespondAsync
await context.RespondAsync(response);
每次,RespondAsync
行都会抛出以下异常。
Microsoft.Azure.ServiceBus.MessagingEntityNotFoundException: 'Put token failed. status-code: 404,status-description: The messaging entity 'sb://dev-xxxxx-bus.servicebus.windows.net/DESKTOPXXYYZZ_iisexpress_bus_xrsyyydbnyyx9a4pbdcxkg6udd' could not be found. To know more visit https://aka.ms/sbResourceMgrExceptions
我希望响应消息放在 input-queue
上并传递给调用者。
我做错了什么?
context
行上有一些 RespondAsync
值
我无法在 Service Bus Explorer 中观察到临时队列的创建。
抛出 MessagingEntityNotFoundException
后,GetResponse
调用最终在 30 秒后超时,表明它仍在运行、作用域和侦听。
解决方法
当使用请求客户端时,responseAddress 被设置为总线端点的地址,这是一个临时的、自动删除的队列。请求客户端在发送请求时将响应/故障处理程序动态连接到总线端点,并在 GetResponse
完成后断开这些处理程序。
还有一点,您可以使用 short addresses 轻松地为服务端点创建目标地址。例如:
x.AddRequestClient<CreateThingCommand>(new Uri($"queue:{queueName}"));
如果 RespondAsync
抛出一个 EntityNotFoundException
,那么可以肯定地说原始请求客户端不再连接/监听响应。
别忘了启动巴士!
bus.StartAsync();
MassTransit 使用临时的非持久队列并有一个消费者 处理响应。这个临时队列只被配置和创建 当您启动巴士时。如果您忘记启动公交车 应用程序代码,请求客户端将因超时而失败,等待 寻求回应。
https://masstransit-project.com/troubleshooting/common-gotchas.html
就我而言,不启动总线并不会阻止 input-queue
的创建,而是导致无法创建临时的自动删除响应队列。
感谢@Chris Patterson 为我指明了正确的方向。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。