[英]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
服务总线主题订阅属性
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);
await _creatorSubscription.AbandonAsync(message.SystemProperties.LockToken);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.