Greendeck rabbitmq package
Project description
GD-rabbitMQ
Right now this package is only for greendeck's internal use. This will help to publish and consume messages with your rabbitMQ
Install from pip
https://pypi.org/project/greendeck-rabbitmq/
pip install greendeck-rabbitmq
Read details about all default parameters and core functions here in RabbitMQ official website. (https://www.rabbitmq.com)
How to use ?
import the library
import greendeck_rabbitmq
import RabbitMQ class
from greendeck_rabbitmq import RabbitMQ
initialize RabbitMQ client connection
Here default values of some arguments are
- RMQ_PORT=5672
- RMQ_VHOST='/'
- username=Null
- password=Null
from greendeck_rabbitmq import RabbitMQ
# declare variables
RMQ_HOST = <YOUR_RMQ_HOST> # RabbitMQ host address
RMQ_PORT = <YOUR_RMQ_PORT> # RabbitMQ port
RMQ_VHOST = <YOUR_RMQ_VHOST> # RabbitMQ virtual host
username = <YOUR_USERNAME> # RabbitMQ username
password = <YOUR_PASSWORD> # RabbitMQ password
```Here default values are RMQ_PORT=5672, RMQ_VHOST='/', username=Null, password=Null```
rabbitmq_client = RabbitMQ(RMQ_HOST, RMQ_PORT, RMQ_VHOST = RMQ_VHOST, username = username, password = password)
close RabbitMQ client connection
rabbitmq_client.rabbitmq_close_connection()
check size of a rabbitmq queue
queue = "test_library"
print(rabbitmq_client.size(queue))
check if a size of queue is empty or not
queue = "test_library"
print(rabbitmq_client.is_empty(queue))
consume all messages of a queue
queue = "test_library"
rabbitmq_client.rabbitmq_get_all(queue)
single message producer
Here default parameters and their values are:
- exchange=""
- delivery_mode=2
- mode="single"
message = "hello world"
queue = "test_library"
routing_key = "test_library"
exchange = ''
delivery_mode = 2
mode = "single"
```The routing key is a message attribute. The exchange might look at this key when deciding how to route the message to queues (depending on exchange type). ```
``` delivery mode = 1 means non persistent, and delivery mode = 2 means persistent```
```available modes are 'single' & 'multi' and in 'multi' mode it expects message as list of messages
rabbitmq_client.rabbitmq_publisher(message, queue, routing_key, exchange = exchange, delivery_mode = delivery_mode, mode = mode)
rabbitmq_client.rabbitmq_close_connection()
multi messages producer
Here default parameters and their values are:
- exchange=""
- delivery_mode=2
- mode="single"
message = ["hello world"] * 100 #list of messages
queue = "test_library"
routing_key = "test_library"
exchange = ''
delivery_mode = 2
mode = "multi"
rabbitmq_client.rabbitmq_publisher(message, queue, routing_key, exchange = exchange, delivery_mode = delivery_mode, mode = mode)
rabbitmq_client.rabbitmq_close_connection()
messages consumer
Here default parameters and their values are:
- size=1
queue = "test_library"
size = 1 # mention number of required messages
results = rabbitmq_client.rabbitmq_consumer(queue, size)
print("number of messages", len(results))
rabbitmq_consumer.rabbitmq_close_connection()
create an exchange
This will create an exchange and bind the list of queues to the same exchange. Default arguments and their values are:
- exchange_type = "fanout"
- routing_key = ""
exchange = "test_exchange"
queues = ["queue1", "queue2", "queue3"]
exchange_type = "fanout" # for now exchange_type only supports 'fanout'
routing_key = "" # make sure to keep this one same in your project for easy use
```Here default arguments are exchange_type="fanout", routing_key=""```
rabbitmq_client.make_rabbitmq_exchange(exchange, queues, exchange_type=exchange_type, routing_key=routing_key)
produce single message to an exchange
Produce a single message to an exchange
Default arguments and their values are:
- exchange_type = "fanout"
- routing_key = ""
- mode = "single"
exchange = "test_exchange"
message = "hello"
exchange_type = "fanout"
routing_key = ""
mode = "single"
``` Here avilable modes are single or multi . When it is in multi mode it expects type of message field as list```
rabbitmq_client.rabbitmq_exchange_publisher(exchange ,message, exchange_type=exchange_type, routing_key=routing_key,
mode=mode)
produce single message to an exchange
Produce a single message to an exchange
Default arguments and their values are:
- exchange_type = "fanout"
- routing_key = ""
- mode = "single"
exchange = "test_exchange"
message = ["hello1", "hello2", "hello3"]
exchange_type = "fanout"
routing_key = ""
mode = "multi"
``` Here avilable modes are single or multi . When it is in single mode it expects type of message field as a string```
rabbitmq_client.rabbitmq_exchange_publisher(exchange ,message, exchange_type=exchange_type, routing_key=routing_key,
mode=mode)
How to build your pip package
- open an account here https://pypi.org/
In the parent directory
python setup.py sdist bdist_wheeltwine upload dist/*
Update your package
python setup.py sdisttwine upload dist/*
references
- https://medium.com/small-things-about-python/lets-talk-about-python-packaging-6d84b81f1bb5
- https://packaging.python.org/tutorials/packaging-projects/RabbitMQ
Thank You
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
File details
Details for the file greendeck-rabbitmq-1.0.14.tar.gz.
File metadata
- Download URL: greendeck-rabbitmq-1.0.14.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad8354c64bc844504d30ec47d333f7d07945b088dbe707db1e39c428f9a22d46
|
|
| MD5 |
99c96d9072f29c23c9a4a83b959f6691
|
|
| BLAKE2b-256 |
e146b76ba412b685043060015e7f53538c263614019823d91b414e121d861ae6
|