Repository navigation
Make the messaging transport pluggable (Redis, RabbitMQ, TCP, in-memory) - #7
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Sovik · project thread
What changes
Services now depend only on the abstract
messaging.Brokerinterface. TheBROKER_URLscheme picks which backend is used at start-up:redis://host:6379/0RedisBroker(LPUSH/BRPOP)messaging[redis]amqp://user:pass@host:5672/RabbitMQBroker(durable queue, persistent messages)messaging[rabbitmq](pika)tcp://host:7000TcpBroker→ newapps/tcp-brokerservermemory://InMemoryBroker(tests)register_backend("nats", ...)without changing any service.orders-apiandnotifier-workercode 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
orders-apiandnotifier-workerDockerfiles take a newBROKER_EXTRASbuild arg (default"redis rabbitmq") that decides which client libraries go into the image. With the default, one image works with every broker.compose.yamlnow has one profile per broker (redis,rabbitmq,tcp)..env(default: Redis) andbrokers/{redis,rabbitmq,tcp}.envsetCOMPOSE_PROFILESandBROKER_URL:Tests and CI
MESSAGING_TEST_REDIS_URL/MESSAGING_TEST_AMQP_URLare set.scripts/ci/compose_smoke.sh).Verified locally
ruff,mypy --strictand pre-commit pass.pytest: 81 passed (+20 real-broker cases skipped). With real Redis and RabbitMQ containers, all 71 messaging tests pass.BROKER_EXTRAS=rabbitmqimage leaves out redis and gives a clear error if it's pointed atredis://.Generated by Claude Code