If I run the following code, the callback (test) passed to the consumer is never triggered.
However, if I keep an eye on the rabbitmq GUI, I do see that the message is retrieved (but not acknowledged). So it seems the consumer is getting the message, but not passing it on to my callback. If I set no_ack to true, the message just disappears from the queue, again without calling the callback.
hn = "..."
usr = "..."
pwd = "..."
vh = "/"
port = 5672
rkey = "some.routing.key"
qname = "some-queue-name"
exchangeName = "MyExchange"
connection = BrokerConnection(hostname=hn,
userid=usr,
password=pwd,
virtual_host=vh,
port=port)
connection.connect()
ch = connection.channel()
# Create & the exchange
exchange = Exchange(name=exchangeName,
type="topic",
channel=ch,
durable=True)
exchange.declare()
# Temporary channel
ch = connection.channel()
# Create the queue to feed from
balq = Queue(name=qname,
exchange=exchange,
durable=True,
auto_delete=False,
channel=ch,
routing_key=rkey)
# Declare it on the server
balq.declare();
def test(b,m):
print '** Message Arrived **'
# Create a consumer
consumer = Consumer(channel=connection.channel(),
queues=balq,
auto_declare=False,
callbacks = [test]
)
# register it on the server
consumer.consume(no_ack=False);
print 'Waiting for messages'
while(True):
pass
However, the following code does work properly (I can successfully get and acknowledge the message):
m = balq.get(no_ack=False)
m.ack()
print m
But the whole point was to stay asynchronous. So something must be wrong with my callback..
Message Ordering The RabbitMQ documentation states the following regarding its ordering guarantees: Messages published in one channel, passing through one exchange and one queue and one outgoing channel will be received in the same order that they were sent.
`Kombu` is a messaging library for Python. The aim of `Kombu` is to make messaging in Python as easy as possible by. providing an idiomatic high-level interface for the AMQ protocol, and also. provide proven and tested solutions to common messaging problems.
RabbitMQ is a messaging broker. It accepts messages from publishers, routes them and, if there were queues to route to, stores them for consumption or immediately delivers to consumers, if any. Consumers consume from queues. In order to consume messages there has to be a queue.
By default, RabbitMQ will send each message to the next consumer, in sequence. On average every consumer will get the same number of messages. This way of distributing messages is called round-robin.
Turns out its a simple error. Adding
connection.drain_events()
to the while loop causes messages to arrive.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With