In the new preview version of the IoT Edge gateways one module can invoke methods on another via InvokeDeviceMethodAsync. This takes a device id and a module id as parameters, presumably to tell Edge how to route the call. When calling within the same gateway, the device id parameter should be the device id of the gateway instance in IoT Edge hub. The module id should be the module id of the instance of the module pushed down to the gateway from IoT edge. It is easy to hard code those id's but would obviously not be desirable. You could place the hard coded values in config files that get read by the modules on load which would be less problematic but still not ideal. Is there a way to pro grammatically discover/populate the needed values? Do the deployment json configs support variable substitution or similar upon deployment to populate instance ids?
-
Could this be considered as "configuration" for the module? If yes, then one avenue could be to populate this information in the module's twin when you create the deployment and then as first order of business the module would call `GetTwinAsync` to fetch its twin so it knows where to direct the method calls. Another alternative could be environment variables injected into the container via Docker. – Raj Dec 19 '17 at 03:27
2 Answers
I don't think there is a preferred way currently. You have basically three options, I mention two of them.
- Using
Env
in thecreateOptions
section of the deployment manifest of the module - You can push via Module Twin as property to the module
I personally would choose option 1 as you define the module-id during creation of the deployment manifest and with that you can also inject the environment variable into the specific modules create options in the manifest.
I would choose method 2 in case modules communication will change based on some domain rules, but couldn't find in my projects any use case where this is true.
BTW I would answer as comment, but missing reputation.

- 161
- 1
- 6
The typical scenario for method invocation by modules on IoT Edge device, is that the module receives telemetry messages from other modules on the same device or downstream devices connected to that IoT Edge gateway device, and based on the contents of the message, decides to invoke a method on the sender module or device to indicate some change (for example, say if the message indicates the device is running too hot, then the module can invoke a method to slow down fan speed, etc.).
In such a scenario, the module can get the device Id and module Id of the sender module from the message itself. The message object has the following properties, that provide this information - ConnectionDeviceId ConnectionModuleId

- 76
- 3
-
The scenario I'm trying to solve could be done that way by crafting a request message of sorts but it feels more natural to call a method on the receiver. For instance if I have 10 modules that need information from a database anytime a device connects, to me it makes sense to create a DB module that defines the needed query methods needed. Then each module needed some bit of information calls GetInformation on the DB module. In my scenario I think device id is the same between modules as it points to the gateway id, but I would still need the target module's instance id – Tim Dec 19 '17 at 02:26