nsq
nsq copied to clipboard
nsqd: defer is not working as expected
Based on the document, we only need pass defer parameter in ms to achieve message delay delivery. https://nsq.io/components/nsqd.html#post-pub
- consumer
const nsq = require('nsqjs')
const moment = require('moment')
// reader
const reader = new nsq.Reader('sample_topic', 'sample_topic', {
lookupdHTTPAddresses: 'nsqlookupd:4161'
})
reader.connect()
reader.on('message', msg => {
console.log('Received message [%s] [%s]: %s', moment.utc().format('YYYY-MM-DD HH:mm:ss:SSS'), msg.id, msg.body.toString())
setTimeout(() => {
msg.finish()
}, 1000)
});
- producer, just call the API with postman http://localhost:4151/pub?defer=5000&topic=sample_topic
pre-request part, will generate the current time in ms.
var moment = require('moment');
var date = moment.utc().format('YYYY-MM-DD HH:mm:ss:SSS');
pm.environment.set("now", date);
in the request
{
"text": "some message",
"message ": [{{now}}]
}
- output
nsq-demo-client-1 | Received message [2022-12-13 14:37:15:684] [11bc612bb5c88000]: {
nsq-demo-client-1 | "text": "some message",
nsq-demo-client-1 | "message ": [2022-12-13 14:37:12:336]
nsq-demo-client-1 | }
expect
the Received message should be 5 seconds later comparing with the timestamp in the message body.
actual
the Received message is always within the defer ms.
Going to need the nsqd
logs with --log-level=debug
enabled to debug.