akuma8 akuma8 - 2 years ago 82
Java Question

Is it possible to proxy a POJO in microservices application?

I would like to avoid duplicating my POJOs in a microservices application, so I am wondering if there is a way to do that (like proxying)?

I mean, is there a way for a

Service A
to access POJOs (or other classes/interfaces) defined inside a
Service B
without physically creating these POJOs classe files in
Service A

The big big challenge in a microservice architecture is that point and I didn't find a way to solve it.

Answer Source

"Simple": when there are two services that should be using something common - then the answer is move this code into some form of library and have both services depend on it.

Anything else is most likely a bad idea. The whole idea of micro-services is that service A does not in any form depend on B. And you do not want to get into the reflection game and somehow access internals of another service through some sort of backdoor.

As some comment makes clear: using a library helps to avoid code duplication. The alternative is to willfully copy the "common" parts from service B into service A. This is an option, too.

In that sense: you either re-factor the common parts into a library - or you copy them. Both approaches have their pros and cons. You have to determine what matters most in your environment.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download