Im trying to get rabbit to send round robin messages to different topics. I have 1 queue called "endpoint/1" I am dispatching messages to "endpoint/1" and "endpoint/2". "endpoint/2" does not exists so i expected those messages to disappear but instead they get sent to the queue "endpoint/1" event though there is no binding to it!
I have no idea why this is happening, am i doing something wrong?
// declare exchange
ch.ExchangeDeclare("uop_fanout", "fanout", false, false, false, false, nil)
//send
ch.Publish("uop_fanout", topic, false, false, amqp.Publishing{Body: msg})
// listend
q, err := ch.QueueDeclare(topic, false, false, false, false, nil)
if err != nil {
return nil, err
}
err = ch.QueueBind(q.Name, topic, "uop_fanout", false, nil)
if err != nil {
return nil, err
}
messagesFanout, err := ch.Consume(q.Name, "", false, false, false, false, nil)
if err != nil {
return nil, err
}
With this statement:
ch.ExchangeDeclare("uop_fanout", "fanout", false, false, false, false, nil)
you are declaring an exchange of type fanout
. This means messages arriving at the exchange get cloned and sent to all the queues bound to that exchange.
It's not clear what you mean by "round robin messages to different topics".
If you want to do just round-robin load balancing, you can simply route your messages to a single queue, and have two or more consumers for that queue.
If you want to distribute messages by topic, you can use a direct
exchange, with specific routing keys. An arriving message will be sent to the queue bound with the matching routing key.
Of course, you can combine those concepts.
Source: https://www.rabbitmq.com/tutorials/amqp-concepts.html