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()
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
File details
Details for the file hijiki-1.0.61.tar.gz
.
File metadata
- Download URL: hijiki-1.0.61.tar.gz
- Upload date:
- Size: 19.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2475d9bdf9e12308e3c714089dae1c3745aa74ac3e736c89241fc679281a263a |
|
MD5 | 14617324b731ae4a8b2eb6dba32931c0 |
|
BLAKE2b-256 | 80eee7c051a4e5ca5fecfead5d2a56c808795006627701812cf25f6813f0bd2f |
File details
Details for the file hijiki-1.0.61-py3-none-any.whl
.
File metadata
- Download URL: hijiki-1.0.61-py3-none-any.whl
- Upload date:
- Size: 19.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ad43b0844bdbd7a35714261903db3642f73db9d202e363642ed4a895ce6e5d8 |
|
MD5 | 9c0ac744f353506aa126d5e1921ddbc2 |
|
BLAKE2b-256 | 022c94f612cd2e7282d2ea0b64b104473e3e627faa3a6a9c1f8e7c2ef9049658 |