Skip to main content

Simple language-agnostic message queues: tools, conventions, examples

Project description

rfq

Simple language-agnostic message queues: tools, conventions, examples

Table of Contents

  1. Overview
  2. Features
  3. Installation
  4. Usage
  5. Example
  6. Development
  7. License

Overview

Implementing a reliable message queue with redis is possible but has to follow certain best practices. The goal of this project is to provide a simple reliable message queue Python library and command line wrapper while following best practices and capturing conventions as code.

The underlying queue design makes it simple to write adapters for other languages, e.g. see rfq.js for a Javascript/Typescript integration.

Context: we've started this project because we needed a simple queue abstraction easily accessible through different languages and abstract away over manually using redis. This project started back when we were running on a single dedicated server, but we are still using it for both local development as well as production.

Features

  • Library and command line wrappers capturing best practices
  • Throughput: https://redis.io/topics/benchmarks
  • Persistence: https://redis.io/topics/persistence
  • Exactly-Once Processing: Messages are delivered once, and stay in the system until clients commit them
  • First-In-First-Out: The order in which messages are sent and received is strictly preserved
  • Payload size: Up to a maximum of 512 MB in message size
  • Total messages: Up to a total of 2^32-1 messages in the system

Installation

We publish rfq to PyPI at https://pypi.org/project/rfq/

Install with poetry

poetry add rfq

Install with pip

pip install rfq

Usage

The command line tool and library can be configured by setting the environment variables

export RFQ_REDIS_HOST=localhost
export RFQ_REDIS_PORT=6397

The library allows you to provide a custom redis instance.

For the command line wrapper, see

$ rfq --help

The command line tool comes with bash completions; install them via

rfq completions bash > /etc/bash_completion.d/rfq.bash-completion

For the Python library see the Queue and Task class in rfq/rfq.py.

Understand

  • There is a "backlog" for published messages not yet consumed
  • There is a "nextlog" for published messages consumed but not yet committed
  • In case commit never happens (e.g. crashes), "harvest" moves messages from "nextlog" back into "backlog"

Example

from rfq.rfq import Queue

# The default queue connects to redis at localhost:6397
# you can pass a custom redis instance or use env vars
# to configure the redis host and port the queue uses
queue = Queue()

# Publishing a message of key-value pairs to a topic
queue.publish("mytopic", {"k": "v"})

# Consuming from a topic returns a task; you must
# only commit the task with .done() once you've
# successfully completed working on it
task = queue.consume("mytopic")
print(task.result())
task.done()

Development

For development

make

make run
$ rfq --help

$ exit
make down

Inside the self-contained reproducible container

flake8 rfq
mypy rfq
pytest

License

Copyright © 2020 robofarm

Distributed under the MIT License (MIT).

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

rfq-1.4.0.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

rfq-1.4.0-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file rfq-1.4.0.tar.gz.

File metadata

  • Download URL: rfq-1.4.0.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.10 CPython/3.8.5 Linux/5.8.0-55-generic

File hashes

Hashes for rfq-1.4.0.tar.gz
Algorithm Hash digest
SHA256 af00cfd0593a9b56059c93bbe92e3d8dc04046e0a7fe729762bac3b371b4b666
MD5 91f4c27997286ca1e8221518564e15b6
BLAKE2b-256 bb64acb6d148367ba3097f63fd6440bbc37f0cac5caa104f25337fd1c5ba1e49

See more details on using hashes here.

File details

Details for the file rfq-1.4.0-py3-none-any.whl.

File metadata

  • Download URL: rfq-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 13.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.10 CPython/3.8.5 Linux/5.8.0-55-generic

File hashes

Hashes for rfq-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fed75a74f488ebebaed9584740d6f725be8b5f2eb620499a5b7322836b48c05e
MD5 61698351431e061c211d4b1289bd982b
BLAKE2b-256 f4718e7cd3323e5eabbd5378cac8a6d5e30f6a09272028df69476806537da967

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