【问题标题】:How Azure Service Bus Queue delivers messages to client on HTTPs modeAzure 服务总线队列如何在 HTTPS 模式下向客户端传递消息
【发布时间】:2019-06-22 13:43:38
【问题描述】:
我们在应用程序中为 Azure 服务总线队列使用 HTTPS 模式。
ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Https;
但我们不确定 Azure 服务总线如何在 HTTPS 模式下传递消息,如果服务总线客户端使用轮询,轮询到 Azure 服务总线队列的频率。
我们使用包:
Microsoft.ServiceBus;
Microsoft.ServiceBus.Messaging;
【问题讨论】:
标签:
c#
azure
azureservicebus
azure-servicebus-queues
【解决方案1】:
我们似乎没有任何官方文档。但是,大多数服务总线客户端使用长轮询,这意味着它们打开到服务总线的连接并保持打开状态,直到它们接收到数据。如果收到消息,客户端会处理该消息并打开一个新连接。如果连接超时,客户端将在增量回退期后打开一个新连接。 According to the product team,超时时间设置为30秒。
您可以使用此测试程序查看消息发送到队列后需要多长时间才能收到。当前设置为一次运行一条消息。通过使用批处理,总吞吐量可以比这个例子高得多。
在我的机器上,消息通常在被放入队列后的 100 毫秒内被检索到。如果我将 sleepTime 设置为更大的间隔,则检索将花费稍长的时间,因此增量回退是有效的。如果音量较低,则接收消息可能需要更长的时间。
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();
}
}