使用SendBatchAsync方法向服务总线发送1000个代理消息

nit*_*igo 2 servicebus azure azureservicebus brokeredmessage

我有一个应用程序,其中数据从SQL DB获取并作为代理消息发送到服务总线.这些是步骤:

  1. 从DB获取的数据(批量为1000)
  2. 每行数据都转换为Brokered Message并添加到列表中.
  3. 使用SendBatchAsync方法将1000个代理消息的列表发送到服务总线.

这是我面临的第三步.这是代码:

public async Task SendMessagesAsync(List<BrokeredMessage> brokeredMessageList)
        {
            try
            {
                var topicClient = CreateTopicClient();
                await topicClient.SendBatchAsync(brokeredMessageList);
            }
            catch(Exception ex)
            {
                throw ex;
            }
        }
Run Code Online (Sandbox Code Playgroud)

当编译器使用SendBatchAsync方法时,它会在与Service Bus通信期间出现Error错误.检查连接信息,然后重试.内部例外是:

Internal Server Error: The server did not provide a meaningful reply; this might be caused by a premature session shutdown. TrackingId:some guid here
Run Code Online (Sandbox Code Playgroud)

但是,如果我尝试发送100条消息,它可以正常工作.我该怎么做才能让它一次发送1000条消息?

注意:每条消息大小为1445字节

Gau*_*tri 5

遗憾的是,您不能,因为您的总有效负载大小约为1.4 MB(1445字节*1000),而允许的批处理的最大大小为256 KB.

参考:https://msdn.microsoft.com/en-us/library/microsoft.servicebus.messaging.topicclient.sendbatch.aspx(备注部分)

批处理的最大大小与单个消息的最大大小(当前为256 Kb)相同.

我想你需要将批次进一步拆分成更小的批次,这样你就不会超过256K的限制.