Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

369
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda