Created
July 31, 2019 11:42
-
-
Save sasaken555/847e0a7190bd3db462fd457f212a75d8 to your computer and use it in GitHub Desktop.
Pub/Sub messaging with NATS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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