trying to learn nsq, and following the examples from here golang example and here nsqjs. I am sending messages in server side doing w/ a for loop and go routines
var wg sync.WaitGroup
for i := 0; i < 100; i++ {
wg.Add(1)
go func(x int) {
defer wg.Done()
chanName := fmt.Sprintf("import_progress_587e6442ff74889098498f6e")
m := map[string]interface{}{
"body": map[string]interface{}{
"progress": x,
},
}
msg, _ := json.Marshal(m)
req := NSQPubReq{
Topic: chanName,
Body: msg,
}
if err := producer.Publish(req.Topic, req.Body); err != nil {
}
utils.Info(fmt.Sprintf("sent msg=%v", string(msg)))
}(i)
}
wg.Wait()
but the problem is, on the clientside.
// channel = 'import_progress_587e6442ff74889098498f6e'
let reader = new nsq.Reader(channel, channel, {
//lookupdHTTPAddresses: '<<IP>>:4161',
maxInFlight: 10000,
snappy: true
})
reader.connect()
reader.on('message', (msg) => {
var msgData = {
id: msg.id,
body: msg.body.toString(),
chan: channel
}
io.emit(channel, msgData)
msg.finish()
})
the message don't come up immediately to the client. i will wait for a couple of seconds until the message come to the nodejs client. is there any settings that I need to do? thank you!