-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handling prefetched messages upon lost connection? #26
Comments
@jraede hello and thank you for kind words! It's not that simple how it works, although the problem with prefetch still can strike. Each Frankly, I don't know how to "fix" this. If you have ideas — please post them. |
Assuming I'm correct and RabbitMQ will redeliver those messages to another channel (even the same consumer on the new reconnected channel), could we just remake the func (c *Consumer) serve(client mqDeleter, ch mqChannel) {
if c.reportErr(ch.Qos(c.qos, 0, false)) {
return
}
// If prefetch > 1, c.deliveries might have messages in it
// that are associated with a closed RabbitMQ channel (if e.g.
// there was a reconnection event). Rabbit will already deliver
// those messages to a new channel so we need to remove
// references to them here.
c.deliveries = make(chan amqp.Delivery)
deliveries, err2 := ch.Consume(c.q.Name,
c.tag, // consumer tag
c.autoAck, // autoAck,
c.exclusive, // exclusive,
c.noLocal, // noLocal,
false, // noWait,
nil, // args Table
)
if c.reportErr(err2) {
return
}
for {
select {
case <-c.stop:
client.deleteConsumer(c)
ch.Close()
return
case d, ok := <-deliveries: // deliveries will be closed once channel is closed (disconnected from network)
if !ok {
return
}
c.deliveries <- d
}
}
} |
Assuming that user's code uses it like in basic example:
meaning that user calls
Code like this will break.
|
Awesome package, this helps us a lot. Just one question that's come up while testing various edge cases:
If prefetch is set to > 1, then you could conceivably have the following scenario:
amqp.Message
s in thedeliveries
channel reference a channel that is now CLOSED.How would you suggest handling this case? If we remake the deliveries channel would that imply a NACK on the rabbit server?
The text was updated successfully, but these errors were encountered: