我在接收Mqtt协议上的消息属性和消息系统属性时遇到问题。但是在使用TransportType.Amqp时它可以正常工作。
是否可以在此页面的“接收消息”部分找到解释? https://azure.microsoft.com/da-dk/documentation/articles/iot-hub-mqtt-support/ 如果是,那是什么意思,我该怎么做?
收件人代码: 我正在使用来自nuget的1.0.12 of Microsoft.Azure.Devices.Client和所有依赖项。
//connectString: HostName=<host name>;DeviceId=<device id>;SharedAccessKey=<key>
//var deviceClient = DeviceClient.CreateFromConnectionString(connectString,TransportType.Amqp);
var deviceClient = DeviceClient.CreateFromConnectionString(connectString, TransportType.Mqtt);
while (true)
{
var message = await deviceClient.ReceiveAsync(TimeSpan.FromSeconds(2));
if (message != null)
{
//message.MessageId is null on Mqtt but not for Amqp!
}
}
发件人代码: 我正在使用Microsoft.Azure.Devices.dll的1.0.11版本
string messageId = Guid.NewGuid().ToString("D");
var iotHubConnection = "HostName=<host>;SharedAccessKeyName=<...>;SharedAccessKey=<...>";
var serviceClient = ServiceClient.CreateFromConnectionString(iotHubConnection);
if (serviceClient == null) throw new Exception("ServiceClient create failed");
var serviceMessage = new Microsoft.Azure.Devices.Message(Encoding.UTF8.GetBytes("Hello World"));
serviceMessage.Ack = DeliveryAcknowledgement.Full;
serviceMessage.MessageId = messageId;
serviceMessage.Properties["message-id"] = messageId;
serviceClient.SendAsync("0123", serviceMessage).Wait();
C示例代码读取属性,但csharp示例代码不会: https://github.com/Azure/azure-iot-sdks/blob/master/c/iothub_client/samples/iothub_client_sample_mqtt/iothub_client_sample_mqtt.c