简体   繁体   English

为Service Bus worker角色设置OperationTimeOut属性

[英]Setting the OperationTimeOut property for a Service bus worker role

I am creating a worker role using the service bus worker role template. 我正在使用服务总线工作者角色模板创建一个辅助角色。

It is taking more than a minute for me to process each message. 处理每条消息需要一分多钟的时间。

Because of this, i am seeing that the same message is received by the worker role multiple times, roughly one message every minute. 因此,我看到工作者角色多次收到相同的消息,大约每分钟一条消息。

I figured that this is because this value defaults to 60 seconds. 我想这是因为这个值默认为60秒。

http://msdn.microsoft.com/en-us/library/microsoft.servicebus.messaging.messagingfactorysettings.operationtimeout.aspx http://msdn.microsoft.com/en-us/library/microsoft.servicebus.messaging.messagingfactorysettings.operationtimeout.aspx

But I am not sure how to increase this value, because i am not seeing the messageFactorySettings class anywhere. 但我不知道如何增加这个值,因为我没有在任何地方看到messageFactorySettings类。

Where do I set this property? 我在哪里设置这个属性?

here is the code I am using 这是我正在使用的代码

public class WorkerRole : RoleEntryPoint
    {

        // QueueClient is thread-safe. Recommended that you cache 
        // rather than recreating it on every request
        QueueClient Client;
        ManualResetEvent CompletedEvent = new ManualResetEvent(false);

        public override void Run()
        {

            Client.OnMessage((receivedMessage) =>
                {
                    ProcessMessage(recievedMessage);
                });

            CompletedEvent.WaitOne();
        }

        public override bool OnStart()
        {
            ServicePointManager.DefaultConnectionLimit = 12;

            string connectionString = ConfigurationUtility.GetConnectionString("Microsoft.ServiceBus.ConnectionString");
            string queneName = ConfigurationUtility.GetConnectionString("QueueName");

            // Create the queue if it does not exist already
            var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
            if (!namespaceManager.QueueExists(queneName))
            {
                namespaceManager.CreateQueue(queneName);

            }

            Client = QueueClient.CreateFromConnectionString(connectionString, queneName);
            return base.OnStart();
        }

        public override void OnStop()
        {
            // Close the connection to Service Bus Queue
            Client.Close();
            CompletedEvent.Set();
            base.OnStop();
        }
    }

Use the ConnectionStringBuilder which is easier to use than creating the necessary address for MessagingFactory by yourself: 使用ConnectionStringBuilder比自己创建MessagingFactory所需的地址更容易使用:

var builder = new  ServiceBusConnectionStringBuilder(_connectionString)
{
OperationTimeout = TimeSpan.FromMinutes(2) 
};

var messagingFactory = MessagingFactory.CreateFromConnectionString(builder.ToString());
var queueClient = MessagingFactory.CreateQueueClient(_queuePath);

From what I can gather, you need to use the MessagingFactory class to do this. 根据我的收集,您需要使用MessagingFactory类来执行此操作。

I've just written the following to increase the timeout to 2 mins: 我刚写了以下内容将超时时间增加到2分钟:

MessagingFactorySettings settings = new MessagingFactorySettings { 
                OperationTimeout = new TimeSpan(0, 2, 0), 
                TokenProvider = TokenProvider.CreateSharedSecretTokenProvider("issuer", "sharedkey") };

var address = ServiceBusEnvironment.CreateServiceUri("sb", "serviceNamespace", string.Empty);

var messagingFactory = MessagingFactory.Create(address, settings);

return messagingFactory.CreateSubscriptionClient("queueName");

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

相关问题 具有工作人员角色的Azure Service Bus主题和订阅 - Azure Service Bus Topics and Subscriptions with Worker Role Azure Service Bus SDK / NuGet中的serverWaitTime和operationTimeout之间的差异 - Difference between serverWaitTime and operationTimeout in Azure Service Bus SDK/NuGet 带有未处理的服务总线故障消息的Azure工作人员角色回收 - Azure worker role recycling with unhandled Service Bus fault message Azure Service Bus广播到所有工作者角色实例 - Azure Service Bus broadcast to all worker role instances 如何在Web角色和除Service Bus之外的辅助角色之间发送消息? - How to send messages between web role and worker role other than Service Bus? 在Wcf RoutingService上设置OperationTimeout - Setting OperationTimeout on Wcf RoutingService 当带有服务总线队列的辅助角色完成处理时,您如何通知? - How do you notify when a worker role with service bus queue completes it's processing? 单个故障后,Azure服务总线绑定导致工作人员角色变得不正常 - Azure Service Bus Binding causes Worker Role to become unhealthy after single fault 从具有工作角色的多个动态队列中接收Azure服务总线消息 - Receiving Azure service bus messages from multiple, dynamically queues with worker role 工作者角色的Azure服务费用 - Azure Service Charge For A Worker Role
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM