我调用client.Send(brokeredMessage);
了一次,但我收到了几次消息。对于句柄队列,我使用此代码
private static void HandleQueue(string queueName, MessageHandler messageHandler)
{
// Create the queue if it does not exist already
string connectionString =
Configuration.GetConnectionString("Microsoft.ServiceBus.ConnectionString",false);
var namespaceManager =
NamespaceManager.CreateFromConnectionString(connectionString);
if (!namespaceManager.QueueExists(queueName))
{
namespaceManager.CreateQueue(queueName);
}
QueueClient client =
QueueClient.CreateFromConnectionString(connectionString, queueName);
while (true)
{
BrokeredMessage message = client.Receive();
if (message != null)
{
try
{
messageHandler(message);
// Remove message from queue
message.Complete();
}
catch (Exception)
{
// Indicate a problem, unlock message in queue
message.Abandon();
}
}
}
}
问题是BrokeredMessage message = client.Receive();
多次调用并返回相同的消息,如果执行messageHandler(message);
需要很长时间。我该如何解决?