nats test

This commit is contained in:
Pritimay Sarkar
2024-02-19 12:17:06 +05:30
parent 0ed5e0725b
commit 8e659d8fed

21
nats.js
View File

@@ -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}`);