nsqio / go-nsq

The official Go package for NSQ
MIT License
2.59k stars 444 forks source link

nsq on client side (consumer) #306

Closed fuzsh closed 4 years ago

fuzsh commented 4 years ago

I created a route for http request that handles all incoming requests then i push them on queue by producer.Publish() method, then return status code 200 to user. on the other side (consumer) what is the best approach to handle ? waitGroup with large number like wg.Add(100000) or infinite loop ? or .. ?

can you help me with example ...?

refer to ex:

// Gracefully stop the consumer.
consumer.Stop()

it close and i want to run always ....

ploxiln commented 4 years ago

It depends on what you want the consumer to do. Here's a minimal simple consumer example to look at:

https://github.com/nsqio/nsq/blob/master/apps/nsq_tail/nsq_tail.go

That registers a handler function which is called for each message, and then waits for a signal to exit.

If you want these messages to be served to http clients, that is awkward, but possible ...

fuzsh commented 4 years ago

@ploxiln special thanks, i want my consumers to update db (arango db cluster) ...

ploxiln commented 4 years ago

OK, that's the simple standard case. Just do the db update in the handler function.