Created
June 30, 2020 14:15
-
-
Save aricart/a575e518d85d4d78a9062d50281c3840 to your computer and use it in GitHub Desktop.
sample nats-streaming-cluster
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
listen: "localhost:4222" | |
cluster: { | |
listen: "localhost:4333" | |
} | |
streaming: { | |
store: "file" | |
dir: "/tmp/stan-cluster/data" | |
ft_group: "ft" | |
} |
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
listen: "localhost:2224" | |
cluster: { | |
listen: "localhost:3334" | |
routes: ["nats://localhost:4333"] | |
} | |
streaming: { | |
store: "file" | |
dir: "/tmp/stan-cluster/data" | |
ft_group: "ft" | |
} |
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 STAN = require('node-nats-streaming') | |
let interval; | |
const sc = STAN.connect("test-cluster", "me") | |
sc.on('error', (err) => { | |
console.error(err); | |
}) | |
sc.on('connection_lost', () => { | |
console.log('stan connection was lost!') | |
}) | |
sc.on('close', () => { | |
clearInterval(interval) | |
console.log('closed') | |
}) | |
sc.on('connect', () => { | |
console.log(`connected to ${sc.nc.currentServer.url}`) | |
const sub = sc.subscribe("test") | |
sub.on('message', (msg) => { | |
console.log(`[${msg.getSequence()}]: ${msg.getData()}`) | |
}) | |
let count = 0; | |
interval = setInterval(()=>{ | |
sc.publish('test', `${++count}`) | |
}, 1000) | |
}) | |
sc.on('disconnect', () => { | |
console.log('disconnected') | |
}) | |
sc.on('reconnect', () => { | |
console.log(`reconnected to ${sc.nc.currentServer.url}`) | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment