Azure Iot Hub FeedbackReceiver ReceiveAsync 非常慢(15 秒)高延迟
Azure Iot Hub FeedbackReceiver ReceiveAsync is very slow (15 seconds) high latency
如果我通过 IoT-Hub 发送消息(Cloud 2 设备):
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
并尝试接收来自客户端的确认:
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;
}
}
}
我的客户立即收到消息并发送反馈:
DeviceClient deviceClient = DeviceClient.Create(iotHubUri, new DeviceAuthenticationWithRegistrySymmetricKey(bridgeID, deviceKey), TransportType.Amqp);
Message receivedMessage = await deviceClient.ReceiveAsync();
await deviceClient.CompleteAsync(receivedMessage);
我的云收到反馈最多需要 15 秒。
如果我循环发送消息,那么第一条消息需要 1 到 15 秒之间的时间,而接下来的每个响应都需要恰好 15 秒。
为什么需要这么长时间?我可以改变它吗?
我云中的接收方法立即得到答案:
var incommingMessage = eventHubReceiver.ReceiveAsync();
incommingMessage.Wait();
如果客户端发送消息:
var message = new Message(Encoding.ASCII.GetBytes("My Message"));
await deviceClient.SendEventAsync(message);
有问题的整个项目都在 gitHub:
https://github.com/Ben4485/Azure_IotHub_Get_Response
当然15秒很多了。但是,反馈不是单个消息,而是始终包含来自更多设备的更多反馈的批处理(包含一系列反馈的 JSON 文档)。系统有可能在将它们发送到系统之前尝试获取更多反馈。
保罗.
如果我通过 IoT-Hub 发送消息(Cloud 2 设备):
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
并尝试接收来自客户端的确认:
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;
}
}
}
我的客户立即收到消息并发送反馈:
DeviceClient deviceClient = DeviceClient.Create(iotHubUri, new DeviceAuthenticationWithRegistrySymmetricKey(bridgeID, deviceKey), TransportType.Amqp);
Message receivedMessage = await deviceClient.ReceiveAsync();
await deviceClient.CompleteAsync(receivedMessage);
我的云收到反馈最多需要 15 秒。 如果我循环发送消息,那么第一条消息需要 1 到 15 秒之间的时间,而接下来的每个响应都需要恰好 15 秒。
为什么需要这么长时间?我可以改变它吗? 我云中的接收方法立即得到答案:
var incommingMessage = eventHubReceiver.ReceiveAsync();
incommingMessage.Wait();
如果客户端发送消息:
var message = new Message(Encoding.ASCII.GetBytes("My Message"));
await deviceClient.SendEventAsync(message);
有问题的整个项目都在 gitHub: https://github.com/Ben4485/Azure_IotHub_Get_Response
当然15秒很多了。但是,反馈不是单个消息,而是始终包含来自更多设备的更多反馈的批处理(包含一系列反馈的 JSON 文档)。系统有可能在将它们发送到系统之前尝试获取更多反馈。
保罗.