Skip to main content

Message Queueing for Redis Streams

Project description

RedisMQ

PyPI version Build Status codecov Documentation Status

Description

RedisMQ uses the redis stream data structure to effect a message queue. The stream key name is the id of the message queue.

It provides support for confirmed and unconfirmed guaranteed message queuing. Guaranteed messages will remain in the queue (as unread or pending messages in the redis stream) until they are read and acknowledged by exactly one consumer. Confirmed producers will get a response only when the message is received and processed by a consumer. Unconfirmed (but guaranteed) still means only a single consumer will process the message, but no response is sent.

RedisMQ also provides support for fan-out (pub/sub) messaging when zero or more subscribers should receive the message.

RedisMQ libraries for Python and Javascript are available.

Requirements

The RedisMQ module requires Python 3.8 or higher.

Prerequisites

Install Python development headers

On Ubuntu/Debian systems or Microsoft Windows:

apt-get install python-dev

On Redhat/Fedora systems, install them with:

yum install python-devel

On Mac OSX:

xcode-select --install

Installation

To install RedisMQ:

$ pip install redismq

or from source:

$ python setup.py install

testing:

pipenv install --dev
pipenv run pytest

debugging:

export REDISMQ=DEBUG
...

Getting Started

RedisMQ needs to connect to an existing redis server, so you will need the address and port of the server you want to use. RedisMQ also stores global state in the redis server. By default the namespace used for global keys is rmq:*. If you need to change this so it does not conflict with other data stored in redis, the configuration parameter redismq_namespace should be set to something different.

Examples

Here are some examples of using the pyredismq module. See more examples here.

Sending an unconfirmed message

From a Python shell we send an unconfirmed message:

>>> import asyncio
>>> from redismq import Client
>>> async def sendAMessage():
...     mq_connection = await Client.connect('redis://127.0.0.1')
...     my_producer = await mq_connection.producer('mystream')
...     print( await my_producer.addUnconfirmedMessage('Hello there!'))
...
>>> asyncio.run(sendAMessage())
"1601460642682-0"

Sending a confirmed message

From a Python shell we send a confirmed message:

>>> import asyncio
>>> from redismq import Client
>>> async def sendAConfirmedMessage():
...     mq_connection = await Client.connect('redis://127.0.0.1')
...     my_producer = await mq_connection.producer('mystream')
...     response = await my_producer.addConfirmedMessage('Hello there! Let me know when you get this.')
...     print('Got confirmation', response)
...
>>> asyncio.run(sendAConfirmedMessage())

Consuming a message

From a Python shell we consume a message:

>>> from redismq import Client
>>> async def readAndConfirmMessage():
>>>     mq_connection = await Client.connect('redis://127.0.0.1')
>>>     my_consumer = await mq_connection.consumer('mystream', 'mygroup', 'consumer1')
>>>     payload = await my_consumer.read()
>>>     print('Got message', payload.message)
>>>     # here you can do something with the message
>>>     # the response passed to ack() is optional, 
>>>     # and ignored if the original message was unconfirmed:
>>>     resp = 'I got your message' if payload.responseChannel else ''
>>>     await payload.ack(resp)

More Information

RedisMQ is free software under the New BSD license, see LICENSE.txt for details.

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

redismq-1.1.7.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

redismq-1.1.7-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file redismq-1.1.7.tar.gz.

File metadata

  • Download URL: redismq-1.1.7.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.3

File hashes

Hashes for redismq-1.1.7.tar.gz
Algorithm Hash digest
SHA256 49730f3126b606fd521fc538bb7f479e020c838d23cf43ab47c4406291df895a
MD5 1c3625cbbdfb57d67a7c315754789e93
BLAKE2b-256 4bb717f5eb371a6bcad57995e38bc1dd2570f50f9aec63e487340b4f61a5fcdb

See more details on using hashes here.

File details

Details for the file redismq-1.1.7-py3-none-any.whl.

File metadata

  • Download URL: redismq-1.1.7-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.3

File hashes

Hashes for redismq-1.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 789a51d2e0c2e29be6a1980eaadad262b55535e875316e6b4a0b4e527f7dd513
MD5 c77c44be39f2d12259cff7d8290b7205
BLAKE2b-256 b596178a5599adf03323581e032fc70a2917ad17b63c5a24bf4dfb3e06db4700

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