Azure Iot Hub FeedbackReceiver ReceiveAsync is very slow (15 seconds) high latency

六月ゝ 毕业季﹏ 提交于 2019-12-06 08:18:34

问题


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

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;
        }
    }
}

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);

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.

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);

A whole project with the problem is on gitHub: https://github.com/Ben4485/Azure_IotHub_Get_Response


回答1:


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.

Paolo.



来源:https://stackoverflow.com/questions/33689947/azure-iot-hub-feedbackreceiver-receiveasync-is-very-slow-15-seconds-high-laten

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!