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_wheel
twine upload dist/*
Update your package
python setup.py sdist
twine 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
Hashes for greendeck-rabbitmq-1.0.13.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | af7bbd2c9540a5395a35be6519aa1c08d0208eceae3dd1eff97911f6fb4da435 |
|
MD5 | bc1b0ef38cf5475e27da6f870f848a9e |
|
BLAKE2b-256 | c3c570024d8d84ea556d90b89b69db25f4bda91614fa0cf8f4b6d69bd960191f |