如何使用路由查询将消息路由到服务总线队列?

问题描述:

我有一个IoT中心,该中心具有连接的设备,可以发送遥测消息.我想分别从每个设备读取消息,因此我决定为每个设备创建一个不同的终结点.为了对消息进行排序,我将路由与查询一起使用,但是当我向路由添加查询规则时,消息将停止到达端点.连接的设备使用MQTT.

I have an IoT hub with connected devices which sends telemetry messages. I want to read messages from each device separately, so I decided to create a different endpoint for each device. For sorting messages I use routes with query, but when I add a query rule to the route, messages stop going to the endpoint. Connected device uses MQTT.

以下是屏幕截图:

  • Endpoint
  • Routes
  • toMyEndpoint route

您的查询表达式正确.

但是请确保您按如下所示设置内容类型和内容编码:

But make sure you set content type and content encoding like this:

Message eventMessage = new Message(Encoding.UTF8.GetBytes("{\"boarded\":\"0\"}"));
eventMessage.ContentType = "application/json";
eventMessage.ContentEncoding = "utf-8";

对我有用.