RabbitMQ
Requirements#
- Docker
- DockerHub Access
- 2 Spring Projects
- Project Gradle
- Language Kotlin
- Spring-Boot Default
- Packaging Jar
- Java e.g. 11
Presets#
RabbitMQ Docker-Container#
1. Save compose to any directory.#
2. Start compose#
3. Verify container up#
Open Docker-Dashboard (Taskbar > Right > Docker-Icon > Right-Click > Dashboard)
OR
Open RabbitMQ UI
You can always check if your messages delivered correctly via RabbitMQ UI
Project Configuration#
1. Add Gradle dependency#
2. Setup Connection#
2. Create config#
- User Service
- Cache Service
Concept#
You have to connect 2 services with each other via Exchange nicos-dev.user-exchange. There'll be 2 Queues nicos-dev.user-service and nicos-dev.cache-service The use-case is that you must synchronize data (users) from User Service to Cache Service
Legend#
Service - Queue - Exchange - Routing-KeyMessage Data (User)#
- JSON User
- User & Cache Service UserDTO
This is the default JSON-Format our User Object:
For serialization & deserialization we need a this UserDTO class. So we can create this object from JSON and vice versa.
Events#
Event names are Routing-Keys
Event - nicos-dev.user.sync-request#
- Flow
- Message Payload
No data
Event - nicos-dev.user.sync-response#
- Flow
- Message Payload
Message contains a list of all users.
Event - nicos-dev.user.created#
- Flow
- Message Payload
Message contains a the created user.
Event - nicos-dev.user.deleted#
- Flow
- Message Payload
Message contains a the ID of the deleted user.
Event - nicos-dev.data.updated#
- Flow
- Message Payload
Message contains a the updated user.
Sender#
Messages are send to a Exchange with a specific Routing-Key, but without defining a specific Queue.
- User Service
- Cache Service
Receiver#
To receive any messages you have to declare bindings. Because Messages are send to nicos-dev.user-exchange you must define which Routing-Keys should be forwarded to your Queue in order to receive any messages.
- User Service
- Cache Service