[英]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.