My publisher (zpub.js
) publishes in a loop as shown below.
async function publishLoop() {
let payload = []
_.forEach(array, (a) => {
// process a here to generate someKey and someValue
payload.push({someKey:someValue})
})
return Promise.all(payload.map(async (p) => {
await zmqp.publish({t:'topicString', m:p})
}))
}
zmqp.publish
is simply the following.
async publish(payload) {
// this.sock is just a bind to tcp://127.0.0.1:4030
await this.sock.send([payload.t, JSON.stringify(payload.m, null, null)])
return Promise.resolve()
}
My subscriber (zsub.js
) is a version of code as seen on the ZeroMQ website.
const zmq = require("zeromq")
const mom = require('moment-timezone')
async function run() {
const sock = new zmq.Subscriber
sock.connect("tcp://127.0.0.1:4030")
sock.subscribe("topicString")
for await (const [topic, msg] of sock) {
console.log(`${mom().tz('Asia/Kolkata').format('YYYY-MM-DDTHH:mm:ss.SSS')}`)
}
}
run()
- I start my subscriber as
node zsub.js > out
. - I launch my publisher as
node zpub.js
. All messages received successfully. - The
zpub.js
process ends butzsub.js
keeps running. When I re-runnode zpub.js
, not a single message is received by the subscriber. The number of records inout
remains unchanged. - Running
zpub.js
once or twice again seems to deliver messages (the recent ones; not the earlier ones as seen by timestamp) to subscriber.
Thus, I am not sure, what is to be done on the pub/sub side so that messages aren't 'lost'. Please advise.
node zpub.js
with 20 seconds gap and messages are getting dropped. – cogitoergosum