A simple messaging queue
Project description
stiqueue
StiQueue, which stands for "stick queue," is inspired by the simplicity of a stick figure. Just as a stick figure represents simplicity in design, StiQueue is designed to be a simple, lightweight messaging queue system that is both easy to use and flexible.
Code Documentation
For detailed code documentation, visit the StiQueue Documentation.
Guide
SQServer
You can run the SQServer
directly without writing any additional code. The server will handle the messaging queue.
Once the code is downloaded, you can start the server as follows:
python src/stiqueue/sqserver.py --host 0.0.0.0 --port 1234 --debug
It is recommended to use the --debug
flag during the first run to monitor when the server receives a message or
when a message leaves the queue.
Usage
The following are the command-line options for running the server:
usage: StiQueue Server [-h] [--debug] [--host HOST] [--port PORT] [--buff-size BUFF_SIZE]
A message queue server
options:
-h, --help show this help message and exit
--debug Showing debug messages
--host HOST The host address of the server
--port PORT The port to listen on
--buff-size BUFF_SIZE The size of the buffer
--log LOG The log file
SQClient
The SQClient
is intended for use within your code. Once you install the stiqueue
package in your Python project,
you can use the client to send and receive messages from the messaging queue. Ensure that the client's host and port
match those of your SQServer
.
Note that the deq
method is blocking, which can save computation power compared
to the polling method.
Client Code Sample
- Import and initiate the client:
from stiqueue.sqclient import SQClient
c = SQClient()
- Send a message
c.enq("Hello World!")
- Fetch the message
hello_msg = c.deq().decode()
Often, the client that sends the messages is different from the one receiving them. For instance, one client (or app) might send requests, while another client fetches these messages or requests when a resource becomes available. It is also helpful to use a Thread Pool, such as TPool, to manage the number of running threads.
Methods
The following methods are supported by stiqueue
:
enq
: Add a message to the queue (enqueue).deq
: Retrieve a message from the queue (dequeue).cnt
: Get the number of items in the queue.
Examples
Client example
The following is a simple example of how to use the SQClient
to enqueue and dequeue messages from the server:
from stiqueue import SQClient
# Initialize the client
client = SQClient()
# Enqueue messages
client.enq(b"This is message one")
client.enq(b"This is message two")
client.enq(b"This is message three")
# Dequeue and print messages
msg1 = client.deq().decode()
print("msg1:", msg1)
msg2 = client.deq().decode()
print("msg2:", msg2)
msg3 = client.deq().decode()
print("msg3:", msg3)
Note: The decode()
method is used because the deq()
method returns the messages as bytes
,
which need to be decoded to a string for readability.
Extending StiQueue
While StiQueue is designed to be simple and flexible, you might want to extend its functionality for specific use cases. We provide examples of how to extend StiQueue with additional features in the examples directory.
Running Tests
To run the unit tests for StiQueue, use the following command:
python -m unittest discover
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file stiqueue-1.1.4.tar.gz
.
File metadata
- Download URL: stiqueue-1.1.4.tar.gz
- Upload date:
- Size: 18.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0585bd5caa0cc19a2e8b69f0f998f90245c6a10173793b350173352447c0b2a |
|
MD5 | 0da8989c5f765eaa147aefb3a7e836b8 |
|
BLAKE2b-256 | 7666c68cb0609749071daac72396ec61f96d5c9488f1b11d03abb44b93d44a4d |
File details
Details for the file stiqueue-1.1.4-py3-none-any.whl
.
File metadata
- Download URL: stiqueue-1.1.4-py3-none-any.whl
- Upload date:
- Size: 15.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e4e35143c6608640cdf42b717ce08a02950822bfe868ed2cf04d7b2c29d1736 |
|
MD5 | 8e45ecb51599ae7f8ae214d543e18b08 |
|
BLAKE2b-256 | 1c981e400102a3d94f0008e06cee1505f3731592833b1a9f5a4a332448c69b23 |