As per my understading, this variables can not be used in topic names. To receive data from cloud, I have to define mqtt topic? Using mix of static and dynamic variables in topic name is not possible in Nodered
It is not possible in MQTT. A topic must be subscribed to in the remote broker.
But you can:
use wild card topics
environment variables
these env vars can be system defined or group/tab/subflow/global node-red defined env vars
subscribe dynamically (where the topic can be generated in a function node or change node from constants/env vars/values from wherever you please.
The point is the subscription cannot change reactively because it has to be registered to a broker external to node-red. Having a variable topic makes little sense.
Kinda. But the point I was attempting to clarify was it cannot be some variable in the topic specifically - there is an overall unsubscribe/subscribe procedure (and a whole bunch of goings on in the client and node-red) meaning that a topic cannot be some automagically changing variable (probably still not clear)
I can not use function in case where I am subscribing to the data, yes it can be used when I am publishing the data.
Consider a topic
hub/R/{edgeId}/{noderedId}/{flowId}
Instead of hardcoding and define at multiple places, I want to define this variables at one place, and use it everywhere in flow. Is it possible to do so?
You could setup all your constants as env vars (in one tab or group or globally or system defined if desired) or use dynamic subscriptions. You could compute all your topics etc in a function node and store them in context too.
As I said before
NOTE: To clarify.
Each group, tab, subflow and global node-red settings can have env vars defined. Anywhere there is a text input (like topic) you can enter ${myEnvVar}
Maybe do your subscriptions once, output to a link node and you can then consume the data wherever you want? You can use the dynamic subscription mode and use an inject or some other node to deliver the subscriptions.