Python Rabbit wrapper library to simplify to use Exchanges and Queues with decorators
Project description
Hijiki
Python Rabbit wrapper library to simplify to use Exchanges and Queues with decorators
Configurations
Hijiki uses environment variables to configure connection with BROKER.
COMMON
- BROKER_PWD
- BROKER_USERNAME
For single server
- BROKER_PORT
- BROKER_SERVER
For cluster server
- BROKER_CLUSTER_SERVER
if BROKER_CLUSTER_SERVER is present the priority is generate URI using this list of servers, and not use the sever for single server. To user multiples server from cluster is necessary this environment variable has a list of server with port separates with comma.
Ex:
serverA:5672,serverB:5673
generating for uri connection string the value above
amqp://usr:password@server:5672;amqp://usr:password@serverB:5672;
The user and password is the same for all servers.
If server is not present, even BROKER_CLUSTER_SERVER, the connection url will be a default, and to others configs will be changed for "teste".
How to use
Publisher
The example demonstrate how to publish a simple message to topic "teste1_event" with a json message:
pub = Publisher("localhost", "rabbitmq", "rabbitmq", 5672, heartbeat=30)
pub.publish_message('teste1_event', '{"value": "Esta é a mensagem"}')
Consumer
Consumer uses a configuration to define QUEUES and Exchanges and the consumer is a decorator for the queue.
from hijiki.broker.hijiki_rabbit import HijikiQueueExchange, HijikiRabbit
qs = [HijikiQueueExchange('teste1', 'teste1_event'), HijikiQueueExchange('teste2', 'teste2_event')]
gr = HijikiRabbit().with_queues_exchange(qs) \
.with_username("rabbitmq") \
.with_password("rabbitmq") \
.with_host("localhost") \
.with_port(5672) \
.with_heartbeat_interval(30)\
.build()
class MyConsumer():
@gr.task(queue_name='teste1')
def my_consumer(data):
print(f"consumer 1 executed with data : {data}")
@gr.task(queue_name='teste2')
def my_consumer2(data):
print(f"consumer 2 executed with data : {data}")
if __name__ == '__main__':
MyConsumer()
gr.run()
Properties of builder from HijikiRabbit
with_username
Set username of Rabbit Connection
with_password
Set password of Rabbit Connection
with_host
Set host of rabbit when use single node server
with_port
SEt port of rabbit when use single node server
with_cluster_hosts
Set a list of rabbit hosts:port when cluestered server. Example: server-1:5672,server-1:5672,server-1:5672
with_heartbeat_interval
Define heartbeat interval in seconds
with_auto_ack
Define Auto_ack to publish message with autoack
Project details
Release history Release notifications | RSS feed
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 hijiki-1.0.66.tar.gz.
File metadata
- Download URL: hijiki-1.0.66.tar.gz
- Upload date:
- Size: 20.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ffd4d6db4e5131ba58296027f3aba6f7eeb05ca0047377a972ca2d2ebdda238
|
|
| MD5 |
e96b5b8fedde1ad19f16732afc2ac438
|
|
| BLAKE2b-256 |
41b778672efa5831a30300780303c69303fe9ce4156ba336dea22a1ff1bae4f6
|
File details
Details for the file hijiki-1.0.66-py3-none-any.whl.
File metadata
- Download URL: hijiki-1.0.66-py3-none-any.whl
- Upload date:
- Size: 19.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e45ce6420ca998ca575c47117f103cb7d2418a9fe2f0cb5e8942029837bda8ae
|
|
| MD5 |
ff6d14c6a318435f968cc673d0b7304e
|
|
| BLAKE2b-256 |
0eebe1ea02fc60924bae5e27ca48ab68cf4940e4a3e0160ad48df990272a8874
|