Azure IotHub路由无法正常运行

问题描述

我在Azure IotHub中定义了以下路由查询: $body.messageType="Test"

并使用Microsoft.Azure.Devices.Client" SDK Version="1.28.0"

这是我非常简单的C#代码。

            var device = DeviceClient.CreateFromConnectionString(DeviceConnectionString);
       
            await device.OpenAsync();

            var obj = new
            {
                messageType = "Test"
            };

            var telemetryJson = JsonConvert.SerializeObject(obj);

            var message = new Message(Encoding.UTF8.GetBytes(telemetryJson));

            // Set message body type and content encoding. 
            message.ContentEncoding = "utf-8";
            message.ContentType = "application/json";

            await device.SendEventAsync(message);

消息已传递到IotHub,但未应用路由!知道为什么吗?

解决方法

您可以尝试使用$body.messageType='Test'这样的单引号吗?

,

我注意到IotHub资源的行为根本不正常。各种错误消息开始以IotHub is not in an Active state的形式出现。

删除并重新创建资源即可解决此问题。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...