重试消息之前可以延迟Azure Service Bus吗? [英] Can the Azure Service Bus be delayed before retrying a message?

查看:119
本文介绍了重试消息之前可以延迟Azure Service Bus吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Azure服务总线支持内置的重试机制,该机制可使被放弃的消息立即可见,以供另一次读取尝试使用.我正在尝试使用这种机制来处理一些暂时性错误,但是该消息在被放弃后立即可以使用.

The Azure Service Bus supports a built-in retry mechanism which makes an abandoned message immediately visible for another read attempt. I'm trying to use this mechanism to handle some transient errors, but the message is made available immediately after being abandoned.

我想做的是使该消息在废弃后的一段时间内不可见,最好是基于指数递增策略.

What I would like to do is make the message invisible for a period of time after it is abandoned, preferably based on an exponentially incrementing policy.

我已尝试在放弃消息时设置ScheduledEnqueueTimeUtc属性,但是它似乎没有效果:

I've tried to set the ScheduledEnqueueTimeUtc property when abandoning the message, but it doesn't seem to have an effect:

var messagingFactory = MessagingFactory.CreateFromConnectionString(...);

var receiver = messagingFactory.CreateMessageReceiver("test-queue");

receiver.OnMessageAsync(async brokeredMessage =>
{
    await brokeredMessage.AbandonAsync(
        new Dictionary<string, object>
        {
            { "ScheduledEnqueueTimeUtc", DateTime.UtcNow.AddSeconds(30) }
        });
    }
});

我已经考虑过完全不放弃消息,只是让锁过期,但这将需要某种方式来影响MessageReceiver如何指定消息的锁持续时间,而我在其中找不到任何内容.让我更改此值的API.此外,直到已经需要锁定后,才能读取邮件的传递计数(并因此决定等待下一次重试的时间).

I've considered not abandoning the message at all and just letting the lock expire, but this would require having some way to influence how the MessageReceiver specifies the lock duration on a message, and I can't find anything in the API to let me change this value. In addition, it wouldn't be possible to read the delivery count of the message (and therefore make a decision for how long to wait for the next retry) until after the lock is already required.

消息总线中的重试策略会受到某种影响,还是可以通过其他方式人为地引入延迟?

Can the retry policy in the Message Bus be influenced in some way, or can a delay be artificially introduced in some other way?

推荐答案

我实际上

I actually asked this same question last year (implementation aside) with the three approaches I could think of looking at the API. @ClemensVasters, who works on the SB team, responded that using Defer with some kind of re-receive is really the only way to control this precisely.

您可以阅读我对他的回答的评论,以了解执行此操作的特定方法,在该建议中,我建议使用辅助队列存储消息,这些消息指示哪些主消息已被推迟并且需要从主队列中重新接收.然后,您可以通过在这些辅助消息上设置ScheduledEnqueueTimeUtc来控制精确地,在重试之前等待多长时间来控制等待的时间.

You can read my comment to his answer for a specific approach to doing it where I suggest using a secondary queue to store messages that indicate which primary messages have been deferred and need to be re-received from the main queue. Then you can control how long you wait by setting the ScheduledEnqueueTimeUtc on those secondary messages to control exactly how long you wait before you retry.

这篇关于重试消息之前可以延迟Azure Service Bus吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆