How to share entity between REST service between two microservices?

后端 未结 3 1739
被撕碎了的回忆
被撕碎了的回忆 2021-02-14 16:04

I have created two micro-services using java. I need to make a REST api call from service A to service B. The data sent will be in JSON format. Using jax-rs I need to create ent

3条回答
  •  别跟我提以往
    2021-02-14 16:51

    This is common situation where we as developer gets confused. I would suggest to have a common jar(shared) which can be used in both micro services (A and B). It is nothing but sharing a third resource as we use third-party libraries. In my current project we were in the same situation and we found the best approach to have separate shared libraries(api-shared as name) and consuming it as jar in different micro-services.

    In your second approach you ended up with redundant code and also difficult to maintain. Lets say if you have any changes in entity then you have to change in both the entities which is not quite a good way to synchronize the thing.

    All in all I would suggest you to use shared jar for both micro services.

    Regards

    Techno

提交回复
热议问题