azure-functions - 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
完成后断开这些处理程序。
另外一点,您可以使用短地址轻松地为您的服务端点创建目标地址。例如:
x.AddRequestClient<CreateThingCommand>(new Uri($"queue:{queueName}"));
如果RespondAsync
抛出 anEntityNotFoundException
那么可以肯定地说原始请求客户端不再连接/侦听响应。
推荐阅读
- automation - 在 UFT 中的 javatree 中查找子节点的文本
- hyperledger-fabric - 是否可以在 Hyperledger Composer 设置中部署链代码?
- python-3.x - 如何打包 PySide2 应用程序以进行分发?
- python - Airflow 网络服务器为 dags 提供 cron 错误,其中 None 作为计划间隔
- android - 我很困惑他们俩哪一个是最好的 GoogleApiClient 或 FusedLocationProviderClient
- python - 创建具有多个数据框和多个条件的列
- powerbi-desktop - sameperiodlastyear 当会计日历不是逐月时
- python - 初学者在 Python 中循环
- c# - Kendo mvc 在下拉列表中加入文本
- python - python的`in`函数在通过`__getitem__()`'触发时如何工作?