[rabbitmq-discuss] RabbitMQ Usage Patterms?

Shalom Rav csharpplusproject at gmail.com
Tue Jul 19 17:31:32 BST 2011


Marek,

Thank you for your response.

Obviosuly, my main attention goes to the application itself. So 99% of
the time, I'd like it to just run.

I am *happy* to block my app momentarily to consume incoming messages
as they arrive. Then, when messages are consumed, I'd like the
application to keep running.

The question is, how do I achieve the above using python?

So far, it looks like *channel.start_consuming()* just BLOCKS
EVERYTHING and puts 100% of the focus on the messaging (not letting
anything else to run).

Any idea how to solve this?

On Jul 19, 9:20 am, Marek Majkowski <maje... at gmail.com> wrote:
> On Tue, Jul 19, 2011 at 03:31, csharpplusproject
>
> <csharpplusproj... at gmail.com> wrote:
> > Thank you for your explanation, although I do not really understand how this
> > works.
>
> > You write: "...listening for messages arriving from RabbitMQ and dispatching
> > them to your application."
>
> > I have no problem writing code that is "...listening for messages arriving
> > from RabbitMQ". The question is, how do I dispatch these messages to my
> > application while letting the application run continuously with no
> > interruptions?
>
> > Can anybody provide sample code in python that demonstrates such a pattern?
>
> Okay, where to start....
>
> When Rabbitmq (or any other network application) sends data to tcp/ip
> connection,
> well, it is encoded as electrons on the wire.
>
> On the other side of the wire, maybe on different computer, a network card
> receives electrons, decodes them and appends to a tcp/ip receive
> buffer for a particular tcp/ip connection.
>
> That was easy. Now the hard part. It's the application that needs to ask
> the kernel: "is there more data available for me in the buffers?"
>
> Asking this question all over again would be quite inefficient, so it's usually
> put as a blocking request: "give me this number of bytes of data from
> my tcp/ip buffers, wait if there isn't enough yet".
>
> Most AMQP clients follow this pattern: you can do CPU intensive
> work in your application *or* you can wait on the network and
> receive and send data.
>
> If you want to listen to messages: you shall block your program and wait
> for network traffic.
>
> Coming back to your question:
>
> > The question is, how do I dispatch these messages to my
> > application while letting the application run continuously with no
> > interruptions?
>
> You don't. If you want to receive data, you need to or:
>  - block program and hang on socket till data is received
>  - or poll kernel asking for more data which is quite inefficient
>
> In normal programming languages people use threads to do that,
> one thread does CPU stuff, the other does network stuff.
> But a) threads in general are complex b) threads in python are weird.
>
> Hope that helps,
>   Marek
> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-disc... at lists.rabbitmq.comhttps://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss


More information about the rabbitmq-discuss mailing list