Skip to content

Commit

Permalink
docs: Don't mix-in consumer mixin for publisher-only client
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Jan 24, 2022
1 parent 46236d1 commit 85c24e8
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ Yet Another Pika Wrapper |release|
Configure a RabbitMQ client
---------------------------

Create a Client class, by layering in :doc:`mixins<api/clients>`:
Create client classes, by layering in :doc:`mixins<api/clients>`:

.. code-block:: python
from yapw import clients
class Client(clients.Threaded, clients.Durable, clients.Blocking, clients.Base):
class Consumer(clients.Threaded, clients.Durable, clients.Blocking, clients.Base):
pass
class Publisher(clients.Durable, clients.Blocking, clients.Base):
pass
Each mixing contributes features, such that a client will:
Expand All @@ -35,11 +39,15 @@ Publish messages outside a consumer callback

.. code-block:: python
publisher = Client(url="amqp://user:pass@127.0.0.1", exchange="myexchange")
publisher = Publisher(url="amqp://user:pass@127.0.0.1", exchange="myexchange")
publisher.publish({"message": "value"}, routing_key="messages")
The routing key is namespaced by the exchange name, to make it "myexchange_messages".

.. note::

The ``Threaded`` mixin installs :ref:`signal handlers<signal-handling>`, which can only be installed in the main thread. The ``Publisher`` class might be instantiated in a non-main thread (like in a web request); therefore, it doesn't inherit from the ``Threaded`` mixin.

Consume messages
----------------

Expand All @@ -60,7 +68,7 @@ Consume messages
ack(state, channel, method.delivery_tag)
consumer = Client(url="amqp://user:pass@127.0.0.1", exchange="myexchange", prefetch_count=5)
consumer = Consumer(url="amqp://user:pass@127.0.0.1", exchange="myexchange", prefetch_count=5)
consumer.consume(callback, queue="messages", decorator=discard)
yapw implements a pattern whereby the consumer declares and binds a queue. By default, the queue's name and binding key are the same, and are namespaced by the exchange name. To set the binding keys:
Expand Down Expand Up @@ -110,7 +118,7 @@ You can change this behavior. For example, change the bodies of the ``encode`` a
return body
client = Client(encode=encode, decode=decode)
client = Consumer(encode=encode, decode=decode)
publisher.publish({"message": "value"}, routing_key="messages")
Error handling
Expand All @@ -127,6 +135,8 @@ The default decorator is the :func:`yapw.decorators.halt` function, which sends

All decorators also decode the message body, which can be configured as above. If an exception occurs while decoding, the decorator sends the SIGUSR2 signal to the main thread, without acknowledging the message. The :class:`~yapw.clients.Threaded` mixin handles this signal by shutting down gracefully.

.. _signal-handling:

Signal handling
~~~~~~~~~~~~~~~

Expand Down

0 comments on commit 85c24e8

Please sign in to comment.