Skip to main content

Provide easy connection to rabbitmq server.

Project description

rabbitmq-utils

This package will provide easy connection to rabbitmq server.

Producer

Following sample code will allow you to send the message to desire queue.

In RabbitMQProducer class Publisher Confirms is implemented, So it will tell you weather the message is send to desire location or not.

from rabbitmq_utils.producer import RabbitMQProducer
import json

# DEFINING MESSAGE
message = json.dumps({'hello': 'world'})

# SENDING
rmqp = RabbitMQProducer(
    host='localhost', port=5672, virtual_host='/', 
    username='guest', password='guest', 
    exchange='test_exc', exchane_type='topic'
)
is_sent = rmqp.sendMessage(
    message,
    routing_key
)

# RESULT
if is_sent:
    print('INFO: Message sent.')
else:
    print('ERROR: Unable to send on desire routing key.')

Consumer

RabbitMQConsumer class allow you define queue, define exchange and bind queue and exchange using routing key.

Queue and Exchange are consider to be durable. If you are getting some error then remove the existing queue and exchange, before running this code.

Callback function is called when message is received from the rabbitmq server. So define your callback function using following example:

def my_callback_function(ch, method, properties, body):
    # GETTING MESSAGE
    message = body.decode()
    
    # PERFORM YOUR LOGIC HERE
    
    # ACKNOWLEDGE WORK IS DONE
    ch.basic_ack(delivery_tag=method.delivery_tag)
    return None

Following sample code will allow you to receive message from rabbitmq server.

from rabbitmq_utils.consumer import RabbitMQConsumer

# STARTING RABBITMQ CONSUMER
rmqc = RabbitMQConsumer(
        host='localhost', port=5672, virtual_host='/', 
        username='guest', password='guest', exchange='test_exc', 
        queue_name='test_que', routing_key='test_key', exchane_type='topic',
    	my_callback_function
)
rmqc.receiveMessage()

Author

Tahir Rafique

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rabbitmq-utils-1.0.1.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

rabbitmq_utils-1.0.1-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file rabbitmq-utils-1.0.1.tar.gz.

File metadata

  • Download URL: rabbitmq-utils-1.0.1.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for rabbitmq-utils-1.0.1.tar.gz
Algorithm Hash digest
SHA256 a49956f5a2857d2e9f2df838467bc8bd26246cc1ab5aa98717ecbe5966040dd7
MD5 4355a6a809204156925bde0fb1671f8c
BLAKE2b-256 49a088abae60f66b23b386187e40f92dd192ff8b30e1d008f070053f3504b03d

See more details on using hashes here.

Provenance

File details

Details for the file rabbitmq_utils-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for rabbitmq_utils-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2a71a1fa2a41caa8e0696dc8b1b5df2d32281d42bb3e7412db030549c2861b10
MD5 157ba3a129a18283f5d93f34d8067c9a
BLAKE2b-256 9eab0ee56e920735f8d06e73017e1576762d8eb6e960f1b0d11542a9e1614c0a

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page