Event Sourcing(CQRS) and Materialized views with Kafka Streams
GPL-3.0 License
Kafka helps you to build fast, high through put, fault tolerance, scalable microservices and applications. Kafka Streams stores data in Kafka Clusters (Kafka State Stores) and gets data wicket fast.
This repository demonstrates CQRS Event Sourcing (Materialized views) with Kafka Streaming (Version: 2.1.0)
- In typical production environment, we have multiple microservices with dedicated database and we want to perform multiphase commit to each database.
- Let's say if the user wants place an order in eShopping application, we can have different microservices to do the following operations
(a) Check the inventory for the requested product (Inventory MicroService takes care of this)
(b) Check the if any Payment method available and process payment(Payments MicroService takes care of this)
(c) Get Shipping Address and Billing Address (Customer Management MicroService takes care of this)- If anyone of the above microservice fails, we want to roll back the transaction and roll back updates made to microservices
- In this repository you can send customers, orders and greetings(test) events through UI and processed in the listener/receiver then stored in Kafka State Stores, which then accessed through REST API implemented through Jetty Server (Not MicroServices REST API)
KafkaStreamApplication
class. This will bring up producer class.customer
, order
,customer-order
,greetings
,customer-to-ktable-topic
and order-to-ktable
- EventsSender application and Jetty Server run on different ports on the same machine. I used RestTemplate to get data from Kafka Materialized views and show it in HTML pages
Note: For Kafka messaging implementation please look at this repository