Azure Iot Hub FeedbackReceiver ReceiveAsync is ver

2019-04-10 18:50发布

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条回答
来,给爷笑一个
2楼-- · 2019-04-10 19:28

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.

查看更多
登录 后发表回答