[英]Is there a way I can delay the retry for a service bus message in an Azure function?
I have a function which pulls messages off a subscription, and forwards them to an HTTP endpoint. 我有一个函数可以从订阅中提取消息,并将其转发到HTTP端点。 If the endpoint is unavailable, an exception is thrown. 如果端点不可用,则会引发异常。 When this happens, I would like to delay the next attempt of that specific message for a certain amount of time, eg 15 minutes. 发生这种情况时,我想将该特定消息的下一次尝试延迟一定的时间,例如15分钟。 So far, I have found the following solutions: 到目前为止,我已经找到以下解决方案:
ScheduledEnqueueTimeUtc
property and add it back to the queue. 捕获异常,克隆消息,设置ScheduledEnqueueTimeUtc
属性,然后将其添加回队列。 This is a nicer way, but it resets the delivery count, so an actual problem will never be dead-lettered, and it is resent to all subscriptions, when only one subscriber failed to process it. 这是一种更好的方法,但是它会重置传递计数,因此,只有一个订阅者无法处理实际问题时,绝不会解决任何实际问题,并将其重新发送给所有订阅。 What I would ideally like to happen is to catch the exception, and exit the function without releasing the lock on the message . 我理想地希望发生的是捕获异常,并在不释放消息锁定的情况下退出函数。 That way, as soon as the lock expires the message will be retried again. 这样,一旦锁过期,该消息将再次重试。 However, it seems that after completing successfully, the function calls Complete()
on the message, and after an exception is thrown, the function calls Abandon()
on the message. 但是,似乎在成功完成之后,该函数在消息上调用Complete()
,并在引发异常之后,在消息上调用Abandon()
。 Is it possible to bypass this, or to achieve the delay some other way? 是否可以绕过此延迟,或以其他方式实现延迟?
I will address your situation by offering that the flow you are proposing is better handled by a LogicApp over a pure function. 我将通过提供您提出的流程由LogicApp更好地处理纯函数来解决您的情况。
It's quite easy to implement the wait/retry/dequeue next pattern in a LogicApp since this type of flow control is exactly what LogicApps was designed for. 在LogicApp中实现“ 等待/重试/出队”下一模式非常容易,因为这种流控制正是LogicApp所设计的。
Although still in preview (not recommended for production code), you could use Durable Functions . 尽管仍处于预览状态(不建议用于生产代码),但可以使用Durable Functions 。 If you want to maintain the ability to manipulate objects in code, this is likely your best bet! 如果您想保持在代码中操作对象的能力,那可能是最好的选择!
(+1 to LogicApp solution too!) (也为LogicApp解决方案+1!)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.