Closed echupriyanov closed 9 years ago
The problem is, once you interrupt the consumer, the Messages()
channel will be closed eventually. Once this channel is closed, trying to read from it will always immediately return a zero-value. The range
statement handles this, but if you use select
you have to do this yourself.
You can do something like this to detect this:
for {
select {
case message, ok := <-consumer.Messages():
if !ok { // channel is closed
return
}
...
Thanks! What was the issue. I didn't expect select was still trying to read after I hit ^C.
Hello,
I'm trying to write small consumer group application using several workers. Almost everything is working correctly, but when in supplied example (consumergroup.go) I try to change logic from:
to:
When I try to stop worker with ^C, I'm getting nil pointer dereference:
What am I doing wrong?
The full modified source code is: