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
from nats_worker import 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()
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.8.tar.gz
(9.0 kB
view details)
Built Distribution
File details
Details for the file nats-py-worker-0.0.8.tar.gz
.
File metadata
- Download URL: nats-py-worker-0.0.8.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd729544d10cea882b4598ab7727a6f6484358772bad650d2c881c076a1c8971 |
|
MD5 | 071ff515892013b73e69efa2113ba6f2 |
|
BLAKE2b-256 | abb42d072637a4ce67f29c569f3b5ad232a8de15a4d364fdc1b5ef01956464ed |
File details
Details for the file nats_py_worker-0.0.8-py3-none-any.whl
.
File metadata
- Download URL: nats_py_worker-0.0.8-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 | 557ea923da535779117270aff31ce08e3db8b2be58bf11972bff8e67ec1f414f |
|
MD5 | 72718b828a6ec63f883b3d5a48cf37d4 |
|
BLAKE2b-256 | cb25017bd4e8c1f951060f88eec3c73eb96597d14319e6ec1f4a166551c70d07 |