diff --git a/README.md b/README.md index 50ce009..e1c702d 100644 --- a/README.md +++ b/README.md @@ -67,17 +67,26 @@ A response may be sent via: ``` Where `` is the queue to which the response will be published, and `data` is a `bytes` response (generally a `base64`-encoded `dict`). -### [BETA] Asynchronous Consumers +### Asynchronous Consumers +By default, async-based consumers handling based on `pika.SelectConnection` will +be used -Now there is a support for async-based consumers handling based on `pika.SelectConnection` +#### Override use of async consumers -#### Enabling in a code +There are a few methods to disable use of async consumers/subscribers. -To enable creation of async consumers/subscribers, set the class-attribute `async_consumers_enabled` to True: +1. To disable async consumers for a particular class/object, +set the class-attribute `async_consumers_enabled` to `False`: -```python -from neon_mq_connector import MQConnector + ```python + from neon_mq_connector import MQConnector + + class MQConnectorChild(MQConnector): + async_consumers_enabled = True + ``` +2. To disable the use of async consumers at runtime, set the `MQ_ASYNC_CONSUMERS` +envvar to `False` -class MQConnectorChild(MQConnector): - async_consumers_enabled = True -``` \ No newline at end of file + ```shell + export MQ_ASYNC_CONSUMERS=false + ``` diff --git a/neon_mq_connector/connector.py b/neon_mq_connector/connector.py index 72fc5d7..dc8dbd3 100644 --- a/neon_mq_connector/connector.py +++ b/neon_mq_connector/connector.py @@ -65,7 +65,7 @@ class MQConnector(ABC): __max_consumer_restarts__ = -1 __consumer_join_timeout__ = 3 - async_consumers_enabled = False + async_consumers_enabled = os.environ.get("MQ_ASYNC_CONSUMERS", True) @staticmethod def init_config(config: Optional[dict] = None) -> dict: