Skip to content

Make the messaging transport pluggable (Redis, RabbitMQ, TCP, in-memory) - #7

Merged
sovikroy merged 1 commit into
mainfrom
claude/project-thread-s9s19k
Nov 4, 2026
Merged

sovikroy merged 1 commit into
mainfrom
claude/project-thread-s9s19k

Conversation

@sovikroy

@sovikroy sovikroy commented Nov 4, 2026

Copy link
Copy Markdown
Owner

Requested by Sovik · project thread

What changes

Services now depend only on the abstract messaging.Broker interface. The BROKER_URL scheme picks which backend is used at start-up:

URL Backend Client library
redis://host:6379/0 RedisBroker (LPUSH/BRPOP) messaging[redis]
amqp://user:pass@host:5672/ RabbitMQBroker (durable queue, persistent messages) messaging[rabbitmq] (pika)
tcp://host:7000 TcpBroker → new apps/tcp-broker server none (stdlib)
memory:// InMemoryBroker (tests) none
  • Backends are imported lazily. You can add more with register_backend("nats", ...) without changing any service.
  • orders-api and notifier-worker code is unchanged apart from comments, with broker: cleanup, and a 1s backoff in the worker loop so it doesn't spin while the broker is down.

Docker and compose

  • The orders-api and notifier-worker Dockerfiles take a new BROKER_EXTRAS build arg (default "redis rabbitmq") that decides which client libraries go into the image. With the default, one image works with every broker.
  • compose.yaml now has one profile per broker (redis, rabbitmq, tcp). .env (default: Redis) and brokers/{redis,rabbitmq,tcp}.env set COMPOSE_PROFILES and BROKER_URL:
    docker compose up --build                                   # Redis
    docker compose --env-file brokers/rabbitmq.env up --build   # RabbitMQ
    docker compose --env-file brokers/tcp.env up --build        # TCP broker

Tests and CI

  • The same contract tests run against every backend: memory, fakeredis and TCP always, plus real Redis and RabbitMQ when MESSAGING_TEST_REDIS_URL / MESSAGING_TEST_AMQP_URL are set.
  • There are also TCP protocol, reconnect and redelivery tests, a RabbitMQ reconnect test, and registry tests.
  • New CI job brokers runs the messaging tests against Redis and RabbitMQ service containers.
  • New CI job compose builds the images and sends an order end to end over each broker (scripts/ci/compose_smoke.sh).
  • The new-service scaffold, README and ARCHITECTURE.md (new class, selection and compose diagrams) are updated.

Verified locally

  • ruff, mypy --strict and pre-commit pass. pytest: 81 passed (+20 real-broker cases skipped). With real Redis and RabbitMQ containers, all 71 messaging tests pass.
  • The compose smoke test passed for redis, rabbitmq and tcp. A BROKER_EXTRAS=rabbitmq image leaves out redis and gives a clear error if it's pointed at redis://.

Generated by Claude Code

Services now depend only on the abstract `messaging.Broker` interface. The
backend is chosen at start-up from the BROKER_URL scheme:

- redis:// and rediss://  -> RedisBroker (messaging[redis] extra)
- amqp:// and amqps://    -> RabbitMQBroker via pika (messaging[rabbitmq] extra)
- tcp://host:port         -> TcpBroker, talking to the new apps/tcp-broker server
- memory://               -> InMemoryBroker, for tests

Backends are imported lazily and can be added with register_backend(). Every
backend runs the same contract tests; real Redis and RabbitMQ join in when
MESSAGING_TEST_REDIS_URL / MESSAGING_TEST_AMQP_URL are set.

Docker and compose:
- orders-api and notifier-worker Dockerfiles take a BROKER_EXTRAS build arg
  (default "redis rabbitmq") that decides which client libraries are baked in.
- compose.yaml has one profile per broker; .env (default Redis) and
  brokers/{redis,rabbitmq,tcp}.env set COMPOSE_PROFILES and BROKER_URL.

CI gains a broker integration job (Redis + RabbitMQ service containers) and an
end-to-end compose job per broker. The new-service scaffold, README and
ARCHITECTURE.md (with new diagrams) are updated to match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SE2PhKYV7M9PYq4fFJu19d
@sovikroy sovikroy self-assigned this Nov 4, 2026
@sovikroy
sovikroy merged commit 7042262 into main Nov 4, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants