蔚蓝IOT集线器FeedbackReceiver ReceiveAsync非常慢(15秒)的高延迟 [英] Azure Iot Hub FeedbackReceiver ReceiveAsync is very slow (15 seconds) high latency

查看:266
本文介绍了蔚蓝IOT集线器FeedbackReceiver ReceiveAsync非常慢(15秒)的高延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我通过物联网,集线器发送消息(云2设备):

if I send a message (Cloud 2 Device) via the IoT-Hub:

var serviceMessage= new Message(Encoding.ASCII.GetBytes("Hello Device"));
serviceMessage.Ack = DeliveryAcknowledgement.Full;
commandMessage.MessageId = Guid.NewGuid().ToString();
await serviceClient.SendAsync("myDeviceID", serviceMessage);  //Send message here

和尝试从客户端接收的acknoledgement:

And try to receive the acknoledgement from the client:

bool feedbackReceived = false;
while(!feedbackReceived){
  FeedbackReceiver<FeedbackBatch> feedbackReceiver = serviceClient.GetFeedbackReceiver();
  var feedbackBatch = await feedbackReceiver.ReceiveAsync(TimeSpan.FromSeconds(1));
  if(feedbackBatch != null)
    {
      feedbackReceived = feedbackBatch.Records.Any(fm => fm.OriginalMessageId == serviceMessage.MessageId);
      if (feedbackReceived)
        {
          await feedbackReceiver.CompleteAsync(feedbackBatch);
          feedbackReceiver = null;
        }
    }
}

我的客户immediatelly得到消息并发送反馈:

My client gets the message immediatelly and sends an feedback:

DeviceClient deviceClient = DeviceClient.Create(iotHubUri, new DeviceAuthenticationWithRegistrySymmetricKey(bridgeID, deviceKey), TransportType.Amqp);
Message receivedMessage = await deviceClient.ReceiveAsync();
await deviceClient.CompleteAsync(receivedMessage);

这最多需要15秒,直到我云得到反馈。
如果我在一个循环发送邮件,那么第一个消息需要1到15之间sconds的东西,每一个反应之后究竟需要15秒。

It take up to 15 seconds until my Cloud gets the feedback. If I send messages in a loop, then the first message needs something between 1 and 15 sconds and every following response needs exactly 15 seconds.

为什么这个需要这么长时间?我可以改变它?
我在云中的接收方法得到的答案immediatelly:

Why does that need so long? Can I change it? The receive-method in my cloud gets an answer immediatelly:

var incommingMessage = eventHubReceiver.ReceiveAsync();
incommingMessage.Wait();

如果客户端发送一个消息:

If the client sends a message:

var message = new Message(Encoding.ASCII.GetBytes("My Message"));
await deviceClient.SendEventAsync(message);

在问题的整个项目在GitHub上:
https://github.com/Ben4485/Azure_IotHub_Get_Response

推荐答案

当然,15秒一个都不少。然而,反馈不是一个单一的消息,但始终包含来自多个器件反馈批处理(JSON文档与反馈的数组)。这有可能是系统尝试将它们发送到系统之前获得更多的反馈越好。

Of course 15 seconds are a lot. However, the feedback isn't a single message but always a batch (a JSON document with an array of feedback) that contains more feedbacks from more devices. It's possible that the system tries to acquire more feedback as possible before sending them to the system.

保罗。

这篇关于蔚蓝IOT集线器FeedbackReceiver ReceiveAsync非常慢(15秒)的高延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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