为微服务添加依赖
Adding dependencies to microservices
我构建了一些使用大量外部服务的微服务。这些外部服务很少被我构建的 1 个以上的微服务使用。我已经将这些微服务的连接器构建为一个库项目,并将其作为依赖项包含在我所有的微服务项目中。但是我读到微服务的所有逻辑都应该是自包含的,逻辑重复是可以的。如果是这样,是否建议我在每个微服务中定义这些连接器而不是共享库?
...all logic for microservices should be self-contained and
duplication of logic is ok
我认为这是您正在努力解决的问题的核心。这个说法是真的吗?
稍后快速 google 搜索:
http://www.simplicityitself.io/our%20team/2015/01/12/sharing-code-between-microservices.html
本文讨论了这个确切的问题,我们现在可以将其定义为微服务架构中适当的重用级别是多少?
作者列出了开发人员认为需要共享代码的原因,按照耦合度和隔离度从低到高排序:
- Leverage existing technical functionality
- Sharing data schemas, using a class, for example, as an enforcement of a shared schema.
- Sharing data sources, use of the same database by multiple services.
虽然这个列表涵盖了大部分原因,但我要添加另一个共享代码的重要原因,即与快速建立微服务的通用框架有关,通常称为 Microservice Chassis 模式。
作者接着说:
It is of utmost importance to pin down your motivation for wanting to
share code, as unfortunately there is no right answer to this
question. Like everything else, it’s contextual.
综上所述,您是否应该集中连接器?
好吧,这些依赖项在我们的列表中属于什么位置?在您不再使用微服务而是构建单体应用之前,您可以承受多大程度的耦合?
这些问题不容易回答,但希望这能帮助您得出正确的结论。
我构建了一些使用大量外部服务的微服务。这些外部服务很少被我构建的 1 个以上的微服务使用。我已经将这些微服务的连接器构建为一个库项目,并将其作为依赖项包含在我所有的微服务项目中。但是我读到微服务的所有逻辑都应该是自包含的,逻辑重复是可以的。如果是这样,是否建议我在每个微服务中定义这些连接器而不是共享库?
...all logic for microservices should be self-contained and duplication of logic is ok
我认为这是您正在努力解决的问题的核心。这个说法是真的吗?
稍后快速 google 搜索: http://www.simplicityitself.io/our%20team/2015/01/12/sharing-code-between-microservices.html
本文讨论了这个确切的问题,我们现在可以将其定义为微服务架构中适当的重用级别是多少?
作者列出了开发人员认为需要共享代码的原因,按照耦合度和隔离度从低到高排序:
- Leverage existing technical functionality
- Sharing data schemas, using a class, for example, as an enforcement of a shared schema.
- Sharing data sources, use of the same database by multiple services.
虽然这个列表涵盖了大部分原因,但我要添加另一个共享代码的重要原因,即与快速建立微服务的通用框架有关,通常称为 Microservice Chassis 模式。
作者接着说:
It is of utmost importance to pin down your motivation for wanting to share code, as unfortunately there is no right answer to this question. Like everything else, it’s contextual.
综上所述,您是否应该集中连接器?
好吧,这些依赖项在我们的列表中属于什么位置?在您不再使用微服务而是构建单体应用之前,您可以承受多大程度的耦合?
这些问题不容易回答,但希望这能帮助您得出正确的结论。