大量数据未在 Azure 事件中心发布

问题描述

我正在使用 EventHubProducerClient 类在 Azure 事件中心发布消息。 当我尝试发送大量数据时,假设一条一条的发送 1000 条消息,此测试用例通过,但我在事件中心仪表板上只看到 400-500(随机数)。这是代码。

parser = argparse.ArgumentParser(description='SImple Example')    
parser.add_argument('-x','--height',help='Height of the box')
parser.add_argument('-l','--length',type=int,help='Length of the box')
parser.add_argument('-b','--breadth',help='Breadth of the box')
parser.add_argument('--stop',nargs=0,required=False,action=StopAction)

while True:
    args = parser.parse_args(input("enter text: ").split())

但是,如果我尝试在列表中发布它们,我可以看到事件中心上的所有数据。

public async Task TestEventHubPublishMessagesSequentially()
{
    var eventHubConnectionString = "XXXXX.CONNECTION STRING.XXXX";
    var eventHubName = "XXXXX.EVENT HUB NAME.XXXX";

    var messsage = "I am a message"
    int tobePublishCount = 2000;
    int publishCount = 0;
    for (int i = 0; i < tobePublishCount; i++)
    {
       var completeMessage = $"Index:{i}-message";
       var success = await PublishMessageSequentially(eventHubConnectionString,eventHubName,completeMessage);
       if (success)
       {
          publishCount++;
       }
    }

    Assert.Equal(2000,publishCount);
 }
      
 public async Task<bool> PublishMessageSequentially(string eventHubConnectionString,string eventHubName,string messageToPublish)
 {
     await using (var producerClient = new EventHubProducerClient(eventHubConnectionString,eventHubName))
     {
        using EventDataBatch eventBatch = await producerClient.CreateBatchAsync();

        var data = new Azure.Messaging.EventHubs.EventData(Encoding.UTF8.GetBytes(messageToPublish));

        if (eventBatch.TryAdd(data))
        {
           await producerClient.SendAsync(eventBatch);
           return true;
        }
    }
    return false;
 }

我不知道出了什么问题,唯一的区别,我可以看到我一次又一次地创建了一个新的 EventHubProducerClient 对象,但我也在处理它。我认为事件中心旨在消耗大量数据(每秒数百万)。我的用例是我必须将它们一一发布。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...