Azure Service Bus队列如何在HTTPS模式下将消息传递到客户端 [英] How Azure Service Bus Queue delivers messages to client on HTTPs mode

查看:97
本文介绍了Azure Service Bus队列如何在HTTPS模式下将消息传递到客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在应用程序中对Azure Service Bus队列使用HTTPS模式。

ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Https;

但我们不确定Azure Service Bus如何以HTTPS模式传递消息,如果Service Bus客户端使用轮询,轮询到Azure Service Bus队列的频率。

我们使用Package:

Microsoft.ServiceBus;
Microsoft.ServiceBus.Messaging;

推荐答案

我们似乎没有任何有关这方面的官方文档。然而,大多数Service Bus客户端使用长轮询,这意味着它们打开到Service Bus的连接,并使其保持打开状态,直到它们接收到数据。如果收到消息,则客户端处理该消息并打开新连接。如果连接超时,客户端将在增量回退期后打开新连接。According to the product team,超时时间设置为30秒。

您可以使用此测试程序来查看消息在发送到队列后需要多长时间才能收到。它当前设置为一次运行一条消息。通过使用批处理,总吞吐量可能比本例高得多。

在我的机器上,消息通常在被放入队列后100毫秒内被检索到。如果我将休眠时间设置为一个更大的间隔,则检索所需的时间会稍微长一些,因此增量后退是有效的。如果音量较低,则可能需要稍长一点的时间才能收到留言。

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();
        }
    }

这篇关于Azure Service Bus队列如何在HTTPS模式下将消息传递到客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆