An opinionated utility for using NATS as a worker queue with NATS.py
Project description
NATS Worker
An opinionated utility for using NATS as a worker queue with NATS.py.
Example
# pip install nats-py-worker
import nats_worker
from nats.js.api import StreamConfig, KeyValueConfig
worker = Worker(name="demo")
async def init_nats(connection):
connection.jetstream().add_stream(new StreamConfig(name="events", subjects=["inbox.*", "outbox.*"]))
connection.jetstream().create_key_value(config=KeyValueConfig(bucket="state"))
@worker.background_consumer(subject="inbox.*")
async def watch_incoming(msg):
...
@worker.background_state_machine(subject="inbox.*", bucket="state")
async def next_state(kv, msg):
...
await worker.publish_msg(subject=outbox, payload=side_effect)
...
return new_state
if __name__ == '__main__':
worker.start_as_app()
Supported platforms
Should be compatible with at least Python +3.7.
Installing
pip install nats-py-worker
Development
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
The gitlab-ci.yml is currently setup to push to PyPi when merged to main. Make sure you have updated the version other wise it will fail.
License
Unless otherwise noted, the NATS Worker source files are distributed under the MIT license found in the LICENSE file.
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
nats-py-worker-0.0.1.tar.gz
(7.9 kB
view details)
Built Distribution
File details
Details for the file nats-py-worker-0.0.1.tar.gz
.
File metadata
- Download URL: nats-py-worker-0.0.1.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 696588656e65295c5f9e8322836f1cbccd1055c84d28e1eadfb1e8d5d288205b |
|
MD5 | 2474966c58c1ae6cf520a95eb99c7e05 |
|
BLAKE2b-256 | 3b8d5c9044f78a303488c3a03b9b8b542558779deb8764e7aef2e7d52d04306f |
File details
Details for the file nats_py_worker-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: nats_py_worker-0.0.1-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4543bc216e846bf00eb4ecaa755210234325e9b1338dc950080ee419f7c6eb61 |
|
MD5 | 45c449309ae34159a8a3a5c2d12f4b36 |
|
BLAKE2b-256 | a9eef94fa9db5f19de6c44cf9f1b9bb7aa323f78792c3dd83c8d509db988fb3a |