c# - Azure 服务总线队列如何在 HTTPS 模式下向客户端传递消息
问题描述
我们在应用程序中为 Azure 服务总线队列使用 HTTPS 模式。
ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Https;
但我们不确定 Azure 服务总线如何在 HTTPS 模式下传递消息,如果服务总线客户端使用轮询,轮询到 Azure 服务总线队列的频率。
我们使用包:
Microsoft.ServiceBus;
Microsoft.ServiceBus.Messaging;
解决方案
我们似乎没有任何官方文档。但是,大多数服务总线客户端使用长轮询,这意味着它们打开到服务总线的连接并保持打开状态,直到它们接收到数据。如果收到消息,客户端会处理该消息并打开一个新连接。如果连接超时,客户端将在增量回退期后打开一个新连接。根据产品团队的说法,超时时间设置为 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();
}
}
推荐阅读
- c - 使用 C 进行归并排序,输出出错
- nginx - Kubernetes 和 Nginx 的问题。错误代码
- typescript - 我们如何在 switch 代码下面进行更多优化?
- java - 运算符 && 未定义参数 String,JAVA 上的布尔值?
- typescript - Ionic3 on button click iframe.contentWindow.postMessage,每次点击都需要停止刷新url/iframe
- asp.net - 动态删除行后从视图中发布的值不正确
- excel - 使用 VBA 抓取网页以在匹配条件时返回数据
- cookies - Vaadin 8:动态打开和关闭 @Push 以将 @Push 与 cookie 一起使用
- python - Pandas 合并具有不同大小形状和列名的 DF 以及没有重复的频率
- python-3.x - 如何使用具有不同角色的 Python 从 S3 生产复制到 S3 开发?