Created
June 30, 2020 14:15
-
-
Save aricart/a575e518d85d4d78a9062d50281c3840 to your computer and use it in GitHub Desktop.
Revisions
-
aricart created this gist
Jun 30, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ listen: "localhost:4222" cluster: { listen: "localhost:4333" } streaming: { store: "file" dir: "/tmp/stan-cluster/data" ft_group: "ft" } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ 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 hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ 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}`) })