【问题标题】:Mass Transit and Azure Service Bus Scheduled Retries公共交通和 Azure 服务总线计划重试
【发布时间】:2020-11-12 01:44:18
【问题描述】:

我们的公共交通/Azure 服务总线设置运行良好,但还有一个我们非常想使用但似乎无法正常工作的功能 - 预定的重新交付。

这是启动中的代码:

busFactoryConfig.UseServiceBusMessageScheduler();
    
busFactoryConfig.SubscriptionEndpoint(Constants.SubscriptionName, Constants.TopicName, configurator =>
                    {
                        configurator.UseScheduledRedelivery(r => r.Intervals(TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(15), TimeSpan.FromMinutes(30)));
                        configurator.UseMessageRetry(r =>
                        {
                            r.Immediate(2);
                            r.Ignore<InvalidCastException>(); //we don't want to retry here, the message content is invalid
                        });

这似乎与documentation 匹配得很好。虽然文档似乎只提到了 RabbitMQ。

但是,当这实际触发时,会引发公共交通异常,并且重新递送不起作用。这是使用 .NET Core 3.1、MassTransit 7.0.1 和 Azure 服务总线主题。

错误(故意抛出以触发重试):

MassTransit.TransportException: **ADDRESS** => The message delivery could not be rescheduled
 ---> System.AggregateException: One or more errors occurred. (The specified resource description is invalid. TrackingId:cda5544e-90e4-4818-97f9-4de3ee55aaad_G46, SystemTracker:**TOPIC**, Timestamp:2020-07-22T13:22:23) (BAM! <- MY ERROR)
 ---> Microsoft.Azure.ServiceBus.ServiceBusException: The specified resource description is invalid. TrackingId:cda5544e-90e4-4818-97f9-4de3ee55aaad_G46, SystemTracker:**TOPIC**, Timestamp:2020-07-22T13:22:23
 ---> System.ArgumentException: The specified resource description is invalid. TrackingId:cda5544e-90e4-4818-97f9-4de3ee55aaad_G46, SystemTracker:**TOPIC**, Timestamp:2020-07-22T13:22:23

我尝试了不同的设置,更类似于文档:

busFactoryConfig.UseMessageScheduler(uri); //Uri is my sb endpoint, minus Endpoint=

这给我们带来了不同的错误:

InvalidAudience: The authorization header contains a token with a wrong audience.

快速阅读会发现这与 Azure 使用密钥的方式有关,并且可能已过时。但是,这与我用来成功连接到总线的 URI 相同 - 我所做的只是删除 Endpoint= 以便在构造 new Uri() 时它是一个有效的 URI。

安排的重新交付是否适用于 Azure 服务总线的 MT?我在配置中遗漏了什么吗?

任何帮助将不胜感激。

【问题讨论】:

    标签: asp.net-core azureservicebus masstransit


    【解决方案1】:

    您无法使用订阅端点进行重新交付。如果您想使用重新传递,我建议使用常规的 ReceiveEndpoint(消息将从主题转发到队列,该队列由 MassTransit 使用消费者消息类型进行配置)。

    SubscriptionEndpoints 特定于 ASB,通常仅在您有想要直接订阅的现有主题时使用。

    【讨论】:

      【解决方案2】:

      正如 Chris 上面回答的那样 - 不支持 SubscriptionEndpoints,您必须改用 ReceiveEndpoint。这对我有用:

      busFactoryConfig.UseServiceBusMessageScheduler();
      
      busFactoryConfig.ReceiveEndpoint(Constants.SubscriptionName, configurator =>
                          {
                              configurator.UseScheduledRedelivery(r => r.Intervals(TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(2), TimeSpan.FromMinutes(3)));
                              configurator.UseMessageRetry(r =>
                              {
                                  r.Immediate(2);
                                  r.Ignore<InvalidCastException>(); //we don't want to retry here, the message content is invalid
                              });
      
                              configurator.ConfigureConsumer<MyConsumer>(context);
                          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-11-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-07-27
        • 2019-10-15
        相关资源
        最近更新 更多