gorabbit
gorabbit copied to clipboard
consumer already exists
This method is called when creating a new consumer
Why don't we check the name of the new consumer with the old one? With this approach, you can't create multiple consumers for one queue
func (a *amqpConnection) registerConsumer(consumer MessageConsumer) error {
for _, channel := range a.channels {
// maybe check channel.consumer.Name != consumer.Name
if channel.consumer != nil && channel.consumer.Queue == consumer.Queue {
err := errConsumerAlreadyExists
a.logger.Error(err, "Could not register consumer", logField{Key: "consumer", Value: consumer.Name})
return err
}
}
...
That's a good point, we could even check for both in that case
func (a *amqpConnection) registerConsumer(consumer MessageConsumer) error {
for _, channel := range a.channels {
if channel.consumer != nil && (channel.consumer.Name == consumer.Name || channel.consumer.Queue == consumer.Queue) {
err := errConsumerAlreadyExists
a.logger.Error(err, "Could not register consumer", logField{Key: "consumer", Value: consumer.Name})
return err
}
}
...
if channel.consumer != nil && channel.consumer.Name == consumer.Name && channel.consumer.Queue ==consumer.Queue -> return errConsumerAlreadyExists
It seems that such an expression will be correct only if the name and the queue match, return an error