Skip to main content

GD-rabbitMQ

Right now this package is only for greendeck's internal use. This will help to publish and consume messages with your rabbitMQ

Greendeck 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

In the parent directory

  • python setup.py sdist bdist_wheel
  • twine upload dist/*

Update your package

  • python setup.py sdist
  • twine upload dist/*

references

Thank You

Metadata

Release files for greendeck-rabbitmq 1.0.16

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for greendeck-rabbitmq 1.0.16
File Size Uploaded Provenance Actions
greendeck-rabbitmq-1.0.16.tar.gz 4.9 kB Without provenance Details for greendeck-rabbitmq-1.0.16.tar.gz

Release files / greendeck-rabbitmq-1.0.16.tar.gz

Download URL greendeck-rabbitmq-1.0.16.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
3de288c551353164b71215c8ec5ef591be5340cd8d369f355a4915bcce77516b
BLAKE2b-256 checksum
How to use checksums
4a4c640bacdc600de43fa82bd79a0ccc677a4e2dbe86f2df6cbf0599464d7dd1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.4.2 requests/2.22.0 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.6

Security for greendeck-rabbitmq 1.0.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page