Skip to main content

Message queue backed by a database

Project description

squeal: SQL-Backed Message Queue

A python library implementing a message queue using a relational database as the storage backend.

Note: This is an alpha version. The interface is unstable. Feel free to try it out, though, and let me know what you think.

Why?

squeal offers a lightweight implementation of a message queue, using a backend that you probably already have as part of your infrastructure. The basic functionality is exposed by the squeal.Queue object:

  • create and destroy the required database tables
  • put and get messages from a queue
  • a message payload is just a binary blob
  • messages have a priority, where higher-priority messages are retrieved first
  • consumers can ack or nack messages to indicate success or failure
  • if a consumer acquires a message but doesn't ack it, it will eventually be redelivered to another consumer
  • a message that is nacked will be put back in the queue with an exponential backoff delay
  • a Queue object represents multiple logical queues, indicated by a message topic
  • topics are dynamic: they only exist as long as there's a message with that topic
  • a Queue can query for existing topics or the number of messages waiting in any particular topic

Queue objects delegate to a Backend object that implements database-specific methods. The only backend is currently the MySQLBackend, which wraps a Connection from a mysql library, like pymysql.

What database backends are supported?

Currently, the only backend that has been tested is:

But theoretically other database libraries can be used, as long as they implement PEP 249 (Python Database API Specification). Other database engines can probably be supported with minimal effort by changing the dialect of SQL that's generated. (That is, creating a new subclass of Backend)

Examples

Check the examples/ directory.

API

(Coming soon)

Contributing

To-Do

  • dead letter queue for messages that fail repeatedly
  • raise some better exceptions if we get an expected error from the SQL library (table doesn't exist, etc)
  • do some benchmarking and add indices
  • refactor tests so all backends are compared against the same expectations

Please feel free to submit an issue to the github for bugs, comments, or feature requests. Also feel free to fork and make a PR.

Formatting

Please use black to format your code.

Running tests

Install the dev requirements in a virtual env:

python3 -m venv venv
. venv/bin/activate
pip install -r requirements.txt

The tests assume you have a mysql instance running locally. The connection can be adjusted with envvars, but the defaults are:

SQUEAL_TEST_HOSTNAME = os.environ.get("SQUEAL_TEST_HOSTNAME", "localhost")
SQUEAL_TEST_PORT     = os.environ.get("SQUEAL_TEST_PORT", "3306")
SQUEAL_TEST_USERNAME = os.environ.get("SQUEAL_TEST_USERNAME", "root")
SQUEAL_TEST_PASSWORD = os.environ.get("SQUEAL_TEST_PASSWORD", "password")
SQUEAL_TEST_DATABASE = os.environ.get("SQUEAL_TEST_DATABASE", "test")

The easiest way to get this running is to just use docker:

docker run --name mysql -e MYSQL_ROOT_PASSWORD=password -d -p 3306:3306 mysql:8.1.0

Then the tests can be run with pytest:

pytest tests

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

squeal-0.0.13.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

squeal-0.0.13-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file squeal-0.0.13.tar.gz.

File metadata

  • Download URL: squeal-0.0.13.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.5

File hashes

Hashes for squeal-0.0.13.tar.gz
Algorithm Hash digest
SHA256 151072e2b264a93c06826d79e6357e68b4eb92a042ea6c281c028e1dcfadbab8
MD5 09e8922eda84450c0ad53ae22883335a
BLAKE2b-256 d21bc53b95af5045001ccebbaf46654d937e65e7ea2afc6cb3d23aee23fb1f3d

See more details on using hashes here.

File details

Details for the file squeal-0.0.13-py3-none-any.whl.

File metadata

  • Download URL: squeal-0.0.13-py3-none-any.whl
  • Upload date:
  • Size: 14.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.5

File hashes

Hashes for squeal-0.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 afd96dcec7723c432b3197d0ca20374f304e40cd0de110196ac6e0a522a55cea
MD5 6b715b2e6814ff318976923059a500d9
BLAKE2b-256 c63a2e836bcdd392f52d418da88c5f31598f10b8824e6d9544d23e0b78a42817

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