masstransit - 使用 Masstransit 和 Azure 服务总线将故障消息发送到主题订阅死信队列
问题描述
当主题的订阅者抛出异常时,未处理的消息将进入{subscribername}_error
队列。
举个例子:
const string subsriberName = "AnotherSubscriber";
cfg.SubscriptionEndpoint<AnotherThingHappened>(host, subsriberName, configurator =>
{
configurator.Handler<AnotherThingHappened>(context =>
{
Console.WriteLine(context.Message.AnotherThingType);
if (Random.NextDouble() < 0.1)
{
throw new Exception("Oups, I failed :(");
}
return Task.CompletedTask;
});
});
它在 ObjectCreatedA 主题上创建了“AnotherSubscriber”订阅。但是当它失败时,消息会进入队列anothersubscriber_error
。它使诊断、监控和重播消息变得更加困难。因为从 ASB 的角度来看,这只是一个普通的队列。
如何将故障路由到主题 ObjectCratedA/AnotherSubscriber 而不是**_error
一个的 DLQ?
提前致谢。
解决方案
从 MassTransit 6.2 开始,这现在是可能的,请参阅相关的GitHub 问题。
您的配置现在需要如下所示:
cfg.SubscriptionEndpoint(
"my-subscription",
"my-topic",
e =>
{
e.ConfigureConsumer<MyConsumer>(provider);
// Send failures to built-in Azure Service Bus Dead Letter queue
e.ConfigureDeadLetterQueueDeadLetterTransport();
e.ConfigureDeadLetterQueueErrorTransport();
});
推荐阅读
- node.js - 如何将邮递员的值正确插入到我的 Node API
- java - Hibernate:选择对象关系映射?
- c++ - 如何将字符串与一个字符交错?
- c# - 如何在我的 c# 代码中正确添加文档(类似于 javadoc)
- json - 得到 200 响应,但不显示 json 值
- python - 在 tkinter Text 中查找使用 window_create 创建的元素的索引
- amazon-web-services - 如何将 Name.com 上托管的域指向 AWS S3 静态网站?
- babeljs - regeneratorRuntime 未定义(如何防止 babel 包含该 polyfill?)
- tensorflow - 量化感知训练示例?
- python - 当 JSON 记录没有容器名称时从 api 中提取数据