Closed SlothFriend closed 4 years ago
Thank you for your work and your time considering this new feature.
Hi @SlothFriend , if you input a valid json, the D2C message will be sent as what it is. Is this JSON message different with what you do with other way (e.g. using device SDK)?
Closing due to inactivity. Please reopen this issue or create a new issue if you need more help.
Hi @formulahendry!
Sorry for the delay - I've been out of office with the holidays. To continue the conversation...
While the body arrives as a string in JSON format, the main issue lies with the contentType
not being set to JSON. When sending messages with the SDK, we would do something like this:
const message = new Message(data);
message.contentEncoding = "utf-8";
message.contentType = "application/json";
It is my experience (and I've read from a few sources) that without an explicit set of this contentType
message routing in IoT Hub based on message body properties does not work. This is what I'm experiencing when sending D2C messages through VSCode.
For reference, here's an article mentioning the requirement on contentType
. Hope it helps.
https://azure.microsoft.com/en-us/blog/iot-hub-message-routing-now-with-routing-on-message-body/
Let me know if this makes sense. Thanks!
Thanks @SlothFriend for the detailed info! We will investigate on it
I'm having the same problem on my end. My code expects to be able to read a json-formatted body from the IoT hub event but instead it's being encoded in base64 as stated here:
Device telemetry message must be in a valid JSON format with the contentType set to application/json and contentEncoding set to UTF-8 in the message system properties. Both of these properties are case insensitive. If the content encoding is not set, then IoT Hub will write the messages in base 64 encoded format.
Took me a while to figure this out, this behavior is not intuitive at all
Same here. Testing IoT Hub routing did not work when generating messages using the D2C message interface from this extension. The IoTHub log shows the error "Content encoding is not specified in system properties." Please add the ContentEncoding and ContentType system properties as suggested by @SlothFriend.
Thank you Michiel, this will be part of release 2.16.3. Closing this issue.
@montgomp for me sending D2C message from this extension is still not working (version 2.16.6). The resulting data in body is still somehow encoded. Can you share a sample for plain text and/or data template message with which should be used to test routing in IotHub?
This has been incorporated in 2.4.1 the Message class has an added setter for set encoding
Please allow support for different contentTypes when submitting D2C messages, specifically JSON type. This is a significant problem because IoT Hub route queries only work when contentType is set to
application/json
. This means I can't use the extension to test routes and their down-stream connections.