本文介绍了微服务架构依赖性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了很多有关微服务架构的内容,但是有一件事我不了解如何实现,希望您能在此方面为我提供帮助...

I have read a lot about microservice architecture but there is one thing that I dont understand how to achieve and hope you can help me with this...

让我们说我有一个web-api-endpoint,它接收OrderMicroservice负责处理的订单.下订单时,必须更新库存,以便OrderMS将事件发布给订阅者(例如使用Nats的发布/订阅),InventoryMS将更新库存,因为它正在订阅当前事件/消息....耦合架构,并使用对特定信息感兴趣的模块/MS的异步调用.

Lets say I have a web-api-endpoint that recieves orders that an OrderMicroservice is responsible to handle. When order is put Inventory must be updated so OrderMS publish an event to subscribers (pub/sub using for example Nats) and InventoryMS will update the inventory due to it is subscribing to current event/message....I want to have a loose coupled architecture and use asynch calls to modules/MSs thats are interested in given info.

如果您有1个InventoryMS实例,给定方案将非常正常,但是如果水平缩放InventoryMS会发生什么情况,即有5个InventoryMS实例,并且所有这些实例都订阅了venture.change.event,并将尝试更新库存吗?

Given scenario will work perfectly fine if you have 1 instance of InventoryMS but what happens if you have scaled the InventoryMS horizontally i.e there are 5 instances of InventoryMS and all of them subscribes to inventory.change.event and will try to update the inventory?

在具有水平调用MS的情况下,我应该使用哪种架构或消息模式,以便当MS相互依赖时我可以拥有松散耦合的架构?一种方式是内部通信是通过使用断路器模式的REST调用进行的,但随后我觉得我建立了具有一定智能的MS的独占(断路器)...

What kind of architecture or message pattern should I use for a scenario like this with horizonatally scalled MS's so I can have a loose coupled architecture when MSs are dependent of each other?One way is that communication internally is made by REST-calls using circuit breaker pattern but then I feel that I build a monolite of MSs with some smartness (the circuit breaker)...

感谢您的帮助!

推荐答案

使用点对点消息传递模型,只有一个消费者会收到消息.在发布/订阅模型中,将通知所有订阅者.
ActiveMQ 的示例.

Use Point to Point messaging model and only one consumer will receive a mesage. In pub/sub model all subscribers will be notified.
Example with ActiveMQ.

这篇关于微服务架构依赖性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 04:08