Azure / Azure/azure-iot-sdk-node
Azure IoT Edge - route messages between modules: custom message properties are no propagated
- Dominant language
- JavaScript
- Stars
- 268
- Forks
- 228
- PR merge metrics
- No merged PRs in 30d
Description
# Context
- **Node.js version:** v18.15.0
- **npm version:** 9.5.0
- **list of installed packages:**
"azure-iot-device": "^1.18.2",
"azure-iot-device-mqtt": "^1.15.4"
## Description of the issue
I'm using IoT Edge to connect Modbus devices to IoT Hub and I'm trying to implement protocol + identity translation modules.
I started with the example [here](https://github.com/Azure-Samples/azure-iot-edge-identity-translation-lite)
I have two modules:
1. ModbusClient, for the protocol translation, in C#
2. IdentityTranslation, in NodeJS
Here is how routes are defined in the deployment file:
> "ModbusClientToIdentityTranslation": "FROM /messages/modules/ModbusClient/outputs/modbusOutput INTO BrokeredEndpoint(\\"/modules/IdentityTranslation/inputs/input1\\")",
>
> "IdentityTranslationToIoTHub": "FROM /messages/modules/IdentityTranslation/outputs/\* INTO $upstream"
I would like to add a property with the deviceId value in the message transformed by the ModbusClient and read this property in the IdentityTranslation module.
## Code sample exhibiting the issue
Here are the snippets of the code in the two modules:
- ModbusClient
> ```
> Message message = new Message(Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(out_message)));
> message.Properties.Add("content-type", "application/edge-modbus-json");
> message.Properties.Add("deviceId", deviceId);
>
> Console.WriteLine("deviceId " + message.Properties["deviceId"]);
> await ioTHubModuleClient.SendEventAsync("modbusOutput", message);
> ```
- IdentityTranslation
> ```
> moduleClient.on('inputMessage', function (inputName, msg) {
> console.log("new message received", msg);
> if (modbusClient) {
> // Identity Translation configured, wrap message for IoT device
> const message = msg.getBytes().toString('utf8');
> const sensorMsg = new Message(message);
> console.log("sensorMsg ", sensorMsg);
> if(sensorMsg.Keys.Contains("deviceId")){
> console.log("deviceId ", sensorMsg.Properties["deviceId"]);
> }
> modbusClient.sendEvent(sensorMsg);
> }
> ```
When the message arrives at the IdentityTranslation module, Properties are empty and I cannot get the deviceId value.
## Console log of the issue
This is the content of the received message
> ```
> new message received Message {
> data:
> ,
> properties:
> Properties { propertyList: [ [Object], [Object], [Object] ] },
> messageId: '',
> to: '',
> expiryTimeUtc: undefined,
> lockToken: '',
> correlationId: '',
> userId: '',
> contentEncoding: 'utf-8',
> contentType: 'application/json' }
> ```
## Other references
I found this old issue [Message properties seem to get lost after routing through edgeHub](https://github.com/Azure/azure-iot-sdk-python/issues/244) related to the python sdk that has been fixed. Maybe is there a similar problem on nodejs (or .Net)?
Contributor guide
Research direction
Start at the Node.js moduleClient.on('inputMessage') handler and the Message properties shown in the console output; compare how the C# SendEventAsync message is serialized and how routed input properties are exposed. Reproduce the route with deviceId and verify whether the property is available in the received message, establishing whether the issue belongs in the Node.js SDK or upstream Edge routing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, csharp, node.js
- Domain
- distributed-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100