Skip to main content

RabbitMQ client based on the pika library.

Project description

RabbitMQ client based on pika

PyPI version

This repository offers a RabbitMQ client based on pika. Its purpose is to provide an extremely simple API with which to interact with RabbitMQ. The idea is to remove the need for deep knowledge of RabbitMQ in order to use it as a messaging service, allowing more people to leverage its power while avoiding having to invest an inordinate amount of time researching before getting started.

Limitations

For now, this client has been created for a specific purpose, and because of that it really only works well while interacting with other clients of this same repository. For example, the publish/subscribe functionality expects an exchange of type fanout with no additional settings. Should an exchange with the same name as what is being subscribed to already exist, the operation will fail as RabbitMQ spots this difference and throws an error. So, currently this client only works well/at all with other clients of the same type, i.e. other rabbitmq_client clients.

It is the intention to generalize the applicability of this client in the future, but for now it is being engineered to support all use cases of these projects:

Supported types of messaging

Publish/subscribe

Allows for message distribution to whoever is currently listening on a given topic. The publish/subscribe feature does not support confirmed message delivery nor is it intended to, only listening services at the time of publishing will receive the published message.

RPC

Lets a service define a named RPC queue allowing other services to post messages expecting a reply from the RPC server. The solution leverages RabbitMQs direct reply-to functionality as described here: https://www.rabbitmq.com/direct-reply-to.html. Clients need to provide a reply-to property in order for the RPC server to be able to reply. Implementation is based on the examples provided here: https://www.rabbitmq.com/tutorials/tutorial-six-python.html.

Command queues

Queues consumed from by a single service, command queues gives a service a way of exposing an API to other services. Commands can be sent to the named queue and the owning service consumes from it.

Logging

rabbitmq_client uses python logging, to tap into the logging flow you need to provide a Queue object from the multiprocessing module when instantiating the client (the log_queue kwarg). A queue is used since the consumer and producer is run in separate processes, and to streamline handling of logging records, each log record from all processes is put on a single queue. The consumer and producer processes set up QueueHandlers each with log_level set to logging.DEBUG. This means that ALL log records will be put on the multiprocessing.Queue.

An application using the rabbitmq_client that wants to enable logging needs to do the following BEFORE instantiating the rabbitmq_client:

# Configure the logger for the current process, log to a queue handler
logger = logging.getLogger('rabbitmq_client')
logger.setLevel(WANTED_LOGGING_LEVEL)

queue = multiprocessing.Queue()
queue_handler = logging.handlers.QueueHandler(queue)
queue_handler.setLevel(WANTED_LOGGING_LEVEL)

logger.addHandler(queue_handler)

# Create a handler of your choice to log messages, this is where all client
# logging messages will end up
file_handler = logging.FileHandler("rmq_client.log", mode='w')
file_handler.setLevel(WANTED_LOGGING_LEVEL)

# The queue listener is the final handler for all logging messages related to
# the client
listener = logging.handlers.QueueListener(
    queue,
    file_handler,
    respect_handler_level=True
)
listener.start()

# Now declare the client and pass the log queue to it. The client will
# ensure that the consumer and producer processes put all logging messages on
# the supplied queue
client = RMQClient(log_queue=queue)
client.start()

The example above ensures all processes log to the file rmq_client.log, and that the application using rabbitmq_client can determine the log level using the respect_handler_level kwarg.

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-client-1.0.1.tar.gz (22.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rabbitmq_client-1.0.1-py2.py3-none-any.whl (25.4 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: rabbitmq-client-1.0.1.tar.gz
  • Upload date:
  • Size: 22.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.9.0

File hashes

Hashes for rabbitmq-client-1.0.1.tar.gz
Algorithm Hash digest
SHA256 adf02054a5748e6b18dd00419370d5b6831faca1774e8d84e4f8120c6ab956a4
MD5 e90a716958b292a4627f972d19e8cdab
BLAKE2b-256 5cde036cc5db13cc79f83497fbfff7f945ace960dd5cf8cc7ef0b72ea0494aaf

See more details on using hashes here.

File details

Details for the file rabbitmq_client-1.0.1-py2.py3-none-any.whl.

File metadata

  • Download URL: rabbitmq_client-1.0.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 25.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.9.0

File hashes

Hashes for rabbitmq_client-1.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b6919dbff3b1235e4f53f8bb913b567c37fa8fde330697f8abee3073ee5dd585
MD5 339dda2e99f3d55057555be7d784f235
BLAKE2b-256 edc4bb9c42b0f3de5471e2bb6294c273a5545b4bd8a53a88b6cd6039ddaed5e4

See more details on using hashes here.

Supported by

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