3
votes

Could someone with Pika experience give me a quick yes/no response as to whether the following functionality is possible, or whether my thinking that it is indicates a lack of conceptual understanding of Pika.

My desired functionality:

Python service (single threaded script) has one connection to my RabbitMQ broker using the SelectConnection adapter.

That connection has two channels.

Using one channel, A, the service declares a queue and binds to some exchange E1. The other channel, B, is used to declares some other exchange, E2.

The service consumes messages from the queue via A. It does some small processing of those messages, [possibly carries out CRUD operates through its connection to a MongoDB instance,] then publishes a message to exchange E2 via B.

I have read the Pika docs thoroughly, and have not found enough information to understand whether this is doable.

To put it simply - can a single python script both publish and consume via one selectconnection adapter connection?

1
The answer to your question is "yes". You can do everything you want with the connection provided that you don't use it across threads.user8808265
Thank you user8808265. FWIW if you 'answer' the question I would accept that as the answer.Xavier Taylor

1 Answers

1
votes

Yes of course. You can achieve that in many ways (via the same connection, different connection, same channel, different channel etc.)

What I do when I have implemented this in the past is, I create my connection, get the channel and setup my consumer with it's delegate (function). When my consume message function is called I get the channel parameter that comes with it, which I sub-sequentially use to publish the next message to a different queue. If you don't want to use the same channel, you can simply setup another then.