Skip to main content

Easy utilities for common RabbitMQ tasks

Project description

# easyrabbit

[![Coverage Status](https://coveralls.io/repos/github/scnerd/easyrabbit/badge.svg?branch=master)](https://coveralls.io/github/scnerd/easyrabbit?branch=master)

[![Build Status](https://travis-ci.org/scnerd/easyrabbit.svg?branch=master)](https://travis-ci.org/scnerd/easyrabbit)

Actually easy RabbitMQ utilities for common tasks. Hides the complexities of complete control packages like `pika` by wrapping common use cases in minimalistic wrappers.

# Installation

You can install directly from git using pip:

pip install git+https://github.com/scnerd/easyrabbit

or from PyPi (not yet uploaded):

pip install easyrabbit

# Usage

## Simple routing

### Reader

`RoutingReader` provides a fully asynchronous way to read from an exchange via a queue bound with a routing key. It launches a subprocess to free the calling program from being responsible for its computational overhead; within its own process, it uses `pika`'s asynchronous connection, enabling the highest possible performance client. The API exposed mimics a simple queue, if, after all, what you really want is to use a RabbitMQ queue as if it were a Python queue.

```python
with RoutingReader(url, exchange, queue_name, routing_key) as reader:
for msg in reader:
print("Received the following message: {}".format(msg))
```

If the reader is needed persistently, you can also launch and terminate it yourself:

```python
reader = RoutingReader(url, exchange, queue_name, routing_key)
reader.start()
# Do things with the reader
reader.close()
```

Note that even though the reader is asynchronous, you don't need to wait for it to be ready before using it. All calls hang on the process pipe that sends data from the client process to your parent code. If you want to make sure that the connection is fully established before using it, however, you can use `wait_till_ready`:

```python
reader = RoutingReader(url, exchange, queue_name, routing_key)
reader.start()
try:
reader.wait_till_ready(timeout=5)
except TimeoutError:
raise RuntimeError("RabbitMQ reader took more than 5 seconds to launch")
```

While `reader.get` is blocking, a non-blocking equivalent is `reader.get_nowait`, or your code can explicitly check that a value is available first using `not reader.empty()`. Iterating over `reader` just repeatedly calls `get`, and hence is blocking and will only end when the reader is closed. Use `reader.getall_nowait()` to obtain all values currently in the queue.

All result objects are byte arrays (or strings, in Python 2)

### Writing

The analogous utility for writing is `RoutingWriter`, which provides a nearly identical interface for writing messages to RabbitMQ

```python
with RoutingWriter(url, exchange, routing_key) as writer:
for msg in msgs:
writer.put(msg)
```

`RoutingWriter` exposes much the same API as `RoutingReader`, except of course exposing `put` instead of `get`.

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

easyrabbit-0.0.1.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

easyrabbit-0.0.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file easyrabbit-0.0.1.tar.gz.

File metadata

  • Download URL: easyrabbit-0.0.1.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for easyrabbit-0.0.1.tar.gz
Algorithm Hash digest
SHA256 cbc997c9e16250373b58efe660422b9b02e21ae63643d672caa56e69e54daa58
MD5 bba3ea64006978e95afc48bb2fca1424
BLAKE2b-256 bf3dbe6ea3541b80d0d66d0bb0983658e449446b2fe878d24470b3725ac23606

See more details on using hashes here.

File details

Details for the file easyrabbit-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for easyrabbit-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3ddb66310ad4a16c8c32e21bf1cd7d0217cef9155622774c7a39b034ee7aa324
MD5 f7ab8bebcffe47a8488e66796ab02edd
BLAKE2b-256 136a4c4f828fec59224d2b9f584693845936dd10dc71ecf7fe71248877ae7c37

See more details on using hashes here.

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