【问题标题】:Azure IotHub routing is not functioningAzure IotHub 路由不起作用
【发布时间】:2020-09-02 20:40:40
【问题描述】:

我在 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,但未应用路由!知道为什么吗?

【问题讨论】:

  • 路由查询字符串正常。你能发布路线详细信息的屏幕sn-p吗?
  • 另外,出于测试目的,将 设备遥测消息 路由 (true) 添加到存储 blob。您应该会看到 json 格式文本中的消息正文,例如 { "messageType":"Test" }
  • IoT Hub 也会为路由发出诊断日志,这可能会有所帮助

标签: azure-iot-hub azure-iot-sdk azure-iot-hub-device-management


【解决方案1】:

你能用像$body.messageType='Test'这样的单引号试试吗?

【讨论】:

    【解决方案2】:

    我注意到 IotHub 资源的行为根本不正常。不同类型的错误消息开始出现,例如IotHub is not in an Active state

    删除并重新创建资源解决了问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-19
      • 2017-10-31
      • 2022-11-01
      • 2019-11-03
      • 1970-01-01
      • 2018-02-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多