有没有一种方法可以延迟Azure功能中对服务总线消息的重试? [英] Is there a way I can delay the retry for a service bus message in an Azure function?

查看:87
本文介绍了有没有一种方法可以延迟Azure功能中对服务总线消息的重试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个函数可以从订阅中提取消息,并将其转发到HTTP端点.如果端点不可用,则会引发异常.发生这种情况时,我想将特定消息的下一次尝试延迟一定的时间,例如15分钟.到目前为止,我发现了以下解决方案:

  • 捕获异常,睡觉,然后抛出.这是一个糟糕的解决方案,因为我需要为处于睡眠状态的CPU使用率付费,这会影响该函数的吞吐量.
  • 捕获异常,克隆消息,设置ScheduledEnqueueTimeUtc属性,然后将其添加回队列.这是一种更好的方法,但是它会重置传递计数,因此,只有一个订阅者无法处理实际问题时,才不会死机,而是将其发送给所有订阅.
  • 捕获异常,然后将消息放置在存储队列中.这意味着维护一个存储队列以匹配每个订阅,并具有两个功能而不是一个功能.

我理想地希望发生的是捕获异常,并退出函数,而无需释放消息上的锁定.这样,一旦锁过期,该消息将再次重试.但是,似乎成功完成之后,该函数在消息上调用Complete(),并且在引发异常之后,该函数在消息上调用Abandon().是否可以绕过这个,或者以其他方式实现延迟?

解决方案

我将通过 LogicApp 通过纯函数更好地处理您提出的流程,来解决您的情况.

在LogicApp中实现 wait/retry/dequeue next 模式非常容易,因为这种流控制正是LogicApp的目的.

I have a function which pulls messages off a subscription, and forwards them to an HTTP endpoint. 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, e.g. 15 minutes. So far, I have found the following solutions:

  • Catch the exception, sleep, then throw. This is a terrible solution, as I will be charged for CPU usage while it is sleeping, and it will affect the throughput of the function.
  • Catch the exception, clone the message, set the ScheduledEnqueueTimeUtc property and add it back to the queue. 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.
  • Catch the exception, and place the message on a storage queue instead. This means maintaining a storage queue to match each subscription, and having two functions instead of one.

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. 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.

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.

这篇关于有没有一种方法可以延迟Azure功能中对服务总线消息的重试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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