简体   繁体   English

微服务之间的通信和使用 REST 的内聚

[英]Communication between Microservices and cohesion using REST

This problem has been in my head for a while and I can't seem to understand the logic when I find solutions.这个问题在我的脑海里已经有一段时间了,当我找到解决方案时,我似乎无法理解其中的逻辑。

Heres the deal: I'm currently working on a simple application that has been split up into 2 microservices.交易如下:我目前正在开发一个简单的应用程序,该应用程序已拆分为 2 个微服务。 The application is very similar to the task of managing software Trello.该应用程序与管理软件 Trello 的任务非常相似。 There's a microservice solely used for storing User information (User service) Another microservice is responsible for the Boards (Boards hold lists and lists hold tasks but that's not relevant to my question).有一个微服务仅用于存储用户信息(用户服务)另一个微服务负责董事会(董事会持有列表和列表持有任务,但这与我的问题无关)。 Both microservices use their own database.两个微服务都使用自己的数据库。 All of this will be hosted on AWS, the code is written in Java and I use Hibernate to generate the databases.所有这些都将托管在 AWS 上,代码是用 Java 编写的,我使用 Hibernate 来生成数据库。

My problem: How do I make use of the User service and have a Board be used by multiple User entities?我的问题:如何使用 User 服务并让多个 User 实体使用 Board? I understand the practice of using a many-to-many table which stores the BoardId's together with the UserId's, but what would happen if I were to remove a user that's connected to a board.我了解使用将 BoardId 与 UserId 一起存储的多对多表的做法,但是如果我要删除连接到板的用户会发生什么。 There's no logical connection between the User that's in the user database and the userId that's stored by the board.用户数据库中的 User 和板子存储的 userId 之间没有逻辑连接。 (A user can be signed to multiple boards and vice-versa) (一个用户可以签署多个板,反之亦然)

My questions in short:我的问题简而言之:
How does this look in the database?这在数据库中看起来如何?
How does the Boards service access the User service and save Users to Boards? Boards 服务如何访问User 服务并将Users 保存到Boards?
What happens when I delete a User on the User microservice?当我在 User 微服务上删除一个 User 时会发生什么?

This seems to be a typical Microservice Communication related problem.这似乎是一个典型的微服务通信相关问题。 As per my knowledge and experience, there is a solution ie to introduce a message broker in the architecture which can perform actions on events like say USER_DELETED event can be passed to board microservice which will handle board related db changes.根据我的知识和经验,有一个解决方案,即在体系结构中引入一个消息代理,它可以对诸如 USER_DELETED 事件之类的事件执行操作,可以将其传递给板微服务,该微服务将处理板相关的数据库更改。

Implementing this can feel scary for you at the start, but nowadays it is not that difficult with all the very supportive internet communities helping and coming up with new solutions every day.一开始实施这一点可能会让您感到害怕,但现在所有非常支持的互联网社区每天都在帮助并提出新的解决方案,这并不困难。 If you are using Java for microservices with spring boot, then there are solutions like Apache Kafka, Hazelcast(quite cost effective).如果您在 Spring Boot 中将 Java 用于微服务,那么有一些解决方案,如 Apache Kafka、Hazelcast(相当划算)。 If you are using NodeJS for micorservices, then NATS is one of the libraries which I have used recently.如果你在微服务中使用 NodeJS,那么 NATS 是我最近使用的库之一。

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

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