简体   繁体   English

两个微服务之间的通信架构

[英]Architecture for communication between two microservices

First of all, I'm using JHipster 4.0.x for my project. 首先,我正在为项目使用JHipster4.0.x。 I'm using microservices architecture. 我正在使用微服务架构。

For this example, I've got one gateway, one microservice for "Store" and a second one for "Skill". 对于此示例,我有一个网关,一个微服务用于“ Store”,第二个微服务用于“ Skill”。 I want to centralise all Stores in one database and Skills in a second one. 我想将所有商店集中在一个数据库中,而技能则集中在另一个数据库中。

Each one is a data repository that will not evolve at the same speed. 每个数据库都是一个不会以相同速度发展的数据库。 On the other hand, they will be the central point of my infrastructure in order to update, via an ESB, the other software. 另一方面,它们将成为我基础结构的中心,以便通过ESB更新其他软件。

Jhipster is great for that, I've got easily my CRUD for each service. Jhipster很好,我很容易为每项服务提供CRUD。

The tricky point is a Store is defined by a Skill. 棘手的一点是商店由技能定义。 The simplest way would be to say that I only do one service with "Skill" and "Store". 最简单的方法是说我只对“技能”和“商店”提供一项服务。 But I can't do that because "Skill" must also be a central point for other data. 但是我不能这样做,因为“技能”也必须是其他数据的中心点。

I imagined this Entity's architecture 我想象这个实体的架构

[SKILL] [技能]

[STORE]----many-to-one----[LINK_WITH_OTHER_ENTITIES] [STORE] ----一对多---- [LINK_WITH_OTHER_ENTITIES]

(with *.json generate by jhipster): (使用* .json由jhipster生成):

  • on Skill Service : 关于技能服务:

    • an entity Skill 实体技能

    { "fluentMethods": true, "relationships": [], "fields": [ { "fieldName": "code", "fieldType": "String" }, { "fieldName": "libelle", "fieldType": "String" } ], "changelogDate": "20161201084915", "dto": "no", "service": "no", "entityTableName": "filiere_metier", "pagination": "no", "microserviceName": "metiers", "searchEngine": "elasticsearch" }

  • on Store Service : 上门服务:

    • an entity Store 实体店

    { "fluentMethods": true, "relationships": [ { "relationshipName": "categorie_metier", "otherEntityName": "pont_msvc", "relationshipType": "many-to-one", "otherEntityField": "id" } ], "fields": [ { "fieldName": "code", "fieldType": "String" }, { "fieldName": "lib", "fieldType": "String" } ], "changelogDate": "20161125141916", "dto": "no", "service": "no", "entityTableName": "store", "pagination": "no", "microserviceName": "store", "searchEngine": "elasticsearch" }

    • an Entity to make a link with Skill 实体与技能链接

    { "fluentMethods": true, "relationships": [], "fields": [ { "fieldName": "idext", "fieldType": "String" }, { "fieldName": "msvcName", "fieldType": "MicroServices", "fieldValues": "gw,metier" }, { "fieldName": "msvcEntityName", "fieldType": "String" } ], "changelogDate": "20161208100401", "dto": "no", "service": "no", "entityTableName": "pont_msvc", "pagination": "no", "microserviceName": "store", "searchEngine": "elasticsearch" }

Then When I'll CRUD on Store I'll use CRUD from Skill too, thanks this article but this point is an another story. 然后,当我在Store上进行CRUD时,我也将使用Skill中的CRUD,感谢本文,但这是另一回事了。

What do you think? 你怎么看? Is this the right way? 这是正确的方法吗?

There is no the right way , as it depends on your needs. 没有正确的方法 ,因为这取决于您的需求。 In your mentioned article (i'm the author, thanks for the complement!), I described the general approach, which has a better work flow described here , which makes it easier to implement but doesn't change the fact, you do more CRUD calls for one request as you increase your service communication chain. 在您提到的文章中(我是作者,谢谢您!),我描述了通用方法,该方法在此处描述了更好的工作流程,这使它更易于实现,但又没有改变事实,您可以做更多随着您增加服务通信链,CRUD要求一个请求。

So, what might be wrong with that? 那么,这可能有什么问题呢? While this is the most consistent approach (you always get the very recent state of the data), you got a lack of availability, as your store service is coupled to the skill service. 尽管这是最一致的方法(您始终会获得最新的数据状态),但是由于存储服务与技能服务耦合,因此缺乏可用性。 If this fails and there is no advanced cache setup (such as with hystrix), you have 2 services failing if skill service crashes. 如果失败,并且没有高级缓存设置(例如使用hystrix),则如果技能服务崩溃,则有2个服务将失败。 Additionally, request will produce a bigger network overhead. 此外,请求将产生更大的网络开销。

Another approach is called event-sourcing, where your skill service informs in a messaging channel about changes of skill entities, so all consuming services can calculate the current state by applying that changelogs. 另一种方法称为事件源,其中您的技能服务在消息传递通道中通知技能实体的更改,因此所有使用服务的服务都可以通过应用更改日志来计算当前状态。 While this leads to less network overhead and guaranteed availability, your data is "eventually consistent". 尽管这将减少网络开销并保证可用性,但您的数据“最终是一致的”。

For this you could take apache kafka (which is also supported by JHipster) and switch to event based entity communication. 为此,您可以使用apache kafka(JHipster也支持)并切换到基于事件的实体通信。 This approach is harder to implement, as there are no pre-built functions as they exist for REST-based and secure communication 这种方法很难实施,因为不存在用于基于REST的安全通信的预构建功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM