How jonashackt/spring-rabbitmq-messaging-microservices works
1. Overall shape
This repo is a multi-module Maven project built around two Spring Boot microservices that communicate asynchronously through RabbitMQ. The core architectural pattern is: one service accepts a request, turns it into a message, RabbitMQ routes it, and the other service consumes it, performs work, then publishes a response message back.
2. Shared library boundary
The weathershare module is a shared Java library, not a runnable service. It contains the cross-cutting contract between services:
- message/event types (EventGetOutlook, EventGeneralOutlook, EventSimple)
- queue names (Queues)
- shared domain model classes (Weather, User, Product, MethodOfPayment, GeneralOutlook)
- utility code (ModelUtil)
This module is the dependency boundary that keeps both services aligned on message schema and shared DTOs.
3. weatherservice as the entry point
weatherservice is the producer-facing microservice. It exposes an HTTP endpoint layer (endpoint/WeatherServiceEndpoint) and has its own messaging package. It receives external requests, converts them into a message, and sends them to RabbitMQ. Its role is to initiate the workflow and later handle the returned result message.
4. weatherbackend as the worker service
weatherbackend is the consumer/processor microservice. It contains:
- service/WeatherBackendService for business orchestration
- businesslogic/IncredibleLogic for the actual computation
- messaging handlers/senders for RabbitMQ integration
- a backend healthcheck component
This service consumes the request message, performs the backend logic, and emits the result message back onto the message bus.
5. Message-driven data flow
The main runtime flow is:
- a request is triggered in weatherservice
- weatherservice publishes an event such as EventGetOutlook to a RabbitMQ queue
- one weatherbackend instance consumes it
- weatherbackend computes the answer
- weatherbackend publishes EventGeneralOutlook
- weatherservice receives the response and logs/uses it
This is the central architecture boundary: HTTP in one direction, AMQP messaging between services.
6. RabbitMQ as the integration hub
RabbitMQ is the only required infrastructure component for service-to-service communication. The repository uses the RabbitMQ management image, and the README shows it exposed on:
- AMQP: 5672
- management UI: 15672
In Docker Compose, the backend service is wired to RabbitMQ through the container hostname rabbitmq, not localhost, which is an important deployment detail.
7. Scalability model
The backend is designed to be horizontally scalable. Multiple weatherbackend containers can run at the same time, all competing for messages from the same queue. This means load distribution is handled by RabbitMQ queue consumption rather than by direct service-to-service calls.
8. Runtime packaging and deployment
Each microservice has its own Dockerfile, and the root repo provides:
- docker-compose.yml for local development
- docker-stack.yml for Swarm deployment
The backend image is built from the Maven-produced JAR in its module. This makes the build pipeline important: the shared library is built first, then backend, then service. The root pom.xml controls that module ordering.
9. Testing strategy
The tests are intentionally integration-heavy and mirror the runtime topology:
- weatherbackend tests use Testcontainers GenericContainer to start only RabbitMQ
- weatherservice tests use DockerComposeContainer to start the real compose setup, including RabbitMQ and the backend service
This shows a clear boundary between isolated service verification and full end-to-end messaging verification.
10. Health and operability
Both services contain dedicated healthcheck classes. These are separate from business logic and are part of the operational surface of the system, likely used for container or orchestrator readiness/liveness probing.
11. Logging and observability
Each service has a logback-spring.xml, and the README describes optional integration with the Elastic stack / Logstash for tracing messages across scaled backend instances. This is not part of the core business flow, but it matters for operating the system when multiple backend replicas are active.
12. Architectural summary for diagramming
A good diagram should show:
- weatherservice on the left as the request initiator
- RabbitMQ in the center as the message broker
- one or more weatherbackend instances on the right as consumers/processors
- weathershare as a shared code/library dependency beneath both services
- optional side boxes for Docker Compose/Swarm, tests, and observability tooling
The dominant architectural style is event-driven microservices with shared contracts and horizontally scalable consumers.
Main entry points: EventGetOutlook.java Shared models · WeatherBackendApplication.java Backend app · WeatherServiceApplication.java Service app · docker-compose.yml Compose
Components 22
Runtime services
Main event-driven application components
- Backend app · Worker service entry point
weatherbackend/src/main/java/de/jonashackt/WeatherBackendApplication.java - Backend svc · Coordinates backend processing
weatherbackend/src/main/java/de/jonashackt/service/WeatherBackendService.java - Logic · Core computation for weather processing
weatherbackend/src/main/java/de/jonashackt/businesslogic/IncredibleLogic.java - Backend msg in · Consumes request events
weatherbackend/src/main/java/de/jonashackt/messaging/MessageHandler.java - Backend msg out · Publishes response events
weatherbackend/src/main/java/de/jonashackt/messaging/MessageSender.java - Backend mq config · RabbitMQ wiring for backend
weatherbackend/src/main/java/de/jonashackt/messaging/MessagingConfiguration.java - Backend health · Operational probe endpoint/component
weatherbackend/src/main/java/de/jonashackt/healtcheck/WeatherBackendHealthcheck.java - Service app · Producer-facing service entry point
weatherservice/src/main/java/de/jonashackt/WeatherServiceApplication.java - HTTP endpoint · Receives external requests
weatherservice/src/main/java/de/jonashackt/endpoint/WeatherServiceEndpoint.java - Service msg out · Turns HTTP requests into request events
weatherservice/src/main/java/de/jonashackt/messaging/MessageSender.java - Service msg in · Receives backend responses
weatherservice/src/main/java/de/jonashackt/messaging/MessageHandler.java - Service mq config · RabbitMQ wiring for service
weatherservice/src/main/java/de/jonashackt/messaging/MessagingConfiguration.java - Service health · Operational probe component
weatherservice/src/main/java/de/jonashackt/healtcheck/WeatherServiceHealthcheck.java
Shared contract
Cross-service message and model types
- Shared models · Events, queues, and DTOs shared by both services
weathershare/src/main/java/de/jonashackt/messaging/EventGetOutlook.java - Model util · Shared helper for model handling
weathershare/src/main/java/de/jonashackt/common/ModelUtil.java
Build and ops
Packaging, deployment, and observability
- Root POM · Multi-module build and module order
pom.xml - Compose · Local RabbitMQ plus service topology
docker-compose.yml - Stack · Swarm deployment definition
docker-stack.yml - Backend tests · RabbitMQ-focused send/receive verification
weatherbackend/src/test/java/de/jonashackt/WeatherBackendSendAndReceiveTest.java - Service tests · Compose-based end-to-end verification
weatherservice/src/test/java/de/jonashackt/WeatherServiceSendAndReceiveTest.java - Backend image · Container packaging for backend service
weatherbackend/Dockerfile - Service image · Container packaging for service
weatherservice/Dockerfile
Connections 28
- Root POM → Shared models: builds first · Shared module is compiled before services
- Root POM → Backend app: builds · Maven builds backend module
- Root POM → Service app: builds · Maven builds service module
- Service app → HTTP endpoint: exposes · HTTP entry point accepts external requests
- HTTP endpoint → Service msg out: creates request · Request is converted into an AMQP message
- Service msg out → Shared models: uses contracts · Shares event and queue types
- Service mq config → Service msg out: configures · Wires messaging behavior
- Service msg in → Shared models: uses contracts · Consumes shared response event types
- Service msg in → HTTP endpoint: returns result · Response is received and used by service side
- Service msg out → Compose: publishes via · Messages go through RabbitMQ in local compose
- Backend app → Backend svc: starts · Application boots backend orchestration
- Backend svc → Logic: delegates · Business work is handled by core logic
- Backend svc → Backend msg in: consumes from · Backend listens for request events
- Backend msg in → Shared models: uses contracts · Request event types come from shared library
- Backend msg in → Logic: invokes · Consumed message triggers computation
- Logic → Backend msg out: produces response · Computed result is sent back to broker
- Backend msg out → Shared models: uses contracts · Response event types come from shared library
- Backend msg out → Compose: publishes via · Backend responds through RabbitMQ
- Backend app → Backend health: exposes · Backend includes operational health surface
- Service app → Service health: exposes · Service includes operational health surface
- Backend image → Backend app: packages · Backend Docker image wraps built application
- Service image → Service app: packages · Service Docker image wraps built application
- Backend tests → Compose: starts broker · Backend tests bootstrap RabbitMQ only
- Service tests → Compose: starts stack · Service tests run against real compose topology
- Compose → Stack: mirrors · Local compose and swarm stack represent same topology
- Service app → Shared models: depends on · Service uses shared message and model types
- Backend app → Shared models: depends on · Backend uses shared message and model types
- Shared models → Model util: includes · Shared library contains common utility support