python - How can I use Pika to send and receive RabbitMQ messages? -
I am having some problem so that the pic is getting in the way of working with routing keys or exchanges, which It is compatible with AMQP or RabbitMQ documentation. I understand that the RabbitMQ documentation uses an earlier version of Pika, so I have ignored their example code
What I'm trying to do is a line, defines "order" And there are two consumers who handle "Production" of Exchange or Routing_ and who handle "Tests" by looking at the Rabbit MQ document which is directly using direct exchange and routing keys or Isi theme should be quite easy using Exchange.
Although the pica does not even know what to do with the exchanges and routing keys, using RabbitMQ management tool to inspect the queues, it is very clear that the pic or the message may be correctly queued Does not give or that RabbitMQ threw it
On the consumer side, it is not really clear how can I force a user to exchange or handle routing And the documentation is not really helping.
If I get ideas or exchange and routing keys, the message queue up well and is easily handled by my consumer.
Any sign or example code would be good for the people.
As it turns out, my understanding of AMQP was incomplete
< / P>
Customers : After receiving the connection, the customer should not have anything else for the exchange name and the routing key we do not know This is how the queue will end. Consumer When the channel is open, we declare the exchange and queue Channel.exchange_declare (exchange = 'order', type = "topic", durable = true, auto_delete = False) channel.queue_declare (queue) "test", durable = true, exclusive = false, auto_delete = False, callback = on_queue_declared) When the queue is ready, there is a good place in the "on_queue_declared" callback, Using Unji can bind the queue.
channel.basic_publish (exchange = 'order', routing_key = "order.test.customer", body = pickle.dumps (data), attribute = pika.BasicProperties (content_type = "text /
channel.queue_bind (queue = 'test', exchange = 'order', routing_key = 'order.test.customer') #handle_delivery is a callback that actually returns # Will handle by sending messages. The message sent on the "Order" exchange with the routing key "order.test.customer" will now be sent to the "Test" queue, Where consumers can choose it
Comments
Post a Comment