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