A simple example demonstrating communication between two microservices using RabbitMQ and MassTransit.
- .NET 8
- RabbitMQ
- MassTransit
- EFCore
- PostgreSQL
We have two microservices:
- Responsible for creating articles and allowing users to like or dislike them.
- Responsible for tracking and storing article interactions (likes and dislikes).
- A user likes or dislikes an article via the Articles API.
- The Articles API sends an event to the RabbitMQ queue.
- The Analytics API consumes the event and updates its database with the new interaction count.
- The Analytics API sends a message back to the Articles API with the updated total interactions.
- The Articles API updates the displayed total like/dislike count for the article.
The goal is to offload the interaction counting process to a separate service, allowing the Articles API to focus on handling article creation and user interactions efficiently. The Analytics API takes on the heavy lifting of counting and storing interactions.
Note: This example is intentionally simplistic and overkill for a real-world scenario. However, it serves as a great way to demonstrate message queues in action. In a real-world system, this approach is more suited for high-traffic services like payment processing or handling technical debt in a microservices architecture.
This project was built as a quick learning exercise (under 1 day). So the example used is supposed to be simple as possible to avoid high business logic complexity, focusing ONLY on the development complexity (Praticing queue messaging implementation).