Implementing publish/subscribe and event sourcing with Apache Kafka
In the remainder of this chapter, we will not build our own event sourcing system. Previously, we used RabbitMQ to accomplish messaging between our services. However, RabbitMQ only handles message dispatching, so if you need an event log containing all events, you will need to implement it yourself by listening to all events and persisting them. You will also need to take care of event replaying yourself.
Apache Kafka is a distributed message broker that also ships with an integrated transaction log. It was originally built by LinkedIn and is available as an open source product licensed under the Apache License.
In the preceding section, we already built implementations of the EventEmitter
and EventListener
interfaces using an AMQP connection. In this section, we will implement the same interfaces using Kafka.
Kafka quickstart with Docker
Contrary to RabbitMQ, Apache Kafka is a bit more complex to set up. Kafka itself requires...