benjamin-hodgson / asynqp

An AMQP library for asyncio
MIT License
84 stars 29 forks source link

Getting routing_key of incoming message #8

Closed selaux closed 10 years ago

selaux commented 10 years ago

Hey,

is there currently a way to get the routing key of an incoming message when subscribing to a topic exchange?

Example Code:

def handle_message(message):
    # GET ROUTING KEY HERE
    pass

connection = yield from asynqp.connect(
            RABBITMQ_HOST,
            RABBITMQ_PORT,
            RABBITMQ_USERNAME,
            RABBITMQ_PASSWORD,
            RABBITMQ_VIRTUAL_HOST
        )
channel = yield from connection.open_channel()
exchange = yield from channel.declare_exchange(EXCHANGE, 'topic')
queue = yield from channel.declare_queue(QUEUE, auto_delete=True)
consumer = yield from queue.consume(handle_message)
queue.bind(exchange, 'foo.key')
queue.bind(exchange, 'bar.key')
benjamin-hodgson commented 10 years ago

You're right, this feature needs to be added. It's a five-minute job, I'll try and do it next time I get the chance to work on it. Thanks for the feedback :smile:

selaux commented 10 years ago

Sweet, thanks :+1:

benjamin-hodgson commented 10 years ago

I've addressed this issue in commit 6e53b0e by adding some new attributes to IncomingMessage. Could you take the latest master for a spin and see if it works for you?

selaux commented 10 years ago

Works great, thanks.