将错误消息发送到具有Masstransit和Azure Service Bus的主题订阅死信队列中

问题描述 投票:1回答:1

[当主题的订户引发异常时,未处理的消息到达{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的角度来看,这只是一个普通的队列。

enter image description here

如何将故障路由到主题ObjectCratedA / AnotherSubscriber的DLQ而不是**_error一个?

提前感谢。

masstransit
1个回答
3
投票

现在从MassTransit 6.2开始是可能的,请参阅相关的GitHub issue

您的配置现在需要看起来像:

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();
    });
© www.soinside.com 2019 - 2024. All rights reserved.