I invoke client.Send(brokeredMessage);
once, but I receive the message several times. For handle queue I use this code
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();
}
}
}
}
Problem is that BrokeredMessage message = client.Receive();
is invoked several times and return the same message, if execution of messageHandler(message);
takes long time. How can i fix it?