本文介绍了尝试消息上的Azure服务总线异常以完成消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用GitHub示例处理主题消息:

I'm using the GitHub example to process the messages of a topic:

private void RegisterSubscriptionClientMessageHandler()
        {
            _subscriptionClient.RegisterMessageHandler(
                async (message, token) =>
                {
                    var eventName = $"{message.Label}{INTEGRATION_EVENT_SUFIX}";
                    var messageData = Encoding.UTF8.GetString(message.Body);
                    await ProcessEvent(eventName, messageData);

                    // Complete the message so that it is not received again.
                    await _subscriptionClient.CompleteAsync(message.SystemProperties.LockToken);
                },
               new MessageHandlerOptions(ExceptionReceivedHandler) { MaxConcurrentCalls = 10, AutoComplete = false });
        }

所有订户都成功发送和接收了所有消息,但是在命令中:

All messages are sent and received by all subscribers successfully, however in the command:

await _subscriptionClient.CompleteAsync(message.SystemProperties.LockToken);

总是会出现以下错误:

 ERROR ON ExceptionReceivedHandler EXEPTION: The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue, or was received by a different receiver instance.
Bazinga.EventBus.Bus.EventBusSubscription:Error: ERROR ON ExceptionReceivedHandler EXEPTION: The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue, or was received by a different receiver instance.
- Executing Action: UserCallback

有关如何解决的任何提示?谢谢!

Any tips on how to solve? Thank you!

推荐答案

从服务总线队列或主题订阅中收到消息时,将返回一条带有消息的锁定令牌。

When a message is received from Service Bus Queue or Topic Subscription, a lock token will be returned with the message.

锁令牌可用于删除,无用信或延迟消息。

The lock token can be used to delete, dead letter or defer a message.

每个队列和主题订阅都具有锁定持续时间属性。根据为锁定持续时间配置的时间跨度,消息随附的锁定将失效。

Every Queue and Topic Subscription has Lock duration property with it. Based on the time span configured for Lock duration, the lock supplied with the message will be expired.

在这里,您在完成消息之前正在做一些处理 await ProcessEvent(eventName,messageData);

Here, you are doing some processing await ProcessEvent(eventName, messageData); before completing the message.

问题必须是锁在 _subscriptionClient.CompleteAsync(message.SystemProperties.LockToken); 行执行之前已过期

The problem must be the the lock gets expired before_subscriptionClient.CompleteAsync(message.SystemProperties.LockToken); line is executed.

增加锁定持续时间或在调用ProcessEvent之前完成消息将解决您的问题。

Increasing the lock duration or completing the message before calling ProcessEvent will solve your problem.

这篇关于尝试消息上的Azure服务总线异常以完成消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 04:22