Azure服务总线:如何续订锁? [英] Azure Service Bus: How to Renew Lock?

查看:93
本文介绍了Azure服务总线:如何续订锁?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更新接收队列消息处理程序上的锁定? 在事件处理程序上,测试消息不具有续订锁定属性.

How do I renew the lock on a Receiving Queue Message Handler? On the Event Handler, test Message does not have renew lock property.

Message testMessage;

https ://docs.microsoft.com/zh-cn/dotnet/api/microsoft.servicebus.messaging.brokeredmessage.renewlock?view = azure-dotnet

推荐答案

您上面发布的RenewLock api链接来自旧的,已弃用的WindowsAzure.ServiceBus nuget包,其中RenewLock方法是BrokeredMessage的一部分.

The RenewLock api link you posted above is from the old deprecated WindowsAzure.ServiceBus nuget package where RenewLock method was part of BrokeredMessage.

当前软件包Microsoft.Azure.ServiceBus(您正确使用的)具有RenewLockAsync方法作为Receiver的一部分

The current package Microsoft.Azure.ServiceBus (which you are rightly using) has RenewLockAsync method as part of the Receiver https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.servicebus.core.messagereceiver.renewlockasync?view=azure-dotnet. You can call that method from your QueueClient instance like queueClient.RenewLockAsync(testMessage) or queueClient.RenewLockAsync(message.SystemProperties.LockToken).

但是,除了手动进行繁琐的工作外,您还可以通过设置MessageHandlerOptions的MaxAutoRenewDuration属性来利用自动更新锁定功能.这将在

But instead of the hard work of doing it by hand, you can leverage the auto-renew lock feature by setting MaxAutoRenewDuration property of MessageHandlerOptions. That would be in method RegisterOnMessageHandlerAndReceiveMessages in this example.

        static void RegisterOnMessageHandlerAndReceiveMessages()
        {
            // Configure the MessageHandler Options in terms of exception handling, number of concurrent messages to deliver etc.
            var messageHandlerOptions = new MessageHandlerOptions(ExceptionReceivedHandler)
            {
                // Maximum number of Concurrent calls to the callback `ProcessMessagesAsync`, set to 1 for simplicity.
                // Set it according to how many messages the application wants to process in parallel.
                MaxConcurrentCalls = 1,

                // Indicates whether MessagePump should automatically complete the messages after returning from User Callback.
                // False below indicates the Complete will be handled by the User Callback as in `ProcessMessagesAsync` below.
                AutoComplete = false,

                // https://docs.microsoft.com/en-us/azure/service-bus-messaging/message-transfers-locks-settlement#peeklock
                MaxAutoRenewDuration = <some timespan>
            };

            // Register the function that will process messages
            queueClient.RegisterMessageHandler(ProcessMessagesAsync, messageHandlerOptions);
        }

这篇关于Azure服务总线:如何续订锁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆