]> git.aero2k.de Git - urlbot-v3.git/commit
Add NATS/JetStream as an alternative broker to RabbitMQ
authorThorsten <mail@aero2k.de>
Sat, 18 Jul 2026 07:16:02 +0000 (09:16 +0200)
committerThorsten <mail@aero2k.de>
Sat, 18 Jul 2026 07:16:02 +0000 (09:16 +0200)
commitb82ee8602c4c262f00d8373e236ac201b0bdf6a8
tree4356e422cae0e03a90372e84e7edc16be2802bba
parented9ab0c7a75ae2b227f26ea3e8346c85779663cd
Add NATS/JetStream as an alternative broker to RabbitMQ

RabbitMQ's Erlang VM baseline costs ~300-500MB RES regardless of actual
traffic, which is wasteful for a small hobby-scale chatbot. Introduces a
runtime toggle (broker_backend = amqp | nats in local_config.ini) so a
deployment can opt into a NATS+JetStream backend instead, while defaulting
to amqp so existing deployments are unaffected.

- New common/broker.py abstraction (SyncBroker/AsyncBroker) with
  broker_amqp.py (thin, behavior-preserving wrapper around the existing
  pika calls) and broker_nats.py backends.
- Binding-key wildcard matching (some patterns, e.g. fun.py's mid-pattern
  "#", have no native NATS subject-algebra equivalent) is handled by
  subscribing broadly and filtering in-process via common/routing.py,
  lifted from the AMQP-routing simulator already used in integration tests.
- action_processing and plugin_registry go through JetStream for
  durability/late-subscriber buffering, matching today's AMQP guarantees.
- Ansible role: broker_backend/nats_uri toggle, optional local NATS server
  provisioning (nats_local), wait-for-broker.sh picked conditionally.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
24 files changed:
deploy/roles/urlbot/defaults/main.yml
deploy/roles/urlbot/handlers/main.yml
deploy/roles/urlbot/tasks/main.yml
deploy/roles/urlbot/tasks/nats_server.yml [new file with mode: 0644]
deploy/roles/urlbot/templates/nats-server.service [new file with mode: 0644]
deploy/roles/urlbot/templates/urlbot-chat.service
deploy/roles/urlbot/templates/urlbot-worker.service
deploy/roles/urlbot/templates/wait-for-nats.sh [new file with mode: 0644]
pyproject.toml
src/distbot/bot/action_worker.py
src/distbot/bot/bot.py
src/distbot/bot/worker.py
src/distbot/common/action.py
src/distbot/common/broker.py [new file with mode: 0644]
src/distbot/common/broker_amqp.py [new file with mode: 0644]
src/distbot/common/broker_nats.py [new file with mode: 0644]
src/distbot/common/config/local_config.ini.spec
src/distbot/common/message.py
src/distbot/common/routing.py [new file with mode: 0644]
src/distbot/minijobber/run.py
src/distbot/plugins/plugin_help.py
tests/test_integration/bot_test_utils.py
tests/test_unit/test_action_worker.py [new file with mode: 0644]
tests/test_unit/test_worker_callback.py [new file with mode: 0644]