【发布时间】:2021-12-28 10:16:38
【问题描述】:
我正在尝试做一个 PoC 来测试 Azure Service Bus Premium 的最新功能,该功能可以处理大小为 100 MB 的消息。我尝试了两种模式。
-
批量发送 3495253 条消息,累积消息 sizeInBytes 为 104857595。这绝对小于 100 MB 的限制。当我这样做时,我收到以下错误, System.InvalidOperationException: '链接'G5S2:196:amqps://sbpocbatching1.servicebus.windows.net/-c53a3e1c;0:5:6' 被代理强制分离,因为发布者(link82)收到了一个没有里面的数据。分离来源:Publisher。'
-
如果我尝试在该批次中发送一条大小为 100MB 的消息,它会在 1 分钟后超时。
这是我的问题还是 Azure 的问题?我有一个非常好的互联网连接,显示 350 Mbps 下载和 300 Mbps 上传。
谁能解释一下我在这里错过了什么?
using System;
using System.Text;
using System.Threading.Tasks;
using Azure.Messaging.ServiceBus;
// connection string to your Service Bus namespace
string connectionString = "Endpoint=sb://sbpocbatching1.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=czthvMkrDa6W34KrpfOHttKpEnuv90oWfAh6Z9tBpCM=";
// name of your Service Bus topic
string topicName = "mytopic";
// the client that owns the connection and can be used to create senders and receivers
ServiceBusClient client;
// the sender used to publish messages to the topic
ServiceBusSender sender;
// number of messages to be sent to the topic
int numOfMessages = 0;
//byte[] data = new byte[100 * 1024 * 1024];
//Random rng = new Random();
//rng.NextBytes(data);
string strdata = GenerateString();
{
// The Service Bus client types are safe to cache and use as a singleton for the lifetime
// of the application, which is best practice when messages are being published or read
// regularly.
//
// Create the clients that we'll use for sending and processing messages.
client = new ServiceBusClient(connectionString);
sender = client.CreateSender(topicName);
// create a batch
using ServiceBusMessageBatch messageBatch = await sender.CreateMessageBatchAsync();
//messageBatch.TryAddMessage(new ServiceBusMessage(strdata));
for (numOfMessages = 0; numOfMessages <= 104857600; numOfMessages++)
{
//if (messageBatch.SizeInBytes >= messageBatch.MaxSizeInBytes / 4)
// break;
// try adding a message to the batch
if (!messageBatch.TryAddMessage(new ServiceBusMessage(strdata)))
{
// if it is too large for the batch
//throw new Exception($"The message {i} is too large to fit in the batch.");
break;
}
}
try
{
// Use the producer client to send the batch of messages to the Service Bus topic
await sender.SendMessagesAsync(messageBatch);
Console.WriteLine($"A batch of {numOfMessages} messages has been published to the topic.");
}
finally
{
// Calling DisposeAsync on client types is required to ensure that network
// resources and other unmanaged objects are properly cleaned up.
await sender.DisposeAsync();
await client.DisposeAsync();
}
Console.WriteLine("Press any key to end the application");
Console.ReadKey();
GenerateString();
}
String GenerateString()
{
int length = 1;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < length; i++)
{
sb.Append("A");
}
return sb.ToString();
}
【问题讨论】:
-
虽然总大小不到 100MB,但一批 3,495,253 条消息听起来像是一个值得研究的问题点。
-
@SeanFeldman:感谢您的回复。没有记录在案的批次中有大量消息的实例。否则,Microsoft 应该告诉我们批次中可接受的计数是多少。此外,正如您所指出的,我在一条消息中发送所有 100 MB 的第二个选项也永远不会通过。我的网速很好,上下 300 Mbps。
-
批处理中的消息数量存在限制,文档目前没有很好地突出显示 - 但内容作者正在努力解决这些问题。 SDK 无法预先验证这一点,因为该限制当前未暴露在服务之外。更多上下文可以在这里找到:github.com/Azure/azure-sdk-for-net/issues/21451
标签: azure azure-devops azureservicebus