Search code examples
c#azureazure-servicebus-queues

Why am I not getting queue messages using Azure Service Bus Queue?


I was following the documentation for How to use Service Bus Queues on Azure documentation.

I created 2 different web applications to test out using Queues for a project I need to work on. I created one project to publish messages into the queue and then the other application is supposed to listen to the Queue to process the messages.

I successfully was able to publish messages to the Queue and I can see that the queue length in the Azure portal says 3. So there should be 3 messages waiting for me to process. However, when I run the web application that has the QueueClient.OnMessage no messages are getting pushed. Is there something else that I am missing when doing this?

var client = QueueClient.CreateFromConnectionString(ConnectionString, "TestQueue");

        var options = new OnMessageOptions
        {
            AutoComplete = false,
            AutoRenewTimeout = TimeSpan.FromMinutes(1)
        };

        // Callback to handle received messages.
        client.OnMessage((message) =>
        {
            try
            {
                // Process message from queue.
                var messageBody = message.GetBody<string>();
                // Remove message from queue.
                message.Complete();
            }
            catch (Exception)
            {
                // Indicates a problem, unlock message in queue.
                message.Abandon();
            }
        }, options);
    }
}

The ConnectionStrings are the same in both applications so there is no differences there. Here is the code that I am using to connect and send a message to the Queue.

var client = QueueClient.CreateFromConnectionString(ConnectionString, "TestQueue");
        var message = new BrokeredMessage(value);

        message.Properties["TestProperty"] = "This is a test";
        message.Properties["UserId"] = "TestUser";

        client.Send(message);

If anyone has any insights into why this is happening it would be greatly appreciated.


Solution

  • So it turns out that I was running into a 407 Proxy Authentication Required error when trying to connect to the service bus that I noticed when trying to debug this through a different application. All I had to do was add the following to the system.net section of the web.config once I did that I was able to receive messages.

    <defaultProxy useDefaultCredentials="true">
    <proxy bypassonlocal="True" usesystemdefault="True"/>
    </defaultProxy>