Simple RabbitMQ consumer starter for Python
Project description
一、消费者示例
import logging
import sys
import os
# 添加项目根目录到Python路径
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
from src.config import MQConfig
from src.decorator import mq_listener
from src.starter import MQStarter
logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s')
@mq_listener("order_queue")
def handle_order(data):
raise Exception("handle_order_delay")
# logging.info("process order_queue1:", data)
@mq_listener("order_queue_delay")
def handle_order_delay(data):
logging.info(f"process order_queue_delay:{data}")
config = MQConfig(
host="192.168.0.177",
username="admin",
password="LdeZYqzS809VbQfV",
redis_url=None
)
starter = MQStarter(config)
starter.start()
二、生产者示例
import sys
import os
# 添加项目根目录到Python路径
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
from rabbitmq_starter.config import MQConfig
from rabbitmq_starter.connection import MQConnection
from rabbitmq_starter.producer import MQProducer
config = MQConfig(
host="192.168.0.177",
username="admin",
password="LdeZYqzS809VbQfV"
)
conn = MQConnection(config)
producer = MQProducer(conn, config)
producer.send(
"order_queue",
{"order_id": 1}
)
producer.send_delay(
"order_queue_delay",
{"order_id": 1},
2000
)
producer.send_delay(
"order_queue_delay",
{"order_id": 2},
6000
)
producer.send_delay(
"order_queue_delay",
{"order_id": 3},
10000
)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rabbitmq_starter-0.1.7.tar.gz.
File metadata
- Download URL: rabbitmq_starter-0.1.7.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
efc26cd4ffb8803f4b0d153e8f1314592357b21d2fd149a96186b5c66b623f4f
|
|
| MD5 |
9c2c365dc764c611125d543a8e3ce3ed
|
|
| BLAKE2b-256 |
99109fed5bc8ba2a32e8c90a4f9763fcfa400026927deeebd45d7af45e118ce8
|
File details
Details for the file rabbitmq_starter-0.1.7-py3-none-any.whl.
File metadata
- Download URL: rabbitmq_starter-0.1.7-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74871fe1dcb3d8e75621d56802e66bd138ce4552cc5e4076b5133949ad28992c
|
|
| MD5 |
2344efe13f585bb4bc7895d295a154c6
|
|
| BLAKE2b-256 |
f85b2d98d9a8a5eb7d3b789808e20d12aa1eaf5bd59e584bfd27afbe0a2ff911
|