微服务架构依赖 [英] Microservice Architecture dependency

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

问题描述

我已经阅读了很多关于微服务架构的内容,但有一点我不明白如何实现,希望您能帮我解决这个问题...

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 实例,并且所有这些实例都订阅了inventory.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.

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

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