# Mad idea - link call type MQTT mechanism

**URL:** https://discourse.nodered.org/t/mad-idea-link-call-type-mqtt-mechanism/53829
**Category:** General
**Created:** [16 November 2021 13:10 UTC](https://discourse.nodered.org/t/mad-idea-link-call-type-mqtt-mechanism/53829 "2021-11-16T13:10:42Z")
**Posts on this page:** 18
**Page:** 1

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [16 November 2021 13:10 UTC](https://discourse.nodered.org/t/mad-idea-link-call-type-mqtt-mechanism/53829/1 "2021-11-16T13:10:42Z")

</div>

Just while working on something and repeating something from another instance a (probably) daft thought struck me

As well as the link call return thingy, why not do the same across instances (using MQTT??)

e.g You want the RGB value of a colour  
So you send it out of your flow (MQTT??)

In another NR instance, you receive the message - convert it - send it back to originating flow

Is this mad?  
Already been done?  
Dead simple?  
Go away?

I'm thinking of this as local cloud computation 🙂  
Write something once on one machine but make it accessible to all your other flows

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [16 November 2021 14:15 UTC](https://discourse.nodered.org/t/mad-idea-link-call-type-mqtt-mechanism/53829/2 "2021-11-16T14:15:09Z")

</div>

It would be a useful but niche shortcut for sure. I don't think many people would be using multiple instances in this way?

And of course, is _is_ "just" a shortcut since it doesn't take a lot more to do this with existing nodes - and not just using MQTT but also Websockets, HTTP, TCP, UDP and even Unix sockets.

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [16 November 2021 14:40 UTC](https://discourse.nodered.org/t/mad-idea-link-call-type-mqtt-mechanism/53829/3 "2021-11-16T14:40:56Z")

</div>

The idea popped into my head while using MQTT to transfer global context variables from one instance to another

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [16 November 2021 15:04 UTC](https://discourse.nodered.org/t/mad-idea-link-call-type-mqtt-mechanism/53829/4 "2021-11-16T15:04:54Z")

</div>

Well, it is a fairly standard API approach. MQTT not really fully suited because of its lightweight nature. Full fat Message Queue services have response capabilities built in. I would say that a direct TCP connection would possibly be better.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [16 November 2021 15:06 UTC](https://discourse.nodered.org/t/mad-idea-link-call-type-mqtt-mechanism/53829/5 "2021-11-16T15:06:52Z")

</div>

> [@cymplecy](#):
>
> using MQTT to transfer global context variables from one instance to another

If you got rid of the globals and use Retained MQTT topics instead then they would automatically be available anywhere.

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [16 November 2021 15:22 UTC](https://discourse.nodered.org/t/mad-idea-link-call-type-mqtt-mechanism/53829/6 "2021-11-16T15:22:29Z")

</div>

I'm needing them to be global as I want to access their values in the middle of flows

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [16 November 2021 15:46 UTC](https://discourse.nodered.org/t/mad-idea-link-call-type-mqtt-mechanism/53829/7 "2021-11-16T15:46:22Z")

</div>

There is always the Join node.

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [16 November 2021 16:03 UTC](https://discourse.nodered.org/t/mad-idea-link-call-type-mqtt-mechanism/53829/8 "2021-11-16T16:03:44Z")

</div>

How would that work?

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [16 November 2021 16:08 UTC](https://discourse.nodered.org/t/mad-idea-link-call-type-mqtt-mechanism/53829/9 "2021-11-16T16:08:08Z")

</div>

You can feed the mqtt node and whatever else you need to use it with into a Join node, so both are available.  
Can you give an example of where you can't easily see how to use MQTT?

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [16 November 2021 16:12 UTC](https://discourse.nodered.org/t/mad-idea-link-call-type-mqtt-mechanism/53829/10 "2021-11-16T16:12:05Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/1/b16a25a60729692de01678ea1cd50881f8ecabb3.png)

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [16 November 2021 16:31 UTC](https://discourse.nodered.org/t/mad-idea-link-call-type-mqtt-mechanism/53829/11 "2021-11-16T16:31:40Z")

</div>

It is solvable, of course, but what is the real world use of that, where the mqtt value is required in more that one device?

---

<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: [17 November 2021 00:42 UTC](https://discourse.nodered.org/t/mad-idea-link-call-type-mqtt-mechanism/53829/12 "2021-11-17T00:42:59Z")

</div>

> [@TotallyInformation](#):
>
> MQTT not really fully suited because of its lightweight nature. Full fat Message Queue services have response capabilities built in.

MQTT v5 has a concept of `returnTopic` for this exact requirement.

@cymplecy if I get time tomorrow, I'll post a demo for you.

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [17 November 2021 07:32 UTC](https://discourse.nodered.org/t/mad-idea-link-call-type-mqtt-mechanism/53829/13 "2021-11-17T07:32:22Z")

</div>

Well the one I'm working on now wants to access the last 6 cheerlight colours  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/f/ffe9904390f7014d881ba5e7b9e9b1a419adcb16.png)

These are available as a global variable on another instance, so instead re-generating it in this flow, I decided to send it to my local broker on a topic called nr/globals/lastSixColours and then my 1st flow in this instance just converts all messages to that topic to globals

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/3/43dcc53b8ad8715615a3f840281f89edebb2c7f9.png)

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [17 November 2021 09:22 UTC](https://discourse.nodered.org/t/mad-idea-link-call-type-mqtt-mechanism/53829/14 "2021-11-17T09:22:46Z")

</div>

To eliminate the global variable, using that MQTT topic instead, I would feed the MQTT value and the payload to be checked into a Join node and change the Switch to test the property `msg.payload.["nr/globals/lastSixColours"]` Contains `msg.payload.colour_topic` where `colour_topic` is the topic of the message containing the current colour.

Do you also need to pass colours back to the original system to be added to the list?

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [17 November 2021 09:44 UTC](https://discourse.nodered.org/t/mad-idea-link-call-type-mqtt-mechanism/53829/15 "2021-11-17T09:44:57Z")

</div>

Well ,all things can be done in different ways 🙂  
I.m going to stick to my current method for now.

> [@Colin](#):
>
> Do you also need to pass colours back to the original system to be added to the list?

No - the other instance has the code/flows to maintain last 6 list.

My whole concept here is a write once - use everywhere approach

One downside is one instance relying on another instance but this isn't a nuclear reactor controller 🙂

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [17 November 2021 10:34 UTC](https://discourse.nodered.org/t/mad-idea-link-call-type-mqtt-mechanism/53829/16 "2021-11-17T10:34:55Z")

</div>

> [@cymplecy](#):
>
> Well ,all things can be done in different ways 🙂  
> I.m going to stick to my current method for now.

Certainly, there is rarely a 'best' way in these situations, there are always trade-offs and to a large extent it is down to personal preferences.

> [@cymplecy](#):
>
> My whole concept here is a write once - use everywhere approach

Isn't that almost a definition of MQTT? 🙂

---

<div class="post-metadata">

### Author: ![andysc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andysc/32/21913_2.png) [@andysc](https://discourse.nodered.org/u/andysc)
#### Post date: [6 December 2021 15:18 UTC](https://discourse.nodered.org/t/mad-idea-link-call-type-mqtt-mechanism/53829/17 "2021-12-06T15:18:27Z")

</div>

I wrote a thing a long time ago (before Node-RED ) to do request-response using MQTT.  
As someone pointed out, you publish your data points retained, so they can be retrieved immediately they are requested.  
You connect to a broker, subscribe to the topic, receive the retained message, disconnect.  
Rather like an HTTP request node, but for MQTT.  
I wonder if you could do this with the fancy new "live" MQTT node that came into a recent NR build?

---

<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: [4 February 2022 15:18 UTC](https://discourse.nodered.org/t/mad-idea-link-call-type-mqtt-mechanism/53829/18 "2022-02-04T15:18:29Z")

</div>

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