I am playing around with Windows Service Bus (Not Azure) which I installed on my local machine. I followed the example here but swapped out for my local instance: http://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-queues/
I have two console apps setup right now, one is a receiver and the other is a sender. The receiver just listens for new messages and does a console.writeline of the output:
// Continuously process messages sent to the "TestQueue"
while (true)
{
BrokeredMessage message = Client.Receive();
if (message != null)
{
try
{
Console.WriteLine("Body: " + message.GetBody<string>());
Console.WriteLine("MessageID: " + message.MessageId);
Console.WriteLine("Test Property: " +
message.Properties["TestProperty"]);
Console.WriteLine("----------------------");
// Remove message from queue
message.Complete();
}
catch (Exception)
{
// Indicate a problem, unlock message in queue
message.Abandon();
}
}
}
Next I have my sender:
while (true)
{
// Create message, passing a string message for the body
BrokeredMessage message = new BrokeredMessage("Test message " + i);
// Set some addtional custom app-specific properties
message.Properties["TestProperty"] = "TestValue";
message.Properties["Message number"] = i;
// Send message to the queue
Client.Send(message);
i++;
System.Threading.Thread.Sleep(50);
}
This actually all works great. I can start up 1 receiver, and the sender and I can see messages. Then I start up a second receiver, and messages automatically pass back and forth between the two receivers.
However, when I spin up a 3rd receiver, the first receiver quits getting messages (until another one quits).
Is there a way to have all three (or "n") receivers process messages from the queue? I thought possibly there would be a setting in the queue setup but I can't seem to find.
If you decrease the sleep on your sender, does the first receiver start to retrieve messages? It may be that your queue is being over read such that the second and third receivers happen to retrieve messages but the first receiver isn't able to retrieve a message because the queue is empty.
Is your goal to have independent readers processing a queue, or are you after one-to-many communication where every receiver has an opportunity to process the message? If so, then you should look at using Topics and Subscriptions.