你可以使用Kafka作为事件存储,但我不建议这样做,尽管它可能看起来是一个不错的选择:
Kafka only guarantees at least once deliver and there are duplicates
in the event store that cannot be removed.
Update:
Here you can read why it is so hard with Kafka and some latest news about how to finally achieve this behavior: https://www.confluent.io/blog/exactly-once-semantics-are-possible-heres-how-apache-kafka-does-it/
Due to immutability, there is no way to manipulate event store when application evolves and events need to be transformed (there are of course methods like upcasting, but...). Once might say you never need to transform events, but that is not correct assumption, there could be situation where you do backup of original, but you upgrade them to latest versions. That is valid requirement in event driven architectures.
No place to persist snapshots of entities/aggregates and replay will become slower and slower. Creating snapshots is must feature for event store from long term perspective.
Given Kafka partitions are distributed and they are hard to manage and
backup compare with databases. Databases are simply simpler :-)
所以,在你做出选择之前,你要三思。事件存储作为应用层接口(监控和管理)的组合,SQL/NoSQL存储和Kafka作为代理是更好的选择,而不是让Kafka处理这两个角色,以创建完整的功能完整的解决方案。
事件存储是一个复杂的服务,如果你认真考虑在事件驱动架构中应用事件源、CQRS、Sagas和其他模式,并保持高性能,那么它需要的服务比Kafka能提供的更多。
欢迎质疑我的答案!你可能不喜欢我说的那些你最喜欢的具有大量重叠功能的代理,但是,Kafka并不是作为事件存储而设计的,而是同时作为高性能的代理和缓冲区来处理快速生产者和缓慢消费者的场景。
请看最终结果。IO微服务开源框架,以发现更多潜在问题:http://eventuate.io/
更新截止2018年2月8日
我没有从评论中加入新的信息,但同意其中一些方面。这次更新更多的是关于微服务事件驱动平台的一些建议。如果你认真考虑微服务的健壮设计和最高性能,我会给你一些你可能会感兴趣的提示。
不要使用Spring——它很棒(我自己也经常使用),但同时又笨重又慢。它根本不是微服务平台。它“只是”一个帮助你实现的框架(这背后有很多工作..)。其他框架“只是”轻量级REST或JPA或不同重点的框架。我推荐可能是同类中最好的开源完整微服务平台,它回归到纯Java的根源:
https://github.com/networknt
如果您想了解性能,可以将自己与现有的基准测试套件进行比较。
https://github.com/networknt/microservices-framework-benchmark
Don't use Kafka at all :-)) It is half joke. I mean while Kafka is great, it is another broker centric system. I think future is in broker-less messaging systems. You might be surprised but there are faster then Kafka systems :-), of course you must get down to lower level. Look at Chronicle.
For Event store I recommend superior Postgresql extension called TimescaleDB, which focuses on high performance timeseries data processing (events are timeseries) in large volume. Of course CQRS, Event sourcing (replay, etc. features) are built in light4j framework out of the box which uses Postgres as low storage.
For messaging try to look at Chronicle Queue, Map, Engine, Network. I mean get rid of this old-fashioned broker centric solutions and go with micro messaging system (embedded one). Chronicle Queue is actually even faster than Kafka. But I agree it is not all in one solution and you need to do some development otherwise you go and buy Enterprise version(paid one). In the end the effort to build from Chronicle your own messaging layer will be paid by removing the burden of maintaining the Kafka cluster.