Hi there,
I am currently struggling with the merging of two payload messages.
I perform two http requests and receive a payload message back from both. Now I want to merge these two payloads using an identical value in both payloads.
Below are the two payloads marked with the identical value.
You may need to elaborate on what you want as a result.
Thoughts: context may help.
You receive the first payload and store it in context. Then when the second payload arrives code checks the existing and new payloads and if they meet your needs, the new message is created.
But what the new message's structure is wasn't defined so I can't help you there.
EDIT:
The above method relies on the input messages to be merged having DIFFERENT topic-names.
It is unclear what the topic-name is for your two sets of incoming data and whether a unique topic-name could be applied (at the source where the data is created).
You are receiving messages and you want to merge them if..... conditions are right.
So does that mean 2 consecutive messages need to have their things meeting the requirements?
Basically - in my example - you are caching a message.
You receive a message, and store it in context.
If the next message meets things, then something needs to happen to merge the two.
If not: dump the first cache, and cache the newer message.
Repeat.
You will need to get that structure understood as a bse line.
Something like:
let counter = context.get("counter") || 0
// if counter == 0 this is the first message
if (counter == 0)
{
context.set("m1",msg.payload); // store this value
context.set("counter",1)
return; // exit. No further action needed
}
// now do stuff here to check the existing m1 and the new payload received.
// If they do NOT meet the requirement.
{
context.set("m1",msg.payload); //store the value
context.set("counter",0)
return
}
// If they do match do stuff to combine the two messages.
// That is beyond me for what you want to use from both messages.
Ok, first of all thanks again for your answers. I will just try to explain the current incoming data for better understanding what the result should look like:
Currently I have two https requests from which I get multiple responses. The first request is generating the following messages (and much more):
These are measurements from the sensors.
Now I have for each sensor two datasets that I want to merge by the property "st_name" because this value is included in both messages from the requests.
Problem is that I have to push a requests to two different endpoints because there is no single endpoint which could give me all the data at once.
Please let me know if it is better understandable now otherwise I will try to share more details.
Thanks
Give unique topics to the two sets of data and feed them into a Join node configured as in the example below, then you will get a single message containing both sets of data so you can build the merged data.