[英]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.首先,有几种方法可以共享数据,您提到了其中两种。
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.
问题是,如果您调用它的次数过多,那么其他服务性能可能会受到影响。
Another solution is maintained local copy of that data in consuming service using Pub/Sub mechanism.另一种解决方案是使用 Pub/Sub 机制在消费服务中维护该数据的本地副本。
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.
这取决于您的用例。
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.