Is it possible to configure a single Inject node to connect and subscribe to an MQTT broker using Dynamic Connections?

I am getting to grips with the concept of Dynamic MQTT connections and related Pub/Sub. However I am curious as to whether it would be possible to use the same Inject Node to do the following:

  1. Force connect to an MQTT broker
  2. Subscribe to a desired topic

I tried doing the following within an inject node:

  • msg.action set to connect
  • set to {"broker": "internal-mqtt-broker", "port":1883, "force":true}
  • msg.action set to subscribe
  • msg.topic set to $SYS/#

Upon deploying the flow, the inject node is not able to connect to the Broker.

node-red              | 20 Apr 19:55:55 - [info] Server now running at
node-red              | 20 Apr 19:55:55 - [info] Starting flows
node-red              | 20 Apr 19:55:55 - [info] Started flows
node-red              | 20 Apr 20:00:47 - [info] Stopping flows
node-red              | 20 Apr 20:00:47 - [info] Stopped flows
node-red              | 20 Apr 20:00:47 - [info] Starting flows
node-red              | 20 Apr 20:00:47 - [info] Started flows

Flow Diagram:

Inject Node Properties

Whereas upon removing the subscribe action and topic from the Inject node, I am able to connect to the broker and subscribe to a topic via a separate node.

Would there be some way to merge the connection + subscription actions of the node into one node?

Kind of - use a delay to cause 2 messages, the 1st one to connect, the 2nd to subscribe


Why your example doesnt work...

... This is easily visible by adding a debug node AFTER the inject (debug node set to "show complete message")

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.