Comments (5)
I managed to reproduce the issue, it's about the routing_key. I have 1 producer using two cony clients to send data in the same queue and exchange but with a different routing key. On the other side I have 2 separate subscribers receiving the messages each with a different routing_key but same queue and exchange.
When only one client is connected he gets all the messages from routing_key 1 and 2. When both are connected, sometimes it works, each one receives its routed messages, but sometimes one receives the messages of the other one.
When I use the rabbit management interface, the queue is fine with all the messages with two different routing_key. I have to check my subscriber code but at first sight it looks fine.
Stay tuned...
from cony.
Here's the consumer source code running in a dedicated go routine and pushing messages to a channel.
`logger.WithField("config", config).Debug("preparing new consummer")
// construct new client with the flag url
// and default backoff policy
cli := cony.NewClient(
cony.URL(config.URL),
cony.Backoff(DefaultBackoff),
)
// declarations
// the queue name will be supplied by the AMQP server
que := &cony.Queue{
Name: config.Queue,
Durable: config.Durable,
AutoDelete: config.AutoDelete,
Exclusive: config.Exclusive,
}
exc := cony.Exchange{
Name: config.Exchange,
Kind: config.ExchangeType,
AutoDelete: config.AutoDelete,
Durable: config.Durable,
}
bnd := cony.Binding{
Queue: que,
Exchange: exc,
Key: config.RoutingKey,
}
cli.Declare([]cony.Declaration{
cony.DeclareQueue(que),
cony.DeclareExchange(exc),
cony.DeclareBinding(bnd),
})
// prepare consumerOpt from config
options := make([]cony.ConsumerOpt, 0)
if config.AutoAck {
options = append(options, cony.AutoAck())
}
if config.Exclusive {
options = append(options, cony.Exclusive())
}
if config.NoLocal {
options = append(options, cony.NoLocal())
}
// declare and register a consumer
cns := cony.NewConsumer(
que,
options...,
)
cli.Consume(cns)
logger.Debug("starting client loop to receive messages")
for cli.Loop() {
select {
case msg := <-cns.Deliveries():
logger.WithField("delivery", msg).Debug("received message")
config.Messages <- msg.Body
// if needed auto ack messages
if !config.AutoAck {
err := msg.Ack(false)
if err != nil {
logger.WithField("msg", msg).WithField("error", err).Debug("fail to send ack on message")
}
}
case err := <-cns.Errors():
logger.WithField("error", err).Warn("consummer error")
case err := <-cli.Errors():
logger.WithField("error", err).Warn("client error")
}
}
logger.Debug("exiting subscriber connection loop")`
from cony.
@sebastienfr It seems that there is some misconception about how RabbitMQ works.
Consumers don't care about routing keys, routing keys only used during publishing, when new message arrives to exchange, exchange decide in which queue this message will go (based on routing key). Consuming single queue with 2 consumers means round-robin pattern of message distribution between consumers.
from cony.
Hello,
Thank you for your reply, looks like I misunderstood the rmq tutorial, because in the binding the consumer side is using the routing key, else why would it be needed ? I'll check again the docs https://www.rabbitmq.com/tutorials/tutorial-four-go.html.
Thanks for your answer
from cony.
Hi,
I was working on existing code, as you suggested it was effectively wrong about the single queue and the key, it's fine now, I'm using 2 queues as you suggested it. It's quite amazing this was working 99% of the time. Thanks for your help.
from cony.
Related Issues (18)
- Make cony thread-safe
- Blocked publisher does not forward unblock message
- Support of headers in queue and exchange
- Subscriber keeps connection to CLOSE_WAIT HOT 1
- Using blank queue name results in error on reconnection HOT 2
- I wan't user the publisher send topic message, but there have many routing key HOT 2
- Exception (501) Reason i/o timeout HOT 1
- Add declare passive for a queue and an exchange
- Handling prefetched messages upon lost connection? HOT 3
- Consumer send on closed channel after Cancel HOT 3
- this project is still active?
- Why don't pass queue.Args when consume queue
- Repalce streadway/amqp with officially maintained package
- Client won't reconnect after second amqp.Dial timeout HOT 5
- Design question HOT 3
- Reconnection error Exception (501) Reason: "EOF" HOT 2
- Support of amqp.Blocking
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cony.