amqpy icon indicating copy to clipboard operation
amqpy copied to clipboard

Add more examples

Open veegee opened this issue 9 years ago • 4 comments

Add more examples in examples directory and update Sphinx docs with better examples.

veegee avatar Mar 20 '15 00:03 veegee

Are there any obvious examples you might be interested in seeing built?

I use RabbitMQ on the side for a project, and have used this library heavily for services that listen on exchanges for work to come in. I could easily adapt some of that code into usage examples, if you are interested. I've had to get creative when pulling down messages from multiple queues due to the single-threaded model of the library, but thus far things have worked out.

When I was using this library for the first time, I can think of a few things I would have loved to see documented, preferably with examples:

  • Similar examples to RabbitMQ's tutorial examples.

    These cover a huge breadth of use cases for AMQP, and when I first started using this library, I had their examples open in one set of browser tabs, and the amqpy docs open in another set of tabs. Even if these are examples not mirrored over wholesale, they at least illustrate common topics.

    • Hello World :: Basic producer/consumer over a queue, no exchanges.
    • Work Queue :: 1 producer, 2 consumers, no exchanges.
    • Publish/Subscribe :: 1 producer, 1 fanout exchange, 2 consumers.
    • Routing :: 1 producer, 1 direct exchange, 2 consumers, routing keys introduced.
    • Topics :: 1 producer, 1 topic exchange, 2 consumers, different binding keys.
    • RPC :: 1 client, 1 server, 2 queues. RPC work handled in client/server code.
  • Creating a custom consumer (Maybe one that deserializes and prints JSON or Msgpack formats).

  • Single client listening on multiple queues.

  • Single client pulling from 1+ queues and pushing messages to 1+ queues.

  • Example illustrating when to use single versus multiple channels on a given connection.

  • Example(s) using threading or multiprocessing and/or gevent in tandem with the library for concurrent work.

philipaconrad avatar Dec 28 '16 04:12 philipaconrad

Sure! Feel free to contribute whatever you think is best. Any help would be much appreciated!

I have to rework the internals of this library to allow for more efficient multithreading. The best way to go about it is via Go-style channels and a Go-style select over the channels. I'm open to any suggestions regarding the implementation of this.

veegee avatar Dec 31 '16 20:12 veegee

I'm in the process of porting over the RabbitMQ tutorial examples, and the first 5 were relatively straightforward since amqpy's API is fairly similar to pika's.

However, I ran into a problem porting their RPC demonstration. It seems to rely on message recipients being able to see fields like reply_to and correlation_id.

From what I can see in amqpy's channel.py, these fields are set sender-side, but are not visible to receivers. For now, I can probably hack around the issue using application headers or something.

It seems to me like this might be something to provide under Message.delivery_info, since fields like exchange and routing_key are available from there.

Thoughts?

philipaconrad avatar Jan 01 '17 22:01 philipaconrad

I've used reply_to and correlation_id successfully, on the sending and receiving side (both sides using amqpy). They are stored on the Message.properties dictionary and can be retrieved by name there.

pryano avatar Feb 23 '17 17:02 pryano