Skip to content

Commit

Permalink
Update default async behavior to True
Browse files Browse the repository at this point in the history
Read async behavior from envvar `MQ_ASYNC_CONSUMERS`
Update documentation to reflect changes in default and configuration
  • Loading branch information
NeonDaniel committed Jan 20, 2025
1 parent ac28303 commit 6260da6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,26 @@ A response may be sent via:
```
Where `<queue>` 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
```
```shell
export MQ_ASYNC_CONSUMERS=false
```
2 changes: 1 addition & 1 deletion neon_mq_connector/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 6260da6

Please sign in to comment.