From 8e659d8fed785ee7147d7f87062066958e9432a7 Mon Sep 17 00:00:00 2001 From: Pritimay Sarkar Date: Mon, 19 Feb 2024 12:17:06 +0530 Subject: [PATCH] nats test --- nats.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/nats.js b/nats.js index 7b32907..3da4756 100644 --- a/nats.js +++ b/nats.js @@ -37,7 +37,7 @@ const NATS = require('nats'); const sc = NATS.StringCodec(); const seed = new TextEncoder().encode( - "SUADA3R4HRQG5ZEGR7E65P5P2JUQ2LMVLEOGJWEIKLEYOZEPQES2WHW2KU", + "SUACFBL4SJNFOYVB6F4AHK7A7VCHDENCKVLKJTTKAH3I47BOTSOE3Z2K7M", ); const servers = [ { @@ -57,15 +57,16 @@ servers.forEach(async (v) => { const nc = await NATS.connect(v); // Subscribe to a subject - const subscription = await nc.subscribe("server.hpos.HCV-000-3001.ping"); - - // // Handler for incoming messages - // subscription.on('message', (msg) => { - // console.log(`Received message: ${sc.decode(msg.data)}`); - // }); - //console.log(subscription.); - - // nc.publish("server.hpos.HPP1-000-2001.ping", "ALIVE"); + const subscription = await nc.subscribe("server.hpos.HCV-000-3998.ping"); +/* + (async () => { + for await (const msg of subscription) { + console.log(`Received message: ${sc.decode(msg.data)}`); + // Your custom logic for handling the incoming message goes here + } + })(); +*/ + nc.publish("server.hpos.HCV-000-3998.ping", "ALIVE"); } catch (err) { console.log(`error connecting to ${JSON.stringify(v)} ${err}`);