如何处理微服务架构中的共享模型 [英] How to deal with shared models in micro service architectures

查看:253
本文介绍了如何处理微服务架构中的共享模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是创建一个体系结构,其中服务应该能够彼此独立部署并且完全自治,但是当您有两个从数据库读取相同对象类型的服务时,您会怎么做?

My goal is to create an architecture in which services should be able to deploy independent of each other and are completely autonomous, but what do you do when you have 2 services that reads from DB the same object type?

就我而言,我有一个套接字服务器(微服务1)和一个http服务器(微服务2).我的用户使用http服务器创建了一个资产:A,该资产存储在数据库中,并返回mongoID.然后,使用另一个协议和该ID,对套接字服务器的调用需要检查该ID的有效性,因此需要从DB读取.这两个服务将必须共享A的模型才能将其映射到一个对象,但这意味着这两个服务将必须共享代码,这不行.

In my case I have a socket server (micro service 1) and a http server (micro service 2). Using the http server my users creates an asset called: A, this asset gets stored on a DB and a mongoID is returned. Then, using another protocol and the ID, there are calls to the socket server that needs to check that validity of that ID, thus, needs to read from DB. This two services will have to share the model of A in order to map it to an object, but this means the 2 services will have to share code, and that's not ok.

我需要其他服务吗?还是应该只让service1能够从数据库读取,然后让第二个与service 1对话?

Do I need another service? or should I make only service1 able to read from DB and then make the second one talks to service 1?

推荐答案

两个微服务不应共享相同的数据模型.您可以创建一个仅负责管理数据持久性的服务,并可以在其他服务中使用它.

Two microservices should not share same data model. You can create a service which is solely responsible for managing data persistence, and can use it in other services.

这篇关于如何处理微服务架构中的共享模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆