简体   繁体   English

我无法重试 Azure 服务总线主题中的失败项目

[英]I can't retry failed item in Azure Service Bus topic

I have a process that is consuming items from the Azure Service Bus topic.我有一个进程正在使用 Azure 服务总线主题中的项目。 If everything goes well there is no problem but If the process gets an error I need to retry consuming the failed item.如果一切顺利,则没有问题,但如果过程出错,我需要重试使用失败的项目。

Here is my message handler;这是我的消息处理程序;

public async Task StartRecieverAsync()
    {
        var messageHandlerOptions = new MessageHandlerOptions(ExceptionReceivedHandler)
        {
            MaxConcurrentCalls = 1,
            AutoComplete = false,
            MaxAutoRenewDuration = TimeSpan.FromSeconds(30)
        };

        _creatorSubscription.RegisterMessageHandler(ProcessCreatorMessageAsync, messageHandlerOptions);

        Console.ReadLine();

        await _creatorSubscription.CloseAsync();
    }

    private async Task ProcessCreatorMessageAsync(Message message, CancellationToken token)
    {
        try
        {
            var jsonString = Encoding.UTF8.GetString(message.Body);
            PickingRequest req = JsonSerializer.Deserialize<PickingRequest>(jsonString);

            WorkOrderManager manager = new WorkOrderManager(_sqlManager, _cacheManager, _workOrderFunctions);
            manager.CreatePickingTask(req);

            SendNotification(req.UserRegistrationNumber, NotificationConstants.PickingRequestNotification);

            await _creatorSubscription.CompleteAsync(message.SystemProperties.LockToken);
        }
        catch
        {
            if (message.SystemProperties.DeliveryCount < 5)
            {
                await _creatorSubscription.AbandonAsync(message.SystemProperties.LockToken);
            }
            else
            {
                await _creatorSubscription.DeadLetterAsync(message.SystemProperties.LockToken);
            }
        }
    }

At first 5 times, I would like to try again but it results not change I want to send the item to the dead letter queue.起初 5 次,我想再试一次,但结果没有改变我想将项目发送到死信队列。 But after the first time, the item goes to the dead letter queue.但在第一次之后,该项目进入死信队列。

How is the topic subscription configured on the service bus?服务总线上的主题订阅是如何配置的? If the max delivery count is 1 then after the first failure the service bus, will move the message to the Dead-letter queue.如果最大传递计数为 1,那么在服务总线第一次发生故障后,会将消息移动到死信队列。 Service Bus Topic Subscription Properties服务总线主题订阅属性

  • Also it's generally not necessary to manually dead letter a message with a calls DeadLetterAsync , the service bus will do this once the max delivery count is exceeded.此外,通常不需要使用调用DeadLetterAsync手动死信消息,一旦超过最大传递计数,服务总线将执行此操作。 ie your the catch block can be simplified to just await _creatorSubscription.AbandonAsync(message.SystemProperties.LockToken);即您的 catch 块可以简化为await _creatorSubscription.AbandonAsync(message.SystemProperties.LockToken);

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

相关问题 有没有办法可以延迟Azure功能中对服务总线消息的重试? - Is there a way I can delay the retry for a service bus message in an Azure function? 无法添加Azure Service Bus主题订阅筛选规则 - Can't add Azure Service Bus Topic Subscription filter rule 我们可以在服务总线主题触发 Azure 函数中使用 Polly 重试而不是 ExponentialBackoffRetry 吗? - Can we use Polly retry instead of ExponentialBackoffRetry in Service Bus Topic Trigger Azure Function? 锁定时间到期后,我不能续订吗? 使用Azure Service Bus主题 - Can't i renew the lock after the lock duration has expired ? Using Azure Service Bus Topic Azure Service Bus重试策略不会更改行为 - Azure Service Bus Retry Policy doesn't change the behavior Azure服务总线主题体系结构 - Azure Service Bus Topic Architecture 如何在Azure Service Bus主题上删除DeadLetter消息 - How do I delete a DeadLetter message on an Azure Service Bus Topic 在TaskCancelationException上重试Azure服务总线消息 - Azure Service Bus message retry on TaskCancelationException Azure 服务总线重试选项不起作用 - Azure Service Bus Retry Options Not Working Azure 服务总线:代理主题订阅侦听器 - Azure Service Bus: proxying topic subscription listeners
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM