简体   繁体   English

使用废弃的服务总线消息重新触发Azure功能

[英]Re-trigger Azure Function with abandonded Service Bus messages

I have a Service Bus topic that has 400,000 messages pushed to it from an Azure Function. 我有一个Service Bus主题,其中有400,000条消息从Azure函数推送给它。 I have a second Azure Function that receives the messages as a trigger. 我有第二个Azure函数,它接收消息作为触发器。 When the 2nd Function ran, it successfully processed 98% of the messages. 当第二个函数运行时,它成功处理了98%的消息。 It left me with roughly 8,000 messages that failed. 它给我留下了大约8,000条失败的消息。 Either from an exception, or from my code, the message was abandoned. 无论是从异常还是从我的代码中,消息都被放弃了。 I've now got 8,000 messages sitting in a subscriber of the topic, that I can't get the Function to re-try processing. 现在,在该主题的订阅者中有8,000条消息,这些消息使我无法重试处理。

The subscriber was originally set up to only allow 1 delivery of the message. 最初将订户设置为仅允许传递该消息一次。 I had done it that way because I was seeing the same message get processed multiple times while debugging. 我这样做是因为在调试时看到同一条消息多次被处理。 I wasn't sure if that was a side-effect of debugging in Visual Studio locally, or if messages would get sent to a Function multiple times. 我不确定这是否是在Visual Studio中进行本地调试的副作用,还是不确定消息是否会多次发送给Function。 I assume this is what caused those messages to not have the Function re-run after they were abandoned (if that even is supported?). 我认为这是导致这些消息在被放弃后无法重新运行该功能的原因(如果支持的话)。

I've changed the subscriber delivery count to 5, hoping that it would re-deliver the message to the Function. 我已将订户传递计数更改为5,希望它将消息重新传递给功能。 It didn't. 没有。 What do I need to do now to get the remaining 8,000 messages to trigger the 2nd Function again? 我现在需要做些什么来获取剩余的8,000条消息来再次触发第二功能?

Worst case is that I can delete the subscription, re-create the subscription and run the first Function over again, which should just publish the data associated with the original missing 8,000 messages (I have logic to handle missing data in the 1st Function). 最糟糕的情况是,我可以删除订阅,重新创建订阅,然后再次运行第一个功能,这应该只发布与原始丢失的8,000条消息关联的数据(我有逻辑来处理第一个功能中的丢失数据)。 That would cause the 2nd Function to re-fire. 这将导致第二功能重新启动。 I'd like to figure out how to handle it though when the subscription has the orphaned messages like this, as I'll experience this when I promote to production. 我想弄清楚当订阅中包含这样的孤立消息时如何处理它,因为升级到生产环境时会遇到这种情况。 I want this to be automated and not have to deal with manually cleaning up and re-running the process a 2nd time. 我希望这是自动化的,而不必第二次手动清理并重新运行该过程。

The following shows that there aren't any messages left in the Topic, but they exist still in the subscription. 下面显示了主题中没有剩余任何消息,但它们仍存在于订阅中。 在此处输入图片说明

I wrote the Functions in C# Functions 1.0 on Full Framework. 我在完整框架的C#函数1.0中编写了函数。

If the MaxDeliveryCount is reach the message will be sent to a deadletter queue. 如果达到MaxDeliveryCount,则邮件将发送到死信队列。
You can think about a subscription as a sub-queue so you can still access these messages. 您可以将预订视为子队列,以便仍然可以访问这些消息。

Check this post on how to access deadletter queues: 查看有关如何访问死信队列的文章:

First thing is your scenario will be to increase the MaxDeliveryCount. 首先,您的方案将是增加MaxDeliveryCount。

Then you can create a function that will be triggered every time a message arrived in the deadletter queue/subscription: 然后,您可以创建一个函数,该函数将在每次消息到达死信队列/订阅中时触发:

 [FunctionName("my-subscription-failure")]
 public static async Task RunFailure(
        [ServiceBusTrigger("%MytopicName%", "%MySubscription%/$DeadLetterQueue", Connection = "MyconnectionString")] BrokeredMessage message,
        [ServiceBus( "%MytopicName%", AccessRights.Send, Connection = "MyconnectionString")] ICollector<BrokeredMessage> queueBinding,
        TraceWriter log, ExecutionContext context)
{
    // fist check if the message can be resent (it could be a message that can't be replay)
    ...

    // If ok, resent the message
    queueBinding.Add(message);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure 服务总线 Azure 函数触发并获取所有消息 - Azure service bus Azure Function trigger and get all messages Azure Service Bus和Azure功能队列触发器 - Azure Service Bus and Azure Function Queue Trigger Azure 功能,服务总线触发器不起作用 - Azure Function, Service bus trigger not working 当带有服务总线队列触发器的 Azure Function 被禁用并且消息被排队时会发生什么 - What happens when an Azure Function with service bus queue trigger is disabled and messages are enqueued Azure功能:服务总线输入绑定(不触发) - Azure Function: Service Bus input binding (not trigger) 天蓝色函数上的TaskCanceledException(服务总线触发器) - TaskCanceledException on azure function (Service bus trigger) Azure 服务总线 - 已取消的计划消息重新排队 - Azure Service Bus - cancelled scheduled messages getting re-queued Azure 数据工厂自动重新触发失败的管道 - Azure Data Factory automatically re-trigger failed pipeline 有任何 2 种方法可以从 azure 函数 HTTP 触发器读取所有服务总线消息 - there any 2 ways to read all service bus messages from azure function HTTP trigger 具有批量处理消息的服务总线队列触发器的天蓝色函数是否会立即触发? - Will an azure function with a Service Bus Queue trigger which processes messages in batches be triggered instantaneously?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM