Skip to content

Instantly share code, notes, and snippets.

@aricart
Created June 30, 2020 14:15
Show Gist options
  • Save aricart/a575e518d85d4d78a9062d50281c3840 to your computer and use it in GitHub Desktop.
Save aricart/a575e518d85d4d78a9062d50281c3840 to your computer and use it in GitHub Desktop.
sample nats-streaming-cluster
listen: "localhost:4222"
cluster: {
listen: "localhost:4333"
}
streaming: {
store: "file"
dir: "/tmp/stan-cluster/data"
ft_group: "ft"
}
listen: "localhost:2224"
cluster: {
listen: "localhost:3334"
routes: ["nats://localhost:4333"]
}
streaming: {
store: "file"
dir: "/tmp/stan-cluster/data"
ft_group: "ft"
}
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