Microservices之间的多微服务互通

huangapple go评论81阅读模式
英文:

Microservices inter communication with multiple Microservices

问题

刚接触微服务,想要亲自实践一下。我知道这可能会很庞大,但还请耐心指导我。有人能否就以下最佳方法给予我指导:

  • 如何从另一个微服务的服务类方法与多个微服务进行交互/通信(我这里有5个微服务)。

  • 如果其中一个微服务宕机了,如何处理?

  • 在这种情况下事务管理是如何工作的?

  • 最后,如何将所有这些响应组合起来,并作为单个ResponseEntity<APIResponse>发送回去。

非常感谢您阅读并回复,烦请为我提供指导。

谢谢...

英文:

New to Microservices, trying to get hands-on it, I know it's going to be a big one but please bear with me. So can anyone please guide me on the best approach on,

  • How to interact / communicate with multiple Microservice (5 in my case) from a service class method of
    another Microservice.

  • What if one of those Microservices is down, how to handle?

  • How does Transaction Management work in this case?

  • and finally, how to combine all those responses and send back as a single ResponseEntity&lt;APIResponse&gt;

Thank You for reaching this for with reading, please guide me on this.

Thank You...

答案1

得分: 1

这是一个非常大的问题。答案可以写成多本书。我会尝试列举一些我想法中的内容,让你了解其中一部分。

  • 微服务之间的通信。
    • 同步方式。通过HTTP请求、RPC方法或SOAP。
    • 异步方式。事件源,比如Kafka、RabbitMQ。数据库共享。
  • 如果其中一个微服务出现故障,应该如何处理?
    • 这是如何处理可用性的问题,大多数情况下,所有微服务都会有多个实例。
    • 基于多个实例,你可以实施一些策略来帮助你控制灾难,比如断路器、重试、限流。
  • 在这种情况下事务管理是如何工作的?
    • 你可以尝试分布式事务框架,但它们通常显得过于复杂。
    • 在设计分布式系统的最常见做法是CAP定理和最终一致性。参考 wiki
  • 如何将所有这些响应合并并作为单个响应发送?
    • 这实际上取决于你如何设计你的API,你总是可以使用API网关方法,在一个服务中处理所有的逻辑到前端。

以上只是关于这个问题的一小部分,你可以阅读一些书籍或在网上搜索详细的解决方案。

英文:

It's a very big question. The answers can write more than one book. I'll try to list something in my idea for you to get a piece of this.

  • Communication between microservices.
    • Sync ways. Through HTTP requests, RPC methods, or SOAP.
    • Async ways. Event sourcing, such as Kafka, RabbitMQ. Database sharing.
  • What if one of those Microservices is down, how to handle?
    • This is how you handle your availability, most of the time all microservices will have more than one instance.
    • Based on multiple instances, you could implement some strategies to help you control disasters, such as Circuit Breaker, Retry, Throttling.
  • How does Transaction Management work in this case?
    • You can try distributed transaction framework, but they often seem to be too complicated.
    • The most common practice in design distributed systems, is CAP and Eventually Consistency. check wiki
  • how to combine all those responses and send back as a single
    • This actually depends on how you design your API, you can always use API Gateway methods, handle all your logic to FE in one service.

Above is very little about the question, you could read some book or google detail solution online.

huangapple
  • 本文由 发表于 2020年5月5日 12:07:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/61605623.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定