Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

359
Visualizações
How to customize the Split node in Node-Red in a way not to send all msgs at once?

I am trying to customize the Split node in Node-Red in a way to send the next message only when the first arrives to the Join node; as I am doing some processing in between, and would like to process each msg separately before joining them.

So I have cloned the Split node from Node-Red project, and at the part where the splitting of an array happens; I register listeners to events (random IDs generated by the original Split node).

else if (Array.isArray(msg.payload)) { // then split array into messages
     msg.parts.type = 'array';
     var count = msg.payload.length / node.arraySplt;
     if (Math.floor(count) !== count) {
         count = Math.ceil(count);
     }
     msg.parts.count = count;
     var pos = 0;
     var data = msg.payload;
     msg.parts.len = node.arraySplt;
     for (let i = 0; i < count; i++) {
         msg.payload = data.slice(pos, pos + node.arraySplt);
         if (node.arraySplt === 1) {
             msg.payload = msg.payload[0];
         }
         msg.parts.index = i;
         pos += node.arraySplt;
         if (i === 0) {
             send(RED.util.cloneMessage(msg));
             continue;
         }
         let eventName = msg.parts.id + '-' + i;
         addHandler(eventName, send, msg);
     }
     done();
} 

My handler function

function addHandler(eventName, send, msg) {
  RED.events.addListener(eventName, () => {
    send(RED.util.cloneMessage(msg));
  });
}

And at the Join node (which is in the same js file)

// commented below is the original code of the join function
// if ((tcnt > 0 && group.currentCount > tcnt) || msg.hasOwnProperty('complete')) {
//     completeSend(partId);
//     return;
// } else
if (msg.parts.index <= (msg.parts.count - 2)) {
    let eventName = msg.parts.id + '-' + (parseInt(msg.parts.index) + 1);
    RED.events.emit(eventName);
} else if (msg.parts.index >= (msg.parts.count - 1)) {
    completeSend(partId);
    return;
}

However, this would send the first msg (as I directly send it, and not through an event), and the last msg only; it would skip whatever in between.

Node-Red debug screen shows undefined for 2nd and 3rd msgs

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Modifying the split node is the wrong way to do this.

There are rate limiting nodes that will do this for you. e.g. https://flows.nodered.org/node/node-red-contrib-semaphore

Or you can use the delay node with it's release function

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda