1

Look at the following screenshot

enter image description here

My queue has a binding with an exchange named foo only receiving messages with Routing key bar. I have also defined a pair of arguments {baz: qux}. Now I have a following code:

credentials = pika.PlainCredentials(...)
parameters = pika.ConnectionParameters(...)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
channel.basic_qos(prefetch_count=1)
channel.basic_consume(callback, queue='this_queue')

And the callback has the following signature:

def callback(channel, method, properties, body):
    ....

Now the question: how do I access arguments ({baz: qux}) inside the callback. Is this possible at all?

mnowotka
  • 16,430
  • 18
  • 88
  • 134

2 Answers2

0

It's not possible as AMQP doesn't provide that information in the response to basic.consume. You can use the HTTP API to retrieve that information as long as you have the rabbitmq_management plugin enabled (which you must, if you took that screen shot).


NOTE: the RabbitMQ team monitors the rabbitmq-users mailing list and only sometimes answers questions on StackOverflow.

Luke Bakken
  • 8,993
  • 2
  • 20
  • 33
0

You could use my RabbitMQ library amqpstorm to get this type of information.

from amqpstorm.management import ManagementApi

API = ManagementApi('http://127.0.0.1:15672', 'guest', 'guest')
print(API.queue.bindings('simple_queue', virtual_host='/'))

The result would look something like this.

[
    {
        "source": "",
        "vhost": "/",
        "destination": "simple_queue",
        "destination_type": "queue",
        "routing_key": "simple_queue",
        "arguments": {},
        "properties_key": "simple_queue"
    },
    {
        "source": "amq.direct",
        "vhost": "/",
        "destination": "simple_queue",
        "destination_type": "queue",
        "routing_key": "test",
        "arguments": {},
        "properties_key": "test"
    }
]

More examples available here.

eandersson
  • 25,781
  • 8
  • 89
  • 110