amqp-client-python 0.2.0.post1__tar.gz → 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- amqp_client_python-0.2.1/.github/workflows/publish.yml +22 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/PKG-INFO +14 -9
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/README.md +12 -6
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/__init__.py +11 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/domain/models/__init__.py +6 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/domain/utils/__init__.py +5 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/event/__init__.py +9 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/exceptions/__init__.py +12 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/rabbitmq/__init__.py +15 -1
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/rabbitmq/async_channel.py +32 -13
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/rabbitmq/async_connection.py +87 -51
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/rabbitmq/async_eventbus_rabbitmq.py +20 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/rabbitmq/eventbus_wrapper_rabbitmq.py +29 -3
- amqp_client_python-0.2.1/docs/templates/installation.md +11 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/pyproject.toml +1 -2
- amqp_client_python-0.2.1/tests/integration/async_eventbus/auto_recovery_test.py +167 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/unit/channels/test_async_rpc_client.py +37 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/unit/channels/test_publish.py +29 -0
- amqp_client_python-0.2.1/tests/unit/channels/test_subscribe.py +120 -0
- amqp_client_python-0.2.1/tests/unit/eventbus/test_auto_recovery.py +64 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/uv.lock +4 -1
- amqp_client_python-0.2.0.post1/.github/workflows/publish.yml +0 -24
- amqp_client_python-0.2.0.post1/docs/templates/installation.md +0 -9
- amqp_client_python-0.2.0.post1/tests/unit/channels/test_subscribe.py +0 -30
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/.env.example +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/.flake8 +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/.github/workflows/lint.yml +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/.github/workflows/test.yml +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/.github/workflows/type.yml +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/.gitignore +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/.pre-commit-config.yaml +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/.readthedocs.yaml +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/.vscode/settings.json +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/CODE_OF_CONDUCT.md +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/LICENSE +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/domain/models/config.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/domain/models/options.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/domain/models/ssl_options.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/domain/utils/connection_type.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/domain/utils/types.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/event/async_provider_handler.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/event/async_subscriber_handler.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/event/event.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/event/integration_event.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/event/integration_event_handler.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/event/provider_handler.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/event/subscriber_handler.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/exceptions/auto_reconnect_exception.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/exceptions/blocking_exception.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/exceptions/eventbus_exception.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/exceptions/nack_exception.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/exceptions/publish_timeout_exception.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/exceptions/response_timeout_exception.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/exceptions/rpc_provider_exception.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/exceptions/thread_unsafe_exception.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/exceptions/timeout_exception.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/py.typed +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/rabbitmq/async_channel_factory.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/rabbitmq/async_connection_factory.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/rabbitmq/channel_factory_rabbitmq.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/rabbitmq/channel_rabbitmq.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/rabbitmq/connection_factory_rabbitmq.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/rabbitmq/connection_rabbitmq.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/rabbitmq/eventbus_rabbitmq.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/rabbitmq/ioloop_factory.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/signals.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/create-self-signed-certs.sh +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/dev_requirements.txt +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/docker-compose.yml +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/docs/API/domain/config.md +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/docs/API/domain/options.md +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/docs/API/domain/ssl_options.md +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/docs/API/rabbitmq/async_eventbus.md +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/docs/contribute.md +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/docs/index.md +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/docs/stylesheets/extra.css +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/docs/templates/cards.html +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/docs/templates/sponsors.md +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/docs/templates/user_guide.md +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/docs/tutorial.md +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/examples/__init__.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/examples/async_case.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/examples/default.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/examples/multprocess.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/examples/publish.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/examples/rpc_publish.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/examples/rpc_subscribe.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/examples/sanic_test.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/examples/ssl_connection.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/examples/subscribe.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/examples/sync_case.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/examples/sync_wrapper_case.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/examples/thread.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/external_config/rabbitmq/rabbitmq.conf +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/mkdocs.yml +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/mypy.ini +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/__init__.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/integration/__init__.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/integration/async_eventbus/__init__.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/integration/async_eventbus/conftest.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/integration/async_eventbus/rpc_provider_test.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/integration/async_eventbus/signals_test.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/integration/async_eventbus/ssl_test.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/integration/async_eventbus/subscribe_test.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/integration/async_eventbus_wrapper/__init__.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/integration/async_eventbus_wrapper/conftest.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/integration/async_eventbus_wrapper/rpc_provider_test.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/integration/async_eventbus_wrapper/signals_test.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/integration/async_eventbus_wrapper/ssl_test.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/integration/async_eventbus_wrapper/subscribe_test.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/integration/eventbus/__init__.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/integration/eventbus/conftest.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/integration/eventbus/publish_test.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/integration/eventbus/rpc_publish_test.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/integration/eventbus/rpc_subscribe_test.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/integration/eventbus/subscribe_test.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/unit/__init__.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/unit/channels/test_async_channel.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/unit/channels/test_channel_factory.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/unit/channels/test_rpc_subscribe.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/unit/config/test_uri.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/unit/conftest.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/unit/eventbus/default.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/unit/eventbus/test_async_eventbus.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/unit/eventbus/test_async_eventbus_provide_resource.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/unit/eventbus/test_async_eventbus_publish.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/unit/eventbus/test_async_eventbus_rpc_client.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/unit/eventbus/test_async_eventbus_subscribe.py +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/unit/utils/ca.pem +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/unit/utils/rabbitmq_cert.pem +0 -0
- {amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/tests/unit/utils/rabbitmq_key.pem +0 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [created]
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
deploy:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
|
|
14
|
+
- name: Install uv
|
|
15
|
+
uses: astral-sh/setup-uv@v5
|
|
16
|
+
|
|
17
|
+
- name: Build and publish
|
|
18
|
+
env:
|
|
19
|
+
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }}
|
|
20
|
+
run: |
|
|
21
|
+
uv build
|
|
22
|
+
uv publish
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: amqp-client-python
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: Python AMQP Client Library
|
|
5
5
|
Project-URL: Homepage, https://github.com/nutes-uepb/amqp-client-python
|
|
6
6
|
Project-URL: Repository, https://github.com/nutes-uepb/amqp-client-python
|
|
@@ -17,7 +17,6 @@ Classifier: License :: OSI Approved :: Apache Software License
|
|
|
17
17
|
Classifier: Natural Language :: English
|
|
18
18
|
Classifier: Operating System :: OS Independent
|
|
19
19
|
Classifier: Programming Language :: Python :: 3
|
|
20
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
21
20
|
Classifier: Programming Language :: Python :: 3.9
|
|
22
21
|
Classifier: Programming Language :: Python :: 3.10
|
|
23
22
|
Classifier: Programming Language :: Python :: 3.11
|
|
@@ -81,19 +80,22 @@ pip install amqp-rs
|
|
|
81
80
|
### Table of Compatibility
|
|
82
81
|
| version | compatible with |
|
|
83
82
|
| ---- | ---- |
|
|
83
|
+
| 0.2.1 | ~0.2.0 |
|
|
84
84
|
| 0.2.0 | 0.2.0 |
|
|
85
85
|
| 0.1.14 | ~0.1.12 |
|
|
86
86
|
|
|
87
87
|
### Installation
|
|
88
88
|
|
|
89
|
-
You can install `amqp-client-python` using pip:
|
|
89
|
+
You can install `amqp-client-python` using uv or pip:
|
|
90
90
|
```bash
|
|
91
|
+
uv add amqp-client-python
|
|
92
|
+
# or
|
|
91
93
|
pip install amqp-client-python
|
|
92
94
|
```
|
|
93
95
|
|
|
94
96
|
### Prerequisites
|
|
95
97
|
|
|
96
|
-
* Python 3.
|
|
98
|
+
* Python 3.9+
|
|
97
99
|
* A running RabbitMQ instance.
|
|
98
100
|
|
|
99
101
|
### Examples:
|
|
@@ -110,15 +112,18 @@ from amqp_client_python import (
|
|
|
110
112
|
)
|
|
111
113
|
config = Config(Options("queue", "rpc_queue", "rpc_exchange"))
|
|
112
114
|
eventbus = AsyncEventbusRabbitMQ(config)
|
|
113
|
-
# publish
|
|
115
|
+
# publish (supports dict/str with auto-JSON, or raw bytes/bytearray without overhead)
|
|
116
|
+
await eventbus.publish("rpc_exchange", "routing.key", {"message": "content"})
|
|
117
|
+
await eventbus.publish("rpc_exchange", "routing.key", b"raw_binary_payload")
|
|
114
118
|
|
|
115
|
-
|
|
116
|
-
# subscribe
|
|
119
|
+
# subscribe (auto_decode=True delivers parsed JSON dict; auto_decode=False delivers raw bytes)
|
|
117
120
|
async def subscribe_handler(body) -> None:
|
|
118
121
|
print(body, type(body), flush=True) # handle messages
|
|
119
122
|
await eventbus.subscribe("rpc_exchange", "routing.key", subscribe_handler)
|
|
123
|
+
|
|
120
124
|
# rpc_publish
|
|
121
|
-
response = await eventbus.rpc_client("rpc_exchange", "user.find", "
|
|
125
|
+
response = await eventbus.rpc_client("rpc_exchange", "user.find", {"name": "alice"})
|
|
126
|
+
|
|
122
127
|
# provider
|
|
123
128
|
async def rpc_provider_handler(body) -> bytes:
|
|
124
129
|
print(f"body: {body}")
|
|
@@ -46,19 +46,22 @@ pip install amqp-rs
|
|
|
46
46
|
### Table of Compatibility
|
|
47
47
|
| version | compatible with |
|
|
48
48
|
| ---- | ---- |
|
|
49
|
+
| 0.2.1 | ~0.2.0 |
|
|
49
50
|
| 0.2.0 | 0.2.0 |
|
|
50
51
|
| 0.1.14 | ~0.1.12 |
|
|
51
52
|
|
|
52
53
|
### Installation
|
|
53
54
|
|
|
54
|
-
You can install `amqp-client-python` using pip:
|
|
55
|
+
You can install `amqp-client-python` using uv or pip:
|
|
55
56
|
```bash
|
|
57
|
+
uv add amqp-client-python
|
|
58
|
+
# or
|
|
56
59
|
pip install amqp-client-python
|
|
57
60
|
```
|
|
58
61
|
|
|
59
62
|
### Prerequisites
|
|
60
63
|
|
|
61
|
-
* Python 3.
|
|
64
|
+
* Python 3.9+
|
|
62
65
|
* A running RabbitMQ instance.
|
|
63
66
|
|
|
64
67
|
### Examples:
|
|
@@ -75,15 +78,18 @@ from amqp_client_python import (
|
|
|
75
78
|
)
|
|
76
79
|
config = Config(Options("queue", "rpc_queue", "rpc_exchange"))
|
|
77
80
|
eventbus = AsyncEventbusRabbitMQ(config)
|
|
78
|
-
# publish
|
|
81
|
+
# publish (supports dict/str with auto-JSON, or raw bytes/bytearray without overhead)
|
|
82
|
+
await eventbus.publish("rpc_exchange", "routing.key", {"message": "content"})
|
|
83
|
+
await eventbus.publish("rpc_exchange", "routing.key", b"raw_binary_payload")
|
|
79
84
|
|
|
80
|
-
|
|
81
|
-
# subscribe
|
|
85
|
+
# subscribe (auto_decode=True delivers parsed JSON dict; auto_decode=False delivers raw bytes)
|
|
82
86
|
async def subscribe_handler(body) -> None:
|
|
83
87
|
print(body, type(body), flush=True) # handle messages
|
|
84
88
|
await eventbus.subscribe("rpc_exchange", "routing.key", subscribe_handler)
|
|
89
|
+
|
|
85
90
|
# rpc_publish
|
|
86
|
-
response = await eventbus.rpc_client("rpc_exchange", "user.find", "
|
|
91
|
+
response = await eventbus.rpc_client("rpc_exchange", "user.find", {"name": "alice"})
|
|
92
|
+
|
|
87
93
|
# provider
|
|
88
94
|
async def rpc_provider_handler(body) -> bytes:
|
|
89
95
|
print(f"body: {body}")
|
|
@@ -2,3 +2,14 @@ from .rabbitmq import EventbusRabbitMQ, AsyncEventbusRabbitMQ, EventbusWrapperRa
|
|
|
2
2
|
from .domain.models import Config, Options, SSLOptions
|
|
3
3
|
from .domain.utils import ConnectionType
|
|
4
4
|
from pika import DeliveryMode
|
|
5
|
+
|
|
6
|
+
__all__ = [
|
|
7
|
+
"EventbusRabbitMQ",
|
|
8
|
+
"AsyncEventbusRabbitMQ",
|
|
9
|
+
"EventbusWrapperRabbitMQ",
|
|
10
|
+
"Config",
|
|
11
|
+
"Options",
|
|
12
|
+
"SSLOptions",
|
|
13
|
+
"ConnectionType",
|
|
14
|
+
"DeliveryMode",
|
|
15
|
+
]
|
{amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/event/__init__.py
RENAMED
|
@@ -4,3 +4,12 @@ from .async_provider_handler import AsyncProviderHandler
|
|
|
4
4
|
from .async_subscriber_handler import AsyncSubscriberHandler
|
|
5
5
|
from .provider_handler import ProviderHandler
|
|
6
6
|
from .subscriber_handler import SubscriberHandler
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
"IntegrationEvent",
|
|
10
|
+
"IntegrationEventHandler",
|
|
11
|
+
"AsyncProviderHandler",
|
|
12
|
+
"AsyncSubscriberHandler",
|
|
13
|
+
"ProviderHandler",
|
|
14
|
+
"SubscriberHandler",
|
|
15
|
+
]
|
|
@@ -7,3 +7,15 @@ from .publish_timeout_exception import PublishTimeoutException
|
|
|
7
7
|
from .auto_reconnect_exception import AutoReconnectException
|
|
8
8
|
from .blocking_exception import BlockingException
|
|
9
9
|
from .thread_unsafe_exception import ThreadUnsafeException
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"EventBusException",
|
|
13
|
+
"NackException",
|
|
14
|
+
"RpcProviderException",
|
|
15
|
+
"TimeoutException",
|
|
16
|
+
"ResponseTimeoutException",
|
|
17
|
+
"PublishTimeoutException",
|
|
18
|
+
"AutoReconnectException",
|
|
19
|
+
"BlockingException",
|
|
20
|
+
"ThreadUnsafeException",
|
|
21
|
+
]
|
{amqp_client_python-0.2.0.post1 → amqp_client_python-0.2.1}/amqp_client_python/rabbitmq/__init__.py
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from .async_eventbus_rabbitmq import AsyncEventbusRabbitMQ
|
|
2
2
|
from .async_connection_factory import AsyncConnectionFactoryRabbitMQ
|
|
3
|
-
from .async_connection import AsyncConnection
|
|
3
|
+
from .async_connection import AsyncConnection
|
|
4
4
|
from .async_channel_factory import AsyncChannelFactoryRabbitMQ
|
|
5
5
|
from .async_channel import AsyncChannel
|
|
6
6
|
from .eventbus_rabbitmq import EventbusRabbitMQ
|
|
@@ -9,3 +9,17 @@ from .connection_rabbitmq import ConnectionRabbitMQ
|
|
|
9
9
|
from .channel_factory_rabbitmq import ChannelFactoryRabbitMQ
|
|
10
10
|
from .channel_rabbitmq import ChannelRabbitMQ
|
|
11
11
|
from .eventbus_wrapper_rabbitmq import EventbusWrapperRabbitMQ
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
"AsyncEventbusRabbitMQ",
|
|
15
|
+
"AsyncConnectionFactoryRabbitMQ",
|
|
16
|
+
"AsyncConnection",
|
|
17
|
+
"AsyncChannelFactoryRabbitMQ",
|
|
18
|
+
"AsyncChannel",
|
|
19
|
+
"EventbusRabbitMQ",
|
|
20
|
+
"ConnectionFactoryRabbitMQ",
|
|
21
|
+
"ConnectionRabbitMQ",
|
|
22
|
+
"ChannelFactoryRabbitMQ",
|
|
23
|
+
"ChannelRabbitMQ",
|
|
24
|
+
"EventbusWrapperRabbitMQ",
|
|
25
|
+
]
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from collections import deque
|
|
1
2
|
from typing import MutableMapping, Mapping, Optional, Union, Dict, List
|
|
2
3
|
from .async_channel_factory import AsyncChannelFactoryRabbitMQ
|
|
3
4
|
from amqp_client_python.exceptions import (
|
|
@@ -59,13 +60,19 @@ class AsyncChannel:
|
|
|
59
60
|
self._deliveries: MutableMapping[int, Future] = {}
|
|
60
61
|
self.response_timeout = 60
|
|
61
62
|
|
|
63
|
+
@staticmethod
|
|
64
|
+
def _serialize_payload(body, content_type: str = "application/json"):
|
|
65
|
+
if isinstance(body, (bytes, bytearray, memoryview)):
|
|
66
|
+
return body
|
|
67
|
+
return dumps(body)
|
|
68
|
+
|
|
62
69
|
@property
|
|
63
70
|
def is_open(self) -> Optional[bool]:
|
|
64
71
|
return self._channel and self._channel.is_open
|
|
65
72
|
|
|
66
|
-
def open(self, connection: AsyncioConnection, callbacks=
|
|
73
|
+
def open(self, connection: AsyncioConnection, callbacks=None):
|
|
67
74
|
if not self.is_open:
|
|
68
|
-
self.callbacks = callbacks
|
|
75
|
+
self.callbacks = callbacks if callbacks is not None else deque()
|
|
69
76
|
self._connection = connection
|
|
70
77
|
self.ioloop = connection.ioloop
|
|
71
78
|
self._channel = self.channel_factory.create_channel(
|
|
@@ -87,10 +94,15 @@ class AsyncChannel:
|
|
|
87
94
|
self.ioloop.create_task(self.process_callbacks()) # type: ignore
|
|
88
95
|
|
|
89
96
|
async def process_callbacks(self):
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
97
|
+
while self.callbacks:
|
|
98
|
+
callback, future = self.callbacks.popleft()
|
|
99
|
+
try:
|
|
100
|
+
result = await callback()
|
|
101
|
+
if not future.done():
|
|
102
|
+
future.set_result(result)
|
|
103
|
+
except Exception as exc:
|
|
104
|
+
if not future.done():
|
|
105
|
+
future.set_exception(exc)
|
|
94
106
|
|
|
95
107
|
def add_on_channel_close_callback(self):
|
|
96
108
|
"""This method tells pika to call the on_channel_closed method if
|
|
@@ -302,7 +314,7 @@ class AsyncChannel:
|
|
|
302
314
|
if self.rpc_publisher_started:
|
|
303
315
|
return True
|
|
304
316
|
if self.rpc_publisher_starting:
|
|
305
|
-
return await self.
|
|
317
|
+
return await self.rpc_publisher_future
|
|
306
318
|
self.rpc_publisher_starting = True
|
|
307
319
|
self.rpc_publisher_future = self.ioloop.create_future()
|
|
308
320
|
|
|
@@ -355,7 +367,7 @@ class AsyncChannel:
|
|
|
355
367
|
self._channel.basic_publish(
|
|
356
368
|
exchange_name,
|
|
357
369
|
routing_key,
|
|
358
|
-
|
|
370
|
+
self._serialize_payload(body, content_type),
|
|
359
371
|
properties=BasicProperties(
|
|
360
372
|
reply_to=self._callback_queue, # Response queue address
|
|
361
373
|
correlation_id=corr_id, # Request/response matching ID
|
|
@@ -430,7 +442,7 @@ class AsyncChannel:
|
|
|
430
442
|
self._channel.basic_publish(
|
|
431
443
|
exchange_name,
|
|
432
444
|
routing_key,
|
|
433
|
-
|
|
445
|
+
self._serialize_payload(body, content_type),
|
|
434
446
|
properties=BasicProperties(
|
|
435
447
|
reply_to=self._callback_queue,
|
|
436
448
|
content_type=content_type,
|
|
@@ -485,13 +497,14 @@ class AsyncChannel:
|
|
|
485
497
|
exchange_type="topic",
|
|
486
498
|
durable=True,
|
|
487
499
|
auto_delete=False,
|
|
500
|
+
auto_decode=True,
|
|
488
501
|
):
|
|
489
502
|
await self.start_rpc_publisher()
|
|
490
503
|
self.register_queue(
|
|
491
504
|
exchange_name, queue_name, exchange_type, durable, auto_delete
|
|
492
505
|
)
|
|
493
506
|
self.register_handler(
|
|
494
|
-
queue_name, routing_key, callback, content_type, timeout
|
|
507
|
+
queue_name, routing_key, callback, content_type, timeout, auto_decode=auto_decode
|
|
495
508
|
)
|
|
496
509
|
|
|
497
510
|
self.queue_bind(queue_name, exchange_name, routing_key)
|
|
@@ -526,13 +539,14 @@ class AsyncChannel:
|
|
|
526
539
|
self.consumers[queue_name] = False
|
|
527
540
|
|
|
528
541
|
def register_handler(
|
|
529
|
-
self, queue_name, routing_key, callback, content_type, response_timeout
|
|
542
|
+
self, queue_name, routing_key, callback, content_type, response_timeout, auto_decode=True
|
|
530
543
|
):
|
|
531
544
|
if routing_key not in self.subscribes[queue_name]:
|
|
532
545
|
self.subscribes[queue_name][routing_key] = {
|
|
533
546
|
"handle": callback,
|
|
534
547
|
"content_type": content_type,
|
|
535
548
|
"response_timeout": response_timeout or self.response_timeout,
|
|
549
|
+
"auto_decode": auto_decode,
|
|
536
550
|
}
|
|
537
551
|
if "*" in routing_key and routing_key not in self.re_subscribes:
|
|
538
552
|
self.re_subscribes.append(routing_key)
|
|
@@ -548,12 +562,13 @@ class AsyncChannel:
|
|
|
548
562
|
exchange_type: str = "topic",
|
|
549
563
|
durable: bool = True,
|
|
550
564
|
auto_delete: bool = False,
|
|
565
|
+
auto_decode: bool = True,
|
|
551
566
|
) -> None:
|
|
552
567
|
self.register_queue(
|
|
553
568
|
exchange_name, queue_name, exchange_type, durable, auto_delete
|
|
554
569
|
)
|
|
555
570
|
self.register_handler(
|
|
556
|
-
queue_name, routing_key, callback, content_type, timeout
|
|
571
|
+
queue_name, routing_key, callback, content_type, timeout, auto_decode=auto_decode
|
|
557
572
|
)
|
|
558
573
|
|
|
559
574
|
self.queue_bind(queue_name, exchange_name, routing_key)
|
|
@@ -581,7 +596,11 @@ class AsyncChannel:
|
|
|
581
596
|
|
|
582
597
|
async def process_message(handler: HandlerType):
|
|
583
598
|
nonlocal body
|
|
584
|
-
|
|
599
|
+
if handler.get("auto_decode", True) and handler.get("content_type") == "application/json":
|
|
600
|
+
try:
|
|
601
|
+
body = loads(body)
|
|
602
|
+
except Exception:
|
|
603
|
+
pass
|
|
585
604
|
response = await wait_for(
|
|
586
605
|
handler["handle"](body),
|
|
587
606
|
timeout=handler["response_timeout"],
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
from
|
|
1
|
+
from collections import deque
|
|
2
|
+
from typing import Optional, Callable, Awaitable, Tuple, Dict, Any
|
|
3
|
+
|
|
2
4
|
from .async_connection_factory import AsyncConnectionFactoryRabbitMQ, AsyncioConnection
|
|
3
5
|
from .async_channel import AsyncChannel
|
|
4
6
|
from ..exceptions import AutoReconnectException
|
|
@@ -60,7 +62,7 @@ class AsyncConnection:
|
|
|
60
62
|
self.openning = False
|
|
61
63
|
self.reconnecting = False
|
|
62
64
|
self.reconnect_delay = 1
|
|
63
|
-
self.callbacks:
|
|
65
|
+
self.callbacks: deque[Tuple[Callable, Future]] = deque()
|
|
64
66
|
self.type = connection_type
|
|
65
67
|
self.backup: Dict[str, Dict[str, Any]] = {
|
|
66
68
|
"exchange": {},
|
|
@@ -87,6 +89,7 @@ class AsyncConnection:
|
|
|
87
89
|
if not self.ioloop:
|
|
88
90
|
self.ioloop = get_event_loop()
|
|
89
91
|
self.openning = True
|
|
92
|
+
self._closing = False
|
|
90
93
|
self._connection = self.connection_factory.create_connection(
|
|
91
94
|
uri=uri,
|
|
92
95
|
on_connection_open=self.on_connection_open,
|
|
@@ -129,6 +132,37 @@ class AsyncConnection:
|
|
|
129
132
|
signal=self.signal,
|
|
130
133
|
)
|
|
131
134
|
self._channel.publisher_confirms = self.publisher_confirms
|
|
135
|
+
|
|
136
|
+
if self.reconnecting or self.backup["subscribe"] or self.backup["rpc_subscribe"]:
|
|
137
|
+
async def recorvery():
|
|
138
|
+
for routing_key in list(self.backup["subscribe"].keys()):
|
|
139
|
+
params = self.backup["subscribe"][routing_key]
|
|
140
|
+
await self.subscribe(
|
|
141
|
+
params["queue_name"],
|
|
142
|
+
params["exchange_name"],
|
|
143
|
+
routing_key,
|
|
144
|
+
params["callback"],
|
|
145
|
+
params["timeout"],
|
|
146
|
+
content_type=params.get("content_type", "application/json"),
|
|
147
|
+
auto_decode=params.get("auto_decode", True),
|
|
148
|
+
)
|
|
149
|
+
for routing_key in list(self.backup["rpc_subscribe"].keys()):
|
|
150
|
+
params = self.backup["rpc_subscribe"][routing_key]
|
|
151
|
+
await self.rpc_subscribe(
|
|
152
|
+
params["queue_name"],
|
|
153
|
+
params["exchange_name"],
|
|
154
|
+
routing_key,
|
|
155
|
+
params["callback"],
|
|
156
|
+
params["timeout"],
|
|
157
|
+
content_type=params.get("content_type", "application/json"),
|
|
158
|
+
auto_decode=params.get("auto_decode", True),
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
future: Future = Future(loop=self.ioloop)
|
|
162
|
+
self.callbacks.append((recorvery, future))
|
|
163
|
+
self.reconnect_delay = 1
|
|
164
|
+
self.reconnecting = False
|
|
165
|
+
|
|
132
166
|
self._channel.open(self._connection, self.callbacks)
|
|
133
167
|
|
|
134
168
|
def on_connection_open_error(self, _unused_connection, err):
|
|
@@ -193,30 +227,34 @@ class AsyncConnection:
|
|
|
193
227
|
)
|
|
194
228
|
self.reconnect_delay += 1
|
|
195
229
|
else:
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
params["
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
230
|
+
if self.reconnecting:
|
|
231
|
+
async def recorvery():
|
|
232
|
+
for routing_key in list(self.backup["subscribe"].keys()):
|
|
233
|
+
params = self.backup["subscribe"][routing_key]
|
|
234
|
+
await self.subscribe(
|
|
235
|
+
params["queue_name"],
|
|
236
|
+
params["exchange_name"],
|
|
237
|
+
routing_key,
|
|
238
|
+
params["callback"],
|
|
239
|
+
params["timeout"],
|
|
240
|
+
content_type=params.get("content_type", "application/json"),
|
|
241
|
+
auto_decode=params.get("auto_decode", True),
|
|
242
|
+
)
|
|
243
|
+
for routing_key in list(self.backup["rpc_subscribe"].keys()):
|
|
244
|
+
params = self.backup["rpc_subscribe"][routing_key]
|
|
245
|
+
await self.rpc_subscribe(
|
|
246
|
+
params["queue_name"],
|
|
247
|
+
params["exchange_name"],
|
|
248
|
+
routing_key,
|
|
249
|
+
params["callback"],
|
|
250
|
+
params["timeout"],
|
|
251
|
+
content_type=params.get("content_type", "application/json"),
|
|
252
|
+
auto_decode=params.get("auto_decode", True),
|
|
253
|
+
)
|
|
254
|
+
|
|
255
|
+
self.reconnect_delay = 1
|
|
256
|
+
self.reconnecting = False
|
|
257
|
+
self.ioloop.create_task(self.add_callback(recorvery)) # type: ignore
|
|
220
258
|
|
|
221
259
|
@property
|
|
222
260
|
def is_open(self) -> Optional[bool]:
|
|
@@ -356,7 +394,14 @@ class AsyncConnection:
|
|
|
356
394
|
)
|
|
357
395
|
|
|
358
396
|
async def rpc_subscribe(
|
|
359
|
-
self,
|
|
397
|
+
self,
|
|
398
|
+
queue_name,
|
|
399
|
+
exchange_name,
|
|
400
|
+
routing_key,
|
|
401
|
+
callback,
|
|
402
|
+
timeout,
|
|
403
|
+
content_type="application/json",
|
|
404
|
+
auto_decode=True,
|
|
360
405
|
):
|
|
361
406
|
"""
|
|
362
407
|
Registers an RPC handler for a specific routing key.
|
|
@@ -367,24 +412,16 @@ class AsyncConnection:
|
|
|
367
412
|
routing_key: The routing key to subscribe to
|
|
368
413
|
callback: The function to call when a message is received
|
|
369
414
|
timeout: Timeout in seconds for processing the received message
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
>>> async def handle_rpc(body):
|
|
373
|
-
result = process_request(body)
|
|
374
|
-
return json.dumps(result).encode()
|
|
375
|
-
>>> await connection.rpc_subscribe(
|
|
376
|
-
"rpc_queue",
|
|
377
|
-
"rpc_exchange",
|
|
378
|
-
"user.find",
|
|
379
|
-
handle_rpc,
|
|
380
|
-
10.0
|
|
381
|
-
)
|
|
415
|
+
content_type: Content type of expected message
|
|
416
|
+
auto_decode: Whether to auto-decode JSON payload
|
|
382
417
|
"""
|
|
383
418
|
self.backup["rpc_subscribe"][routing_key] = {
|
|
384
419
|
"queue_name": queue_name,
|
|
385
420
|
"exchange_name": exchange_name,
|
|
386
421
|
"callback": callback,
|
|
387
422
|
"timeout": timeout,
|
|
423
|
+
"content_type": content_type,
|
|
424
|
+
"auto_decode": auto_decode,
|
|
388
425
|
}
|
|
389
426
|
await self._channel.rpc_subscribe(
|
|
390
427
|
queue_name=queue_name,
|
|
@@ -392,6 +429,8 @@ class AsyncConnection:
|
|
|
392
429
|
routing_key=routing_key,
|
|
393
430
|
callback=callback,
|
|
394
431
|
timeout=timeout,
|
|
432
|
+
content_type=content_type,
|
|
433
|
+
auto_decode=auto_decode,
|
|
395
434
|
)
|
|
396
435
|
|
|
397
436
|
async def subscribe(
|
|
@@ -401,6 +440,8 @@ class AsyncConnection:
|
|
|
401
440
|
routing_key: str,
|
|
402
441
|
callback: Callable[[Any], Awaitable[None]],
|
|
403
442
|
timeout: Optional[float],
|
|
443
|
+
content_type: str = "application/json",
|
|
444
|
+
auto_decode: bool = True,
|
|
404
445
|
):
|
|
405
446
|
"""
|
|
406
447
|
Subscribes to messages with a specific routing key.
|
|
@@ -411,23 +452,16 @@ class AsyncConnection:
|
|
|
411
452
|
routing_key: The routing key to subscribe to
|
|
412
453
|
callback: The function to call when a message is received
|
|
413
454
|
timeout: Timeout in seconds for processing the received message
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
>>> async def handle_message(body):
|
|
417
|
-
print(f"Received: {body}")
|
|
418
|
-
>>> await connection.subscribe(
|
|
419
|
-
"notifications_queue",
|
|
420
|
-
"notifications",
|
|
421
|
-
"email.send",
|
|
422
|
-
handle_message,
|
|
423
|
-
5.0
|
|
424
|
-
)
|
|
455
|
+
content_type: Content type of expected message
|
|
456
|
+
auto_decode: Whether to auto-decode JSON payload
|
|
425
457
|
"""
|
|
426
458
|
self.backup["subscribe"][routing_key] = {
|
|
427
459
|
"queue_name": queue_name,
|
|
428
460
|
"exchange_name": exchange_name,
|
|
429
461
|
"callback": callback,
|
|
430
462
|
"timeout": timeout,
|
|
463
|
+
"content_type": content_type,
|
|
464
|
+
"auto_decode": auto_decode,
|
|
431
465
|
}
|
|
432
466
|
await self._channel.subscribe(
|
|
433
467
|
exchange_name=exchange_name,
|
|
@@ -435,6 +469,8 @@ class AsyncConnection:
|
|
|
435
469
|
routing_key=routing_key,
|
|
436
470
|
callback=callback,
|
|
437
471
|
timeout=timeout,
|
|
472
|
+
content_type=content_type,
|
|
473
|
+
auto_decode=auto_decode,
|
|
438
474
|
)
|
|
439
475
|
|
|
440
476
|
async def add_callback(
|
|
@@ -464,7 +500,7 @@ class AsyncConnection:
|
|
|
464
500
|
>>> result = await connection.add_callback(my_operation, 10.0)
|
|
465
501
|
"""
|
|
466
502
|
try:
|
|
467
|
-
if self.is_open and self._channel.is_open:
|
|
503
|
+
if self.is_open and self._channel and self._channel.is_open:
|
|
468
504
|
return await callback()
|
|
469
505
|
else:
|
|
470
506
|
future: Future = Future(loop=self.ioloop)
|
|
@@ -212,6 +212,8 @@ class AsyncEventbusRabbitMQ:
|
|
|
212
212
|
handler: Callable[[Any], Awaitable[Union[bytes, str]]],
|
|
213
213
|
timeout: Optional[int] = None,
|
|
214
214
|
connection_timeout: int = 16,
|
|
215
|
+
content_type: str = "application/json",
|
|
216
|
+
auto_decode: bool = True,
|
|
215
217
|
) -> None:
|
|
216
218
|
"""
|
|
217
219
|
Register a provider to listen on RPC request queue
|
|
@@ -221,6 +223,8 @@ class AsyncEventbusRabbitMQ:
|
|
|
221
223
|
handler: message handler, it will be called when a message is received
|
|
222
224
|
timeout: timeout in seconds for waiting for process the received message
|
|
223
225
|
connection_timeout: timeout for waiting for connection restabilishment
|
|
226
|
+
content_type: Content type of expected message
|
|
227
|
+
auto_decode: Whether to auto-decode JSON payload (default True)
|
|
224
228
|
|
|
225
229
|
Raises:
|
|
226
230
|
AutoReconnectException: when cannout reconnect on the gived timeout
|
|
@@ -233,12 +237,18 @@ class AsyncEventbusRabbitMQ:
|
|
|
233
237
|
"""
|
|
234
238
|
|
|
235
239
|
async def add_resource():
|
|
240
|
+
extra_kwargs = {}
|
|
241
|
+
if content_type != "application/json":
|
|
242
|
+
extra_kwargs["content_type"] = content_type
|
|
243
|
+
if not auto_decode:
|
|
244
|
+
extra_kwargs["auto_decode"] = auto_decode
|
|
236
245
|
await self._rpc_server_connection.rpc_subscribe(
|
|
237
246
|
self.config.options.rpc_queue_name,
|
|
238
247
|
self.config.options.rpc_exchange_name,
|
|
239
248
|
name,
|
|
240
249
|
handler,
|
|
241
250
|
timeout,
|
|
251
|
+
**extra_kwargs,
|
|
242
252
|
)
|
|
243
253
|
|
|
244
254
|
if self._rpc_server_connection.open(self.config.url):
|
|
@@ -252,6 +262,8 @@ class AsyncEventbusRabbitMQ:
|
|
|
252
262
|
handler: Callable[[Any], Awaitable[None]],
|
|
253
263
|
timeout: Optional[float] = None,
|
|
254
264
|
connection_timeout: int = 16,
|
|
265
|
+
content_type: str = "application/json",
|
|
266
|
+
auto_decode: bool = True,
|
|
255
267
|
) -> None:
|
|
256
268
|
"""
|
|
257
269
|
Register a provider to listen on queue of bus
|
|
@@ -262,6 +274,8 @@ class AsyncEventbusRabbitMQ:
|
|
|
262
274
|
handler: message handler, it will be called when a message is received
|
|
263
275
|
timeout: timeout in seconds for waiting for process the received message
|
|
264
276
|
connection_timeout: timeout for waiting for connection restabilishment
|
|
277
|
+
content_type: Content type of expected message
|
|
278
|
+
auto_decode: Whether to auto-decode JSON payload (default True)
|
|
265
279
|
|
|
266
280
|
Raises:
|
|
267
281
|
AutoReconnectException: when cannout reconnect on the gived timeout
|
|
@@ -277,12 +291,18 @@ class AsyncEventbusRabbitMQ:
|
|
|
277
291
|
"""
|
|
278
292
|
|
|
279
293
|
async def add_subscribe():
|
|
294
|
+
extra_kwargs = {}
|
|
295
|
+
if content_type != "application/json":
|
|
296
|
+
extra_kwargs["content_type"] = content_type
|
|
297
|
+
if not auto_decode:
|
|
298
|
+
extra_kwargs["auto_decode"] = auto_decode
|
|
280
299
|
await self._sub_connection.subscribe(
|
|
281
300
|
self.config.options.queue_name,
|
|
282
301
|
exchange_name,
|
|
283
302
|
routing_key,
|
|
284
303
|
handler,
|
|
285
304
|
timeout,
|
|
305
|
+
**extra_kwargs,
|
|
286
306
|
)
|
|
287
307
|
|
|
288
308
|
if self._sub_connection.open(self.config.url):
|