/** * Send a Gossip request packet to a random endpoint * * @param {Object} data * @param {Array} endpoints */ sendGossipToRandomEndpoint(data, endpoints) { if (endpoints.length == 0) return; const ep = endpoints.length == 1 ? endpoints[0] : endpoints[Math.floor(Math.random() * endpoints.length)]; if (ep) { const packet = new P.Packet(P.PACKET_GOSSIP_REQ, ep.id, data); this.publish(packet).catch(() => { this.logger.debug(`Unable to send Gossip packet to ${ep.id}.`); }); if (this.GOSSIP_DEBUG) this.logger.info(kleur.bgYellow().black(`----- REQUEST ${this.nodeID} -> ${ep.id} -----`), packet.payload); } }
/** * Send a Gossip Hello to the remote node * * @param {String} nodeID */ sendHello(nodeID) { const node = this.getNode(nodeID); if (!node) return this.Promise.reject(new MoleculerServerError(`Missing node info for '${nodeID}'`)); const localNode = this.nodes.localNode; const packet = new P.Packet(P.PACKET_GOSSIP_HELLO, nodeID, { host: this.getNodeAddress(localNode), port: localNode.port, }); if (this.GOSSIP_DEBUG) this.logger.info(kleur.bgCyan().black(`----- HELLO ${this.nodeID} -> ${nodeID} -----`), packet.payload); return this.publish(packet).catch(() => { this.logger.debug(`Unable to send Gossip HELLO packet to ${nodeID}.`); }); }
this.publish(rspPacket).catch(() => {}); if (this.GOSSIP_DEBUG) this.logger.info(kleur.bgMagenta().black(`----- RESPONSE ${this.nodeID} -> ${sender.id} -----`), rspPacket.payload); } else { if (this.GOSSIP_DEBUG) this.logger.info(kleur.bgBlue().white(`----- EMPTY RESPONSE ${this.nodeID} -> ${payload.sender} -----`));
diffRemove(val) { return bgRed().black(val); }
successBadge(message) { return bgGreen().black().bold(message); }
diffAdd(val) { return bgGreen().black(val); }
failureBadge(message) { return bgRed().black().bold(message); }
skipBadge(m) { return bgYellow().black().bold(m); }