Repository navigation
Enable Routing on Message Body #118
Description
-
OS and version used: Ubuntu 16.04
-
Java runtime used: Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
-
SDK version used:
<dependency> <groupId>com.microsoft.azure.sdk.iot</groupId> <artifactId>iot-device-client</artifactId> <version>1.3.30</version> </dependency>
Description of the issue:
I want to set the System Properties „ContentEncoding“ und „ContentType“ to enable routing on message body. As it mentioned in the article (https://azure.microsoft.com/de-de/blog/iot-hub-message-routing-now-with-routing-on-message-body/).
Actually, I see no possibilities to set these two system properties with this version of the SDK.
Do I got something wrong here?
Console log of the issue:
If is send a message with Java SDK it looks like:
12.07.2017 09:41:39> Device: [XXXXXXXXXXXXXXX], Data:[…]Properties:
'source': 'XXXXXXXXXXXXXXXXX'
SYSTEM>x-opt-sequence-number=1808
SYSTEM>x-opt-offset=1767872
SYSTEM>x-opt-enqueued-time=12.07.2017 07:41:39
SYSTEM>iothub-connection-device-id=XXXXXXXXXXXXXXXXXXX
SYSTEM>iothub-connection-auth-method={"scope":"device","type":"sas","issuer":"iothub","acceptingIpFilterRule":null}
SYSTEM>iothub-connection-auth-generation-id=XXXXXXXXXXXXXXXXXX
SYSTEM>iothub-enqueuedtime=12.07.2017 07:41:38
SYSTEM>iothub-message-source=Telemetry
SYSTEM>EnqueuedTimeUtc=12.07.2017 07:41:39
SYSTEM>SequenceNumber=1808
SYSTEM>Offset=1767872
SYSTEM>message-id=4646f130-14f5-4717-baf5-75591ef132b9
SYSTEM>correlation-id=921262c0-bc75-4c92-88b0-a06e94c689ea
And if is send a message with C# SDK and set the two propteries it looks like:
12.07.2017 09:43:52> Device: [XXXXXXXXXXXXXXX], Data:[...]Properties:
'Status': 'Active'
SYSTEM>x-opt-sequence-number=1234
SYSTEM>x-opt-offset=773528
SYSTEM>x-opt-enqueued-time=12.07.2017 07:43:52
SYSTEM>iothub-connection-device-id=XXXXXXXXXXXXXXX
SYSTEM>iothub-connection-auth-method={"scope":"device","type":"sas","issuer":"iothub","acceptingIpFilterRule":null}
SYSTEM>iothub-connection-auth-generation-id=XXXXXXXXXXXXXXX
SYSTEM>iothub-enqueuedtime=12.07.2017 07:43:51
SYSTEM>iothub-message-source=Telemetry
SYSTEM>EnqueuedTimeUtc=12.07.2017 07:43:52
SYSTEM>SequenceNumber=1234
SYSTEM>Offset=773528
SYSTEM>content-type=application/json
SYSTEM>content-encoding=utf-8
As far as i understand these last two properties are mandatory for routing on message body.
Best regards,
Activity
[-]Enabling Routing on Message Body[/-][+]Enable Routing on Message Body[/+]prmathur-microsoft commentedon Jul 13, 2017
Which protocol are you using to send properties ?
it-bytes commentedon Jul 14, 2017
We are using the MQTT protocol. But in which way is this relevant? Shouldn't the com.microsoft.azure.sdk.iot.device.Message class not be independent from the chosen protocol?
Additionally, I am aware that the DEFAULT_IOTHUB_MESSAGE_CHARSET is UTF-8, but as it is not reflected into the message system properties, I am not sure in which way the "SYSTEM>content-encoding=utf-8" is set implicitly.
Best,
it-bytes commentedon Jul 18, 2017
Hey there,
is there any solution or suggestion forseeable?
Thx
prmathur-microsoft commentedon Jul 18, 2017
The protocol is relevant because it determines the way in which we set these headers. We are still investigating this issue.
prmathur-microsoft commentedon Jul 19, 2017
We have identified some changes that should go in as part of SDK to enable routing. We have added it to our backlog and will work on it.
it-bytes commentedon Jul 20, 2017
Thank you, I appreciate that.
sandeeps05 commentedon Jul 16, 2018
Hi, is there any solution formulated for this issue? Thanks!
timtay-microsoft commentedon Jul 16, 2018
We haven't had a chance to work on this lately. If you would like to provide a PR, we'd be happy to merge it in for you.
sandeeps05 commentedon Jul 16, 2018
Ok.. Just one more question, if I want to use 'Message.setProperty()' then should I set 'protocol = IotHubClientProtocol.AMQPS' (Or AMQP only supports metadata and MQTT doesn't) ?
timtay-microsoft commentedon Jul 16, 2018
All protocols support metadata, so you can set properties on a message regardless of protocol
sandeeps05 commentedon Jul 16, 2018
ok thanks for the response.. somehow setting MQTT-Metada combination didn't work for me and AMQP-metada worked like a charm!
timtay-microsoft commentedon Aug 20, 2018
Sorry for the really long delay on this issue, but we are now actively working on lighting up message routing for all protocols. Stay tuned.
timtay-microsoft commentedon Aug 30, 2018
The fix for this issue has been released as of Device Client 1.14.0, so I'm closing this issue now.
az-iot-builder-01 commentedon Aug 30, 2018
prmathur (@prmathur-microsoft), Dr. Paul Reinhold (@it-bytes), sandeeps84, thank you for your contribution to our open-sourced project! Please help us improve by filling out this 2-minute customer satisfaction survey
DharitaChokshi commentedon Sep 6, 2018
I am still facing this issue. The description is posted at https://stackoverflow.com/questions/52204809/azure-iothub-devicemessage-route-filter-on-message-body-not-working.
timtay-microsoft commentedon Sep 6, 2018
What format is the message body that you are providing? And what encoding are you using to serialize it into a byte[]? Are you making sure to set the content encoding property of the message that matches that encoding?
In the code sample you posted, it looks like you aren't setting either the contentEncoding or contentType on the message object. Assuming your message body is json, and you are using utf-8 to encoded that string, you need call
before sending the message
timtay-microsoft commentedon Sep 7, 2018
DharitaChokshi did my suggestions above help you, or are you still seeing an issue here?
DharitaChokshi commentedon Sep 9, 2018
Yes Tim Taylor (@timtay-microsoft), your suggestion did helped me. It is just the perfect thing that i was missing in my code. Thanks alot
I have one more question. My Service Bus queue is receiving telemetry of 2 different objects. For Object1 is have to send mail to MailId1 and for Object2 j have to send mail to MailId2. Also i have to use some of the content from hson telemetry as body of my mail.
For single object it is working fine. In my logic app i have used service bus followed by parse json and lastly stmp to send mail. In case i need to make decisions based kn json, what workflow i can use in LogicApp ?
timtay-microsoft commentedon Sep 10, 2018
I'm afraid I don't have much experience with setting up that kind of workflow in a Logic App. I recommend you reach out to a member of the logic apps team as they can help you better than I can.