nsqio / go-nsq

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

Exposing the delegates #213

Closed Chillance closed 7 years ago

Chillance commented 7 years ago

Hi,

I noticed that the Producer doesn't expose any of the callbacks. In my case I would like a way to know how many consumers have received a message, and was thinking that maybe something like knowing when Finished is called could help with that. However, it's not exposed. Producer is basically "send and forget". Now, I could of course use a new and specific topic and channels to communicate this, but it seems to me that there already are things in place in the connection already established that could be used for this.

So, what it boils down to is, how do I let the Producer know that a certain amount of consumers has received the message? I know before hand that I have X amount of consumers for a specific message, but I currently don't see an easy way to communicate back how many of them received the message, so the producer can resend the message in case that is needed because it was consumed by other consumers already and a new consumer was late to subscribe for example.

Also, consumers don't know about each other so they can't requeue the message.

Thanks!

ploxiln commented 7 years ago

Any "requeue" that is needed should be handled by nsqd, not by your producer. If anything knows what channels should exist when a message is published by a producer, it should make sure that channel exists in nsqd before the message is published. Then nsqd will ensure delivery and acknowledgement for that message on all channels.

Chillance commented 7 years ago

Aha, so as long as the Consumers connects to a topic and channel before Producer send, all channels will get the message. Yes, seems to be working fine. But isn't the re-queuing done by the Consumer as well though?

ploxiln commented 7 years ago

nsqd keeps track of the message timeout. If the consumer does not finish or requeue the message within the timeout (default is 60 seconds, can be configured and extended) then nsqd will requeue it.