We follow micro-service arch for our application developed using spring-boot. To explain the problem, Lets consider 3 different services A, B, C. Some of the APIs of Service C are also consumed by Service A and B.
I have a DTO for the API in Project C (service C). My question is - for Projects A & B, should I be creating redundant DTO classes to consume the Service C APIs? Or should I be creating a separate jar for DTOs - so that it can be reused across multiple services?
What is the approach you have followed If you had come across similar situation?
I think it depends on some particular usecases.
If the DTO
is a common class that is used in many modules of you project, It should be contained in a common
module.
There is another solution I think that you can treat service C as an API service (like Google Map API for example). So when you provide a service for your clients, you should provide a library for your clients. Therefore, after you develop service C, you can develop a C service library
that contains DTO needed for its clients.
To use API from C service, A and B need to import C service library
and call (new CService()).getSomething()