I need to publish a message to a MQTT topic which my device has subscribed to from an application using the Event Grid MQTT Broker. Is this even possible or should I create a special MQTT client for publishing?
I couldn't find any documentation for cloud to device communication. I tried to create an EventGrid Topic for publishing but I did't manage to route the message to the EventGrid MQTT Broker so my device could receive it.
Yes, it is possible to send a cloud-to-device message using the Event Grid MQTT Broker, but it requires proper configuration of MQTT topics and permissions. Here's a general approach:
Ensure your Event Grid namespace has the MQTT broker feature enabled.
Create topic spaces for cloud-to-device communication. For example:
devices/{deviceId}/desired
for publishing messages to specific devices.devices/{deviceId}/reported
for receiving responses from devices.Define permission bindings to allow your cloud application to publish messages to the desired
topic and subscribe to the reported
topic.
Ensure devices have permissions to subscribe to the desired
topic and publish to the reported
topic.
Use an MQTT client in your application to publish messages to the desired
topic. The device subscribed to this topic will receive the message.
You can find detailed guidance on implementing MQTT request-response messaging patterns with Event Grid here. This includes examples of topic configuration and permission bindings.
Refer this doc for Publishing and subscribing to MQTT messages on Event Grid Namespace