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)
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) \
.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.56.tar.gz
.
File metadata
- Download URL: hijiki-1.0.56.tar.gz
- Upload date:
- Size: 18.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a81314dfd6b861b78f44956648ab8298cbc29e6541a5ed16ec0b6a904988c433 |
|
MD5 | 8a7de4e73deb9a31abacceb083a9c5d4 |
|
BLAKE2b-256 | c579072175c72d1d6c484520528286fd71796abd5e2bf644f77bce59337a4cf8 |
File details
Details for the file hijiki-1.0.56-py3-none-any.whl
.
File metadata
- Download URL: hijiki-1.0.56-py3-none-any.whl
- Upload date:
- Size: 18.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec6e2aa8eb8c23dbc7552974291dc0e908c8e48e48052d911e2d629072f8ea1a |
|
MD5 | b657b67dfb915378641d46c439c6c8a8 |
|
BLAKE2b-256 | 957e6f4b273ba4db211b15fa02c885c79f554d97f09b0dcb7c21b2b1d22197f7 |