事件来源:我什么时候(不应该)使用Message Queue? [英] Event-sourcing: when (and not) should I use Message Queue?

查看:165
本文介绍了事件来源:我什么时候(不应该)使用Message Queue?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Java和Cassandra的事件源从头开始构建项目. 我的应用程序基于微服务,在某些用例中,信息将异步处理.我想知道消息队列(例如Rabbit,Active MQ Artemis,Kafka等)将发挥什么作用来改善这种环境下的技术堆栈,如果我不使用它,是否理解了这种情况.

I am building a project from scratch using event-sourcing with Java and Cassandra. My apps we be based on microservices and in some use cases information will be processed asynchronously. I was wondering what part a Message Queue (such as Rabbit, Active MQ Artemis, Kafka, etc) would play to improve the technology stack in this environment and if I understand the scenarios if I won't use it.

推荐答案

我将从将RabbitMQ之类的消息传递基础结构与Kafka之类的事件流/存储/处理分离开来.这是为两个(或多个)不同目的而做的两种不同事情.

I would start with separating messaging infrastructure like RabbitMQ from event streaming/storing/processing like Kafka. These are two different things made for two (or more) different purposes.

关于事件来源,您必须有一个必须存储事件的地方.该存储必须是仅追加的,并支持基于身份的非结构化数据的快速读取.这样的持久性的一个示例是 EventStore .

Concerning the event sourcing, you have to have a place where you must store events. This storage must be append-only and support fast reads of unstructured data based on an identity. One example of such persistence is the EventStore.

事件源与CQRS一起使用,这意味着您必须将更改(事件)投影到其他商店,您可以查询该商店.这是通过将事件投影到该存储来完成的,在该存储中将处理事件以更改域对象状态.重要的是要了解使用消息基础结构进行投影通常是一个坏主意.这是由于消息传递和两阶段提交问题的本质造成的.

Event sourcing goes together with CQRS, which means you have to project your changes (event) to another store, which you can query. This is done by projecting events to that store, this is where events get processed to change the domain object state. It is important to understand that using message infrastructure for projections is generally a bad idea. This is due to the nature of messaging and two-phase commit issue.

如果您查看事件如何持续存在,您会发现它们作为一项交易被保存到商店中.如果您随后需要发布事件,则将是另一笔交易.由于您要处理两个不同的基础架构,因此事情可能会崩溃.

If you look at how events get persisted, you can see that they get saved to the store as one transaction. If you then need to publish events, this will be another transaction. Since you are dealing with two different pieces of infrastructure, things can get broken.

这样的消息传递问题是通常保证消息至少一次"传递,并且通常不保证消息的顺序.另外,当您的消息使用者失败并对消息进行NACK时,它将重新发送消息,但通常会在稍后发送,从而再次破坏序列.

The messaging issue as such is that messages are usually guaranteed to be delivered "at least once" and the order of messages is usually not guaranteed. Also, when your message consumer fails and NACKs the message, it will be redelivered but usually a bit later, again breaking the sequence.

无论是谁,都不适用于排序和复制问题,不适用于事件流服务器(如Kafka).另外,如果您使用追赶订阅,EventStore将保证仅按顺序传递一次事件.

The ordering and duplication concerns, whoever, do not apply to event streaming servers like Kafka. Also, the EventStore will guarantee once only event delivery in order if you use catch-up subscription.

以我的经验,消息用于发送命令并实现事件驱动的体系结构,以响应方式连接独立的服务.另一方面,事件存储用于持久化事件,只有到达该事件的事件才被投影到查询存储中,并被发布到消息总线上.

In my experience, messages are used to send commands and to implement event-driven architecture to connect independent services in a reactive way. Event stores, at the other hand, are used to persist events and only events that get there are then projected to the query store and also get published to the message bus.

这篇关于事件来源:我什么时候(不应该)使用Message Queue?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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