进程内事件系统与使用代理的微服务有什么好的用例?

时间:2017-06-17 23:05:40

标签: java event-handling messaging microservices

我最近看到有不同的框架允许使用消息传递体系结构,但在进程中实现,使用相同和不同的线程。我所知道的是Spring,Guava EventBus和Reactor。

我的问题是有什么好的用例,有人想要使用它们而不是向完全成熟的经纪人发送消息。我知道它的用法允许更好地解耦业务逻辑,但在微服务架构中,您通常会发布要由其他微服务使用的事件。这样做的好处是你可以通过添加一个代理集群来实现容错,其中由实例中的故障引起的错误消息可以由另一个代理重试。通过发送稍后由同一系统使用的消息来实现分解和执行的逻辑,特别是当订阅者在不同的线程中执行时,我似乎很难将数据恢复到一致的状态。

1 个答案:

答案 0 :(得分:0)

Advantages of microservices over in-process is not really in the change it represents for message consumption.

Microservices allow you to execute portion of your code on specific nodes within a cluster, permitting to allocate the heavy calculations on powerful computers and secondary or light resources on less powerful resources. Overall it allows you to balance the performances better and scale your resources on the portions of code that require it.

Also, whenever you update the code of a micro-service you do not impact the other services, so that your changes (and errors) are isolated. If everything runs within the same process any wrong update might actually render the entire solution unusable.

In the end, getting the communication out of your process (3rd party broker) allows you to share it with more people, agents, processes, etc. Otherwise people have to become part of your process (a module?) and this is really not efficient.

Honestly, the only good reason you have for intra-process communication within your monolithic is for speed (in-memory communication rather than on-the-wire communication).