- Batch consumption: process messages in batches, improve consumption efficiency.
- Automatic reconnection: when RabbitMQ service disconnects, amqp-worker will automatically reconnect, ensuring uninterrupted consumption.
- Customizable consumption mode: freely decide to use multi-threading and coroutines in the consumption function.
- Configurable message acknowledgment mode: support automatic acknowledgment and manual acknowledgment modes, configure according to your consumption needs.
- Configurable exception handling: support global configuration of message exception consumption mode, re-enter queue, re-insert, consume message.
## Installation
You can use pip tool to install amqp-worker:
```
```
pip install amqp-worker
pip install amqp-workers
```
```
## 使用方法
## Usage
首先,你需要在你的 Python 代码中引入 amqp_worker 模块:
First, you need to import the amqp_worker module in your Python code:
```python
```python
from amqpworker.app import App
from amqpworker.app import App
```
```
然后,你需要实例化一个 App 对象,而App对象依赖AMQPConnection对象:
Then, you need to instantiate an App object, and the App object depends on the AMQPConnection object:
In the above code we give the consumption function a decorator, giving the consumption queue, the number of consumption per batch, it is worth noting that the parameter type of the consumption function is `List[RabbitMQMessage]`
最后,只需要调用 `run` 方法即可开始消费:
Finally, just call the `run` method to start consuming:
```python
```python
app.run()
app.run()
```
```
## 示例代码
## Example code
下面是一个简单的示例代码,它会消费名为 `test` 的队列中的消息:
Below is a simple example code that will consume messages from a queue named `test`:
```python
```python
from datetime import datetime
from datetime import datetime
@ -84,10 +87,16 @@ app.run()
```
```
## 贡献者
## Contributors
- [@JimZhang](https://git.loom.run/zzl221000)
- [@JimZhang](https://git.loom.run/zzl221000)
## 许可证
## License
amqp-worker uses MIT license. Please refer to LICENSE file for details.