本文介绍了是否可以在微服务应用程序中代理POJO?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想避免在微服务应用程序中复制POJO,所以我想知道是否有一种方法(例如代理)?

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)?

我的意思是,Service A是否有一种方法可以访问Service B内部定义的POJO(或其他类/接口),而无需在Service A中物理创建这些POJO类文件?

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.

推荐答案

简单":当有两个服务应该使用 common 时,答案是将这段代码转换为某种形式 library 的服务,并且两种服务都依赖于它.

"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.

其他任何事情很可能是的主意.微服务的整体思想是服务A不会以任何形式依赖于B.并且您想进入反思游戏并以某种方式访问​​其内部通过某种后门提供的另一项服务.

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.

正如一些评论所表明的那样:使用库有助于避免代码重复.另一种选择是故意将服务B中的公用"部分复制到服务A中.这也是一个选择.

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.

这篇关于是否可以在微服务应用程序中代理POJO?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 16:48