Currently we are building a microservice oriented application from our monolith.
The issue we are facing is how to send and receive objects between services while keeping the services independent.
Problem: Say we have an EventService and a NotificationService. The EventService generates an Event, serializes it (json/java?) and publishes the serialized object on an ActiveMQ topic. The NotificationService, which is listening to that specific topic, receives the serialized object and has to deserialize it and therefore needs to know the Event-Class.
What is a good approach to solve the problem of sharing the Event-Class between the two services? Should I introduce a new Project which contains only the Event-Class? The Problem I see here is that this could lead to two scenarios:
Follow this rule of thumb:
For enterprise applications and complex objects, create a 3'rd project (an API project), and share it among your services as a dependency.
For simple and self-descriptive objects, use 'copies' of the same objects in each one of your services; note that this is powerful since the POJOs don't need to be identical;
I just shared sample code here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With