简体   繁体   English

如何访问我的微服务不拥有的数据?

[英]How do I access data that my microservice does not own?

A have a microservice that needs some data it does not own . A 有一个微服务需要一些它不拥有的数据。 It needs a read-only cache of data that is owned by another service.它需要另一个服务拥有的只读数据缓存。 I am looking for guidence on how to implement this.我正在寻找如何实现这一点的指导。

I dont' want my microserivce to call another microservice.我不希望我的微服务调用另一个微服务。 I have too much data that is used in a join for this to be successful.我在连接中使用了太多数据,无法成功。 In addition, I don't want my service to be dependent on another service (which may be dependent on another...).此外,我不希望我的服务依赖于另一个服务(可能依赖于另一个......)。

Currently, I am publishing an event to a queue.目前,我正在将事件发布到队列。 Then my service subscribes and maintains a copy of the data.然后我的服务订阅并维护数据的副本。 I am haivng problem staying in sync with the source system.我遇到了与源系统保持同步的问题。 Plus, our DBAs are complaining about data duplication.另外,我们的 DBA 抱怨数据重复。 I don't see a lot of informaiton on this topic.我没有看到很多关于这个主题的信息。

Is there a pattern for this?有这种模式吗? What the name?叫什么名字?

First of all, there are couple of ways to share data and two of them you mention.首先,有几种方法可以共享数据,您提到了其中两种。

  1. One service call another service to get the data when it is required.一个服务在需要时调用另一个服务来获取数据。 This is good as you get up to date data and also there is no extra management required on consuming service.这很好,因为您可以获得最新数据,而且消费服务不需要额外的管理。 Problem is that if you are calling this too many times then other service performance may impact.问题是,如果您调用它的次数过多,那么其他服务性能可能会受到影响。

  2. Another solution is maintained local copy of that data in consuming service using Pub/Sub mechanism.另一种解决方案是使用 Pub/Sub 机制在消费服务中维护该数据的本地副本。

    • Depending on your requirement and architecture you can keep this in actual db of consuming service or some type of cache ( persisted cache)根据您的要求和架构,您可以将其保存在使用服务的实际数据库或某种类型的缓存(持久缓存)中
    • Here cons is consistency.这里的缺点是一致性。 When working with distributed architecture you will not get strong consistency but you have to depends on Eventual consistency.使用分布式架构时,您不会获得强一致性,但您必须依赖最终一致性。
  3. Another solution is that and depends on your required you can separate out that tables that needs to join in some separate service.另一种解决方案是,根据您的要求,您可以分离出需要加入某些单独服务的表。 It depends on your use case.这取决于您的用例。

  4. If you still want consistency then at the time when first service call that update the data and then publish.如果您仍然想要一致性,那么在第一次服务调用更新数据然后发布时。 Instead create some mediator component and that will call two service in sync fashion.而是创建一些中介组件,它将以同步方式调用两个服务。 Here things get complicated as you now try to implement transaction over distributed system.当您现在尝试在分布式系统上实现事务时,事情变得复杂了。

One another point, when product build around Microservice architecture then it is not only technical move, as a organization and as a team your team needs to understand something that work in Monolith, it is not same in Microservices.还有一点,当产品围绕微服务架构构建时,它不仅仅是技术上的迁移,作为一个组织和一个团队,你的团队需要了解在 Monolith 中有效的东西,而在微服务中是不一样的。 DBA needs to understand that part and in Microservices Duplication of data across schema ( other aspect like code) prefer over reusability. DBA 需要了解这部分,并且在微服务中跨模式的数据复制(其他方面,如代码)更喜欢可重用性。

Last but not least, If it is always required to call another service to get data, It is worth checking service boundary as well.最后但同样重要的是,如果总是需要调用另一个服务来获取数据,那么检查服务边界也是值得的。 It may possible that sometime service needs to merge as business functionality required to stay together.有时服务可能需要合并为保持在一起所需的业务功能。

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

相关问题 我应该把我的状态机代码放在它自己的微服务中吗? - Should i put my statemachine code in its own microservice? 如果我按最终用户/租户对我的微服务数据进行分片,并且每台服务器都有总数据的一个子集,我如何跨所有服务器查询数据? - If I shard my microservice data by enduser/tenant and each server has a subset of the total data, how do I query for data across all servers? 数据非规范化如何与微服务模式一起工作? - How does data denormalization work with the Microservice Pattern? 我应该如何设计Spring Microservice? - How should I design my Spring Microservice? 在Angular中,如何将组件转换为微服务? - In Angular, how do I convert a component into a microservice? 如何将Java接口迁移到微服务? - how do I migrate a Java interface to a microservice? 微服务依赖架构设计模式 - 我如何实际组织我的依赖关系? - Microservice dependency architecture design pattern - How do I practically organize my dependencies? 如何使.NET Core微服务进行递归健康检查? - How can I make my .NET Core microservice do a recursive health check? AWS ECS:如何通过微服务架构API解决“太多容器”的问题? - AWS ECS: How do I get around “too many containers” with my microservice architecture API? 我需要微服务吗? - Do I need a microservice?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM