为服务总线工作程序角色设置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.
我认为这是因为该值默认为60秒.
I figured that this is because this value defaults to 60 seconds.
但是我不确定如何增加此值,因为在任何地方都看不到messageFactorySettings类.
But I am not sure how to increase this value, because i am not seeing the messageFactorySettings class anywhere.
我在哪里设置此属性?
这是我正在使用的代码
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();
}
}
推荐答案
使用ConnectionStringBuilder,它比自己为MessagingFactory创建必要的地址更容易使用:
Use the ConnectionStringBuilder which is easier to use than creating the necessary address for MessagingFactory by yourself:
var builder = new ServiceBusConnectionStringBuilder(_connectionString)
{
OperationTimeout = TimeSpan.FromMinutes(2)
};
var messagingFactory = MessagingFactory.CreateFromConnectionString(builder.ToString());
var queueClient = MessagingFactory.CreateQueueClient(_queuePath);
这篇关于为服务总线工作程序角色设置OperationTimeOut属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!