2
votes

We uses HTTPs mode for Azure Service Bus Queue in our application.

ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Https;

But we are not sure how Azure Service Bus delivers messages in HTTPs mode, if Service Bus client uses polling, how often for the polling to Azure Service Bus queue.

We use package:

Microsoft.ServiceBus;
Microsoft.ServiceBus.Messaging;
1

1 Answers

1
votes

We don’t appear to have any official documentation on this. However, most Service Bus clients use long polling, which means they open a connection to Service Bus and leave it open until they receive data. If a message is received, the client processes the message and opens a new connection. If the connection times out, the client will open a new connection after an incremental back off period. According to the product team, the timeout period is set to 30 seconds.

You can use this test program to see how long it takes for a message to be received after it is sent to a queue. It is currently set up to run one message at a time. By using batching, the total throughput can be much higher than this example.

On my machine, the message was generally retrieved within 100 milliseconds of being placed on the queue. If I set the sleepTime to a larger interval, then the retrieval would take slightly longer, so an incremental back off is in effect. If the volume is low, it might take a little longer for a message to be picked up.

class Program
    {
        private static readonly string connectionString = "";
        private static readonly int sleepTime = 100;
       private static readonly int messageCount = 10;
        static void Main(string[] args)
        {
            ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Https;

            var client = QueueClient.CreateFromConnectionString(connectionString, "testqueue");
            client.PrefetchCount = 1;
            var timeCheck = DateTime.UtcNow;

            client.OnMessage((message) =>
            {
                var timing = (DateTime.UtcNow - message.EnqueuedTimeUtc).TotalMilliseconds;
                Console.WriteLine($"{message.GetBody<string>()}: {timing} milliseconds between between send and receipt.");
            });

            for (int i = 0; i < messageCount; i++)
            {
                client.Send(new BrokeredMessage($"Message {i}"));
                Console.WriteLine($"Message {i} sent");
                Thread.Sleep(sleepTime);
            }

            Console.WriteLine("Test Complete");

            Console.ReadLine();
        }
    }