Search code examples
pythonpython-3.xrabbitmqpika

Change RabbitMQ Consumer Callback to Invoke with 1 Argument (body) Instead of 4 Arguments


Normally, by pika driver, when we set a consumer, we should pass a callback as parameter. On new message, pika will invoke the callback with 4 arguments: ch, method, property, body.

I need my callback to get just one argument: body.

I mean:

def my_callback(body):
    pass

Instead of:

def my_callback(ch, method, property, body):
    pass

How can I implement it?


Solution

  • As @jdehesa said, the solution is using lambda expression, like so:

    lambda ch, method, property, body: my_callback(body)