# Mqtt-in variable broker

**URL:** <https://discourse.nodered.org/t/mqtt-in-variable-broker/88406>\
**Category:** General\
**Created:** [31 May 2024 09:52 UTC](https://discourse.nodered.org/t/mqtt-in-variable-broker/88406 "2024-05-31T09:52:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![HenryTrang](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/henrytrang/32/81582_2.png) [@HenryTrang](https://discourse.nodered.org/u/HenryTrang)\
**Post date:** [31 May 2024 09:52 UTC](https://discourse.nodered.org/t/mqtt-in-variable-broker/88406/1 "2024-05-31T09:52:33Z")

</div>

dear all

for the node mqtt-in how to use variable broker?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [31 May 2024 10:08 UTC](https://discourse.nodered.org/t/mqtt-in-variable-broker/88406/2 "2024-05-31T10:08:42Z")

</div>

You can use dynamic subscriptions to connect to different brokers. It is all in the sidebar help text.  
There are plenty of examples posted on forum to, a quick search for [mqtt bynamic broker connect](https://discourse.nodered.org/search?q=mqtt%20dynamic%20broker%20connect) brings up many.

#### Dynamic Subscription

The node can be configured to dynamically control the MQTT connection and its subscriptions. When enabled, the node will have an input and can be controlled by passing it messages.

### [Inputs](http://192.168.1.10:1880/#)

These only apply when the node has been configured for dynamic subscriptions.

actionstring  
the name of the action the node should perform. Available actions are: `"connect"`, `"disconnect"`, `"subscribe"` and `"unsubscribe"`.  
topicstring|object|array  
For the `"subscribe"` and `"unsubscribe"` actions, this property provides the topic. It can be set as either:

- a String containing the topic filter
- an Object containing `topic` and `qos` properties
- an array of either strings or objects to handle multiple topics in one

brokerbroker  
For the `"connect"` action, this property can override any of the individual broker configuration settings, including:

- `broker`
- `port`
- `url` - overrides broker/port to provide a complete connection url
- `username`
- `password`

If this property is set and the broker is already connected an error will be logged unless it has the `force` property set - in which case it will disconnect from the broker, apply the new settings and reconnect.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [31 May 2024 11:07 UTC](https://discourse.nodered.org/t/mqtt-in-variable-broker/88406/3 "2024-05-31T11:07:34Z")

</div>

and here is a demo of most features: [Dynamic MQTT LWT birth, Close & Will Property - #2 by Steve-Mcl](https://discourse.nodered.org/t/dynamic-mqtt-lwt-birth-close-will-property/58951/2)

---

<div class="post-metadata">

**Author:** ![HenryTrang](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/henrytrang/32/81582_2.png) [@HenryTrang](https://discourse.nodered.org/u/HenryTrang)\
**Post date:** [4 June 2024 08:00 UTC](https://discourse.nodered.org/t/mqtt-in-variable-broker/88406/4 "2024-06-04T08:00:44Z")

</div>

thank you sir for the answer.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [18 June 2024 08:01 UTC](https://discourse.nodered.org/t/mqtt-in-variable-broker/88406/5 "2024-06-18T08:01:42Z")

</div>

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