编排微服务的标准模式是什么?
如果一个微服务只知道它自己的域,但是有一个数据流要求多个服务以某种方式交互,那么该怎么做呢?
假设我们有这样的东西:
发票
装运
为了便于讨论,让我们假设订单发出后,应该创建发票。
在某个地方,有人按下GUI中的一个按钮,“我完成了,让我们开始吧!”
在经典的整体服务体系结构中,我认为要么有ESB处理这个问题,要么发货服务了解发票服务并直接调用它。
但是,在这个勇敢的微服务新世界中,人们是如何处理这些问题的呢?
我知道这可能被认为是高度基于观点的。但它也有具体的一面,因为微服务不应该做上述事情。
因此,必须有一个“根据定义,它应该做什么”,而不是基于意见。
开枪。
所以你有两个服务:
发票微服务
货运微服务
在现实生活中,你会有一些保持有序状态的东西。我们称它为顺序服务。接下来是订单处理用例,它知道当订单从一种状态转换到另一种状态时该做什么。所有这些服务都包含一组特定的数据,现在您需要其他的东西来进行所有的协调。这可能是:
了解所有服务和实现用例的简单GUI(“我完成了”调用发货服务)
一个等待“I'm done”事件的业务流程引擎。这个引擎实现了用例和流程。
一个编配微服务,比如说订单处理服务本身,它知道你的领域的流程/用例
还有其他我没想过的吗
The main point with this is that the control is external. This is because all your application components are individual building blocks, loosely coupled. If your use cases change, you have to alter one component in one place, which is the orchestration component. If you add a different order flow, you can easily add another orchestrator that does not interfere with the first one. The micro service thinking is not only about scalability and doing fancy REST API's but also about a clear structure, reduced dependencies between components and reuse of common data and functionality that are shared throughout your business.
HTH,马克