0

I am looking to RabbitPy for consuming and publishing messages. The consumption part is fine, However I want to send back messages to a specific queue after doing something with the inbound message. However I cannot find anyway to do this in the documentation.

https://rabbitpy.readthedocs.io/en/latest/api/message.html

Here is my consume code:

with rabbitpy.Connection('amqp://guest:guest@localhost:5672/%2f') as conn:
        with conn.channel() as channel:
            queue_read = rabbitpy.Queue(channel, QUEUE_NAME)
            queue_write = rabbitpy.Queue(channel, QUEUE_NAME_RESPONSE)
            # Exit on CTRL-C
            try:
                # Consume the message
                for body in queue_read:
                   # do something on inboud...

Here is what it seems I can only set in creating and sending a message:

message = rabbitpy.Message(channel, result)
message.publish(EXCHANGE, RESPONSE_ROUTING_KEY, mandatory=False)

There is nothing related to a queue. How can I send a message to a specific queue with a routing key?

In Pika I would use the following:

channel = cnn.channel()
channel.exchange_declare(exchange=EXCHANGE, durable='True')
channel.exchange_declare(exchange=EXCHANGE, type='direct', durable='True')
channel.queue_declare(queue=QUEUE_NAME_RESPONSE, durable='True')
channel.queue_bind(exchange=EXCHANGE, queue=QUEUE_NAME_RESPONSE)
channel.basic_publish(exchange=EXCHANGE, routing_key=RESPONSE_ROUTING_KEY, body=return_JSON,properties=pika.BasicProperties(content_type='text/plain', delivery_mode=2))
channel.close()

How can I do this with RabbitPy?

backtrack
  • 7,996
  • 5
  • 52
  • 99
disruptive
  • 5,687
  • 15
  • 71
  • 135

2 Answers2

0

using EXCHANGE, RESPONSE_ROUTING_KEY the queue is binded.

enter image description here

For example

We have 2 queue, Queue1 and Queue2. 1 exchange as Exchange and routingky as routingkey1 and routingkey2.

Exchange  + routingkey1  ==> Queue1 
Exchange  + routingkey1  ==> Queue2

Assume that w ehave the above binding.

When your publisher send a message using Exchange + routingkey1 it will be send to Queue 1. If the publisher use routingkey1 message will be sent to Queue2.

You can create the necessary binding using Rabbitmq Management UI or form your code. more details can be found here

In Rabbitpy you can do something like this,

amqp = rabbitpy.AMQP(channel)
amqp.queue_bind(queue='Queuq1', exchange='Exchange', routing_key='RoutingKey1')
backtrack
  • 7,996
  • 5
  • 52
  • 99
  • This is RabbitPy not Pika, I need to explicitly declare this in the code, not through the UX (we cannot do this). We can solve this issue with Pika but not with RabbitPy. – disruptive Nov 09 '16 at 11:30
  • queue_bind(queue='', exchange='', routing_key='', nowait=False, arguments=None) https://rabbitpy.readthedocs.io/en/latest/api/amqp.html – backtrack Nov 09 '16 at 11:37
  • @techdisrupt, Check the updated answer. Also remove Pike from your Tag. – backtrack Nov 09 '16 at 11:39
0

I possibly have this by binding the routing key to the exchange and the queue. I have the following:

queue_write.bind(EXCHANGE, routing_key=RESPONSE_ROUTING_KEY, arguments=None)
disruptive
  • 5,687
  • 15
  • 71
  • 135