Skip to main content

A dead simple message queue

Project description

Dead Simple Message Queue

What it does

Part mail room, part bulletin board, dsmq is a central location for sharing messages between processes, even when they are running on computers scattered around the world.

Its defining characteristic is bare-bones simplicity.

How to use it

Install

pip install dsmq

Create a dsmq server

As in src/dsmq/example_server.py

from dsmq import dsmq

dsmq.start_server(host="127.0.0.1", port=30008)

Connect a client to a dsmq server

As in src/dsmq/example_put_client.py

mq = dsmq.connect_to_server(host="127.0.0.1", port=12345)

Add a message to a queue

As in src/dsmq/example_put_client.py

topic = "greetings"
msg = "hello world!"
mq.put(topic, msg)

Read a message from a queue

As in src/dsmq/example_get_client.py

topic = "greetings"
msg = mq.get(topic)

Demo

  1. Open 3 separate terminal windows.
  2. In the first, run src/dsmq/dsmq.py.
  3. In the second, run src/dsmq/example_put_client.py.
  4. In the third, run src/dsmq/example_get_client.py.

Alternatively, if you're on Linux just run src/dsmq/demo_linux.py.

How it works

Expected behavior and limitations

  • Many clients can read messages of the same topic. It is a one-to-many publication model.

  • A client will not be able to read any of the messages that were put into a queue before it connected.

  • A client will get the oldest message available on a requested topic. Queues are first-in-first-out.

  • Put and get operations are fairly quick--less than 100 $\mu$s of processing time plus any network latency--so it can comfortably handle requests at rates of hundreds of times per second. But if you have several clients reading and writing at 1 kHz or more, you may overload the queue.

  • The queue is backed by an in-memory SQLite database. If your message volumes get larger than your RAM, you will reach an out-of-memory condition.

API Reference

[source]

start_server(host="127.0.0.1", port=30008)

Kicks off the mesage queue server. This process will be the central exchange for all incoming and outgoing messages.

  • host (str), IP address on which the server will be visible and
  • port (int), port. These will be used by all clients. Non-privileged ports are numbered 1024 and higher.

connect_to_server(host="127.0.0.1", port=30008)

Connects to an existing message queue server.

  • host (str), IP address of the server.
  • port (int), port on which the server is listening.
  • returns a DSMQClientSideConnection object.

DSMQClientSideConnection class

This is a convenience wrapper, to make the get() and put() functions easy to write and remember.

put(topic, msg)

Puts msg into the queue named topic. If the queue doesn't exist yet, it is created.

  • msg (str), the content of the message.
  • topic (str), name of the message queue in which to put this message.

get(topic)

Get the oldest eligible message from the queue named topic. The client is only elgibile to receive messages that were added after it connected to the server.

  • topic (str)
  • returns str, the content of the message. If there was no eligble message in the topic, or the topic doesn't yet exist, returns "".

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

dsmq-0.3.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

dsmq-0.3.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file dsmq-0.3.0.tar.gz.

File metadata

  • Download URL: dsmq-0.3.0.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.4.17

File hashes

Hashes for dsmq-0.3.0.tar.gz
Algorithm Hash digest
SHA256 8d6296f0d8cedca17a3482b32d1cddea02e916b8de3bac0cbd4aa40b4cc9e744
MD5 a6171e3f16e91c3a3ee3f7828db2cfde
BLAKE2b-256 83533b6138ad07e415d5818d04e5db091bbfe01d27e371cf316d28f8a0855d03

See more details on using hashes here.

File details

Details for the file dsmq-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: dsmq-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.4.17

File hashes

Hashes for dsmq-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a1473b1e5a0b68782ae34468590485c9eca833db901ef8d1fb713d4c45e51cd5
MD5 6c1ffa8b3003228eae11d7777dcd8b46
BLAKE2b-256 73475f5b189133226effc344495ad02854dc2a06768278d3b774d1c495cbf771

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