khazrak
khazrak

Reputation: 801

How to handle self-created artifacts in micro service architecture when several services depend on it?

I'm testing micro service architecture using Spring Boot and RabbitMQ.

I now have two small services: UserRegistrationService (Registers the user in a db) GetUserInfo (Returns the user from the same db)

I choose to have all the user-specific services use the same db.

Both the services are using the entity "User"(JPA). (This may not be the smartest way of going about)

Is there a smart way of handling this dependency? (two services depend on the same entity) Should I make the entity (user) to a separate project and use a artifact repository?

Upvotes: 2

Views: 257

Answers (2)

Yes, but you should go one step further and decouple the message representation from the database representation. Define an API artifact that contains just plain DTOs for the vocabulary objects in each service API, and implement the message-driven POJOs in reference to these DTOs, using whatever backend objects are relevant. (If you're using Spring Integration, you can just register a Spring converter to map back and forth automatically.)

Upvotes: 2

kamoor
kamoor

Reputation: 2949

Yes. For better reusability and easy maintenance you may need to publish common components as separate jar artifact(s) and refer it as a dependency in each micro services.

A sample project structure can be something like this,

enter image description here

Upvotes: 1

Related Questions