Skip to content

nsqd: defer is not working as expected #1433

@cychub

Description

@cychub

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)
});

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions