ash*_*rya 4 .net c# servicebus azure azure-worker-roles
我正在使用服务总线工作者角色模板创建一个辅助角色.
处理每条消息需要一分多钟的时间.
因此,我看到工作者角色多次收到相同的消息,大约每分钟一条消息.
我想这是因为这个值默认为60秒.
但我不知道如何增加这个值,因为我没有在任何地方看到messageFactorySettings类.
我在哪里设置这个属性?
这是我正在使用的代码
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();
}
}
Run Code Online (Sandbox Code Playgroud)
使用ConnectionStringBuilder比自己创建MessagingFactory所需的地址更容易使用:
var builder = new ServiceBusConnectionStringBuilder(_connectionString)
{
OperationTimeout = TimeSpan.FromMinutes(2)
};
var messagingFactory = MessagingFactory.CreateFromConnectionString(builder.ToString());
var queueClient = MessagingFactory.CreateQueueClient(_queuePath);
Run Code Online (Sandbox Code Playgroud)