Reputation: 591
I'm building a project which based on microservices architecture in spring boot.The project was divided multiple modules and I used maven dependency management.
Now I want to use services from one module in other module. I have many spring applications. For example, I have 2 application which is named A and B. I want to use classes from A in B and classes of B in A. In this case I used maven dependencies but it is not completely way to using services in one another because I faced with circular dependency.
What should do to use for solve this problem?
Upvotes: 0
Views: 583
Reputation: 854
If you have classes that need to be in some of your Microservices
, i think it's better to make a shared library
and put your shared classes in that, then use your shared library
in your Microservices
.
Actually i think it's a good idea to put classes that need to be in most of your Microservices
in a shared library
and use that library. But should be careful, because it may comes to tight coupling
which isn't a good thing in Microservices Architecture
.
Personally i think some Configuration
classes and some Event models
that most of your Microservices
use are good candidates. But i don't think sharing your Service
classes between your Microservices
are a good idea. Instead they should use each other's services as they are completely independent and are using external services.
Upvotes: 1
Reputation: 684
create one common entity application and add that entity application as a dependency. For example assume you have stored user data in micorservice1(MC1) and need this class(User) in other microservices(like MC2, MC3,MC4, and so on) then you can create one entity application like util and add this dependency in required microservices.
Upvotes: 0
Reputation: 727
It is not a good idea to share classes between microservices, if you want to replace microservice A, you'll have to adapt Microservice B. Every Service must implement its own data classes which holds the fields which are needed for the service.
MicroService A and MicroService B both can contain a class Foo but this classes can be different by its fields. Perhaps both contain the field 'id' and 'name' but only Microservice A also needs a field 'date' to do his work.
Upvotes: 2