使用SendBatchAsync方法将1000个代理消息发送到服务总线 [英] Sending 1000 brokered messages to the service bus using the SendBatchAsync method

查看:90
本文介绍了使用SendBatchAsync方法将1000个代理消息发送到服务总线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

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

Internal Server Error: The server did not provide a meaningful reply; this might be caused by a premature session shutdown. TrackingId:some guid here

但是,如果我尝试发送100条消息,则可以正常工作.如何使它一次发送1000条消息?

注意:每个邮件大小为1445字节

解决方案

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

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

该批次的最大尺寸与一个批次的最大尺寸相同 一条消息(当前为256 Kb).

我想您需要将批次进一步分成较小的批次,以免超过256K的限制.

I have an application wherein data is fetched from the SQL DB and sent to the service bus as brokered message. These are the steps:

  1. Data fetched from the DB(in batches of 1000)
  2. Each row of data converted into Brokered Message and added into a list.
  3. The list of 1000 brokered messages is sent to the service bus using SendBatchAsync method.

It is at the 3rd step that I am facing the issue. This is the code for that:

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

when the compiler comes to SendBatchAsync method, it gives an error that Error during communication with Service Bus. Check the connection information, then retry. with the inner exception being:

Internal Server Error: The server did not provide a meaningful reply; this might be caused by a premature session shutdown. TrackingId:some guid here

However if I try sending 100 messages, it works fine. What can I do to make it send 1000 messages at a time?

Note: each message size is 1445 bytes

解决方案

Unfortunately you can't because your total payload size is about 1.4 MB (1445 bytes * 1000) whereas maximum size of the batch allowed is 256 KB.

Ref: https://msdn.microsoft.com/en-us/library/microsoft.servicebus.messaging.topicclient.sendbatch.aspx (Remarks section)

The maximum size of the batch is the same as the maximum size of a single message (currently 256 Kb).

I guess you would need to split the batch further into smaller batches so that you don't exceed 256K limit.

这篇关于使用SendBatchAsync方法将1000个代理消息发送到服务总线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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