locked
Azure IoTHub DeviceMessage and route filter RRS feed

  • Question

  • I use python and paho.mqtt for sending messages to cloud I set up endpoint and route. When I set query string to true, everything works fine

    messageDict = {}
    systemPropertiesDict = {"contentType": "application/json", "contentEncoding": "utf-8", "iothub-message-source": "deviceMessages", "iothub-enqueuedtime": "2017-05-08T18:55:31.8514657Z"}
    messageDict = {"systemProperties": systemPropertiesDict}
    messageDict["appProperties"] = {}
    body = '{id:1}'
    messageDict["body"] = body
    root = {"message":messageDict}
    msg = json.dumps(root, indent=2).encode('utf-8')
    print("Message to send", msg)
    self.client.publish(topicName, msg)

    But if I set the query string to $body.id = 1, then I don't receive any messages.

    Any ideas, guys?

    Tuesday, July 3, 2018 8:37 PM

Answers

  • Hello Ruslan,

    This because the content encoding type is not set. All the "systemProperties" in your code actually as message body not system properties. Content encoding type set by this method doesn't take effect, so the route not working.

    You can see the message your sent in device explorer and it looks like this:

    7/4/2018 11:36:36 AM> Device: [device1], Data:[{
      "message": {
        "systemProperties": {
          "contentType": "application/json",
          "contentEncoding": "utf-8",
          "iothub-message-source": "deviceMessages",
          "iothub-enqueuedtime": "2017-05-08T18:55:31.8514657Z"
        },
        "appProperties": {},
        "body": "{id:1}"
      }
    }]

    All content in Data:[{}] are as message body.

    Best regards,

    Rita


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Ruslan G Wednesday, July 4, 2018 9:02 AM
    Wednesday, July 4, 2018 3:39 AM
  • Hi Ruslan,

    - try the following: 

    topicName += "$.ct=application%2Fjson&$.ce=utf-8"

    then the device mqtt publish topic is:

    devices/{yourDeviceId}/messages/events/$.ct=application%2Fjson&$.ce=utf-8

    Thanks

    Roman




    Wednesday, July 4, 2018 4:38 AM

All replies

  • Hello Ruslan,

    This because the content encoding type is not set. All the "systemProperties" in your code actually as message body not system properties. Content encoding type set by this method doesn't take effect, so the route not working.

    You can see the message your sent in device explorer and it looks like this:

    7/4/2018 11:36:36 AM> Device: [device1], Data:[{
      "message": {
        "systemProperties": {
          "contentType": "application/json",
          "contentEncoding": "utf-8",
          "iothub-message-source": "deviceMessages",
          "iothub-enqueuedtime": "2017-05-08T18:55:31.8514657Z"
        },
        "appProperties": {},
        "body": "{id:1}"
      }
    }]

    All content in Data:[{}] are as message body.

    Best regards,

    Rita


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Ruslan G Wednesday, July 4, 2018 9:02 AM
    Wednesday, July 4, 2018 3:39 AM
  • Hi Ruslan,

    - try the following: 

    topicName += "$.ct=application%2Fjson&$.ce=utf-8"

    then the device mqtt publish topic is:

    devices/{yourDeviceId}/messages/events/$.ct=application%2Fjson&$.ce=utf-8

    Thanks

    Roman




    Wednesday, July 4, 2018 4:38 AM
  • Hello Ruslan,

    @Roman Kiss is right. It works.

    But to make the route query works on your message you need use this query string: $body.message.body.id = 1

    Best regards,

    Rita


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, July 4, 2018 6:07 AM
  • thank you! Where I could read about $.ct=application%2Fjson&$.ce=utf-8 and related parameters?

    Wednesday, July 4, 2018 9:03 AM
  • Thank  you. It works!
    Wednesday, July 4, 2018 9:03 AM
  • Hello Rita.

    Btw, how could I assign systemProperties and appProperties (I'm using mqtt)


    • Edited by Ruslan G Wednesday, July 4, 2018 9:05 AM
    Wednesday, July 4, 2018 9:05 AM
  • Hello Ruslan,

    If we can capture and decode the encrypted packet sent from Azure IoT SDK, maybe we can find out how the system property and application property added to the packet payload.

    I'll try to do and update if I can find out.

    Best regards,

    Rita


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, July 4, 2018 9:33 AM
  • Hi Roman, how have you found $.ct=application%2Fjson&$.ce=utf-8

    Where can I read about that?

    Wednesday, July 4, 2018 9:44 AM
  • Hi Ruslan,

    - see my answer on SO.

    Thanks

    Roman



    • Edited by Roman Kiss Wednesday, July 4, 2018 2:07 PM
    Wednesday, July 4, 2018 2:07 PM