CLARIFICATION: Notice that this question is different form this one: How to implement a microservice Event Driven architecture with Spring Cloud Stream Kafka and Database per service
This one is about using Kafka as the only repository (of events), no DB needed, The other one is about using a Database (MariaDB) per service + Kafka.
I would like to implement an Event Sourcing architecture to handle distributed transactions:
OrdersService <------------> | Kafka Event Store | <------------>PaymentsService
subscribe/ subscribe/
find find
OrdersService receives an order request and stores the new Order in the broker.
private OrderBusiness orderBusiness;
@PostMapping
public Order createOrder(@RequestBody Order order){
logger.debug("createOrder()");
//do whatever
//Publish the new Order with state = pending
order.setState(PENDING);
try{
orderSource.output().send(MessageBuilder.withPayload(order).build());
}catch(Exception e){
logger.error("{}", e);
}
return order;
}
This is my main doubt: how can I query a Kafka broker? Imagine I want to search for orders by user/date,state, etc.