简体   繁体   English

有没有办法可以延迟Azure功能中对服务总线消息的重试?

[英]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: 到目前为止,我已经找到以下解决方案:

  • 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. 这是一个糟糕的解决方案,因为我需要为处于睡眠状态的CPU使用率付费,这会影响该函数的吞吐量。
  • Catch the exception, clone the message, set the 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. 这是一种更好的方法,但是它会重置传递计数,因此,只有一个订阅者无法处理实际问题时,绝不会解决任何实际问题,并将其重新发送给所有订阅。
  • 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. 但是,似乎在成功完成之后,该函数在消息上调用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.

相关问题 Azure 服务总线的 Azure Function App 延迟重试 - Azure Function App delay retry for azure service bus 在TaskCancelationException上重试Azure服务总线消息 - Azure Service Bus message retry on TaskCancelationException 我无法重试 Azure 服务总线主题中的失败项目 - I can't retry failed item in Azure Service Bus topic 在使用服务总线作为触发器的 C# Azure Function 4.x 中实现指数重试的最佳方法是什么? - What is the best way to implement exponential retry in C# Azure Function 4.x with a Service Bus as a trigger? 如何在 Azure Function 隔离进程中访问服务总线消息的 ApplicationProperties? - How can I access the ApplicationProperties of a service bus message in a Azure Function isolated process? 我们可以在服务总线主题触发 Azure 函数中使用 Polly 重试而不是 ExponentialBackoffRetry 吗? - Can we use Polly retry instead of ExponentialBackoffRetry in Service Bus Topic Trigger Azure Function? Azure功能未将消息发布到服务总线 - Azure Function Not Publishing Message to Service Bus 延迟消息并保持传递计数 Azure 服务总线 - Delay Message and Maintain Delivery Count Azure Service Bus Azure 服务总线重试选项不起作用 - Azure Service Bus Retry Options Not Working 如何在 Azure 功能 2 中访问 Azure 服务总线消息属性 - How to access azure service bus message properties in Azure function 2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM