Skip to content

Instantly share code, notes, and snippets.

@sasaken555
Created July 31, 2019 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sasaken555/847e0a7190bd3db462fd457f212a75d8 to your computer and use it in GitHub Desktop.
Save sasaken555/847e0a7190bd3db462fd457f212a75d8 to your computer and use it in GitHub Desktop.
Pub/Sub messaging with NATS
const NATS = require("nats");
const nc = new NATS({ url: "nats://localhost:4222", json: true });
nc.on("connect", c => console.log("connected!"));
nc.on("error", err => console.log(err.message));
// time.* というSubjectを購読
nc.subscribe("time.*", msg => {
console.log(msg);
nc.close();
});
// time.jp というSubjectに配信
nc.publishe("time.jp", { "publishedAt": new Date().toISOString() });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment