1

I have discovery service: https://github.com/Naresh-Chaurasia/API-MicroServices-Kafka/tree/master/Microservices-CQRS-SAGA-Kafka/DiscoveryService

I have Product Service: https://github.com/Naresh-Chaurasia/API-MicroServices-Kafka/tree/master/Microservices-CQRS-SAGA-Kafka/ProductsService

I have API gateway: https://github.com/Naresh-Chaurasia/API-MicroServices-Kafka/tree/master/Microservices-CQRS-SAGA-Kafka/ApiGateway

Product Service and API gateway are registered with discovery service. I use API Gateway to access the Product Service.

I am following a course to implement CQRS for products service.

Under ProductService, I have src/main/java/com/appsdeveloperblog/estore/ProductsService/command/ProductAggregate.java

Here the ProductAggregate is Command of CRQS.

It has the following methods (Please refer to GitHub for more details):

@CommandHandler
public ProductAggregate(CreateProductCommand createProductCommand) throws Exception {
...
}

@EventSourcingHandler
public void on(ProductCreatedEvent productCreatedEvent) {
...
}

It also has src/main/java/com/appsdeveloperblog/estore/ProductsService/query/ProductEventsHandler.java, which persist the product in H2 db.

I have also implemented src/main/java/com/appsdeveloperblog/estore/ProductsService/query/ProductsQueryHandler.java, which is used to query the db.

Here the ProductsQueryHandleris Query of CRQS.

enter image description here

My Question is as follows

  1. What i am failing to understand that how and when is the Publish Event generated, and when the message is put in Messaging queue.
  2. Also, is it possible that after the data is persisted to Event Store, it is not stored in Read DB. If yes, then how can we synchronize the Read DB.
Naresh Chaurasia
  • 419
  • 5
  • 21

1 Answers1

2

What i am failing to understand that how and when is the Publish Event generated, and when the message is put in Messaging queue.

It happens after the events are published into the event store.

There are lots of possible designs that you might use to copy events from the event store to the event handler on the query side. These would include

  • Having the application code copy the event onto the message queue, which the event handler subscribes to
  • Having the event handler pull batches of events from the event store on a schedule
  • Having the event handler pull events from the event store, but using the message queue to announce that there are new messages to pull.

is it possible that after the data is persisted to Event Store, it is not stored in Read DB.

Yes. How common that is will depend on... well, really it mostly depends on how much you invest in reliability.

This is why the pull model tends to be popular - the read process can keep track of which events it has seen, and ask for the next batch of messages after X - where X is a time stamp, or a sequence number, or something.

Warning: if you are trying to roll your own event store, getting these details right can be tricky. Unless the details of the event store are part of your competitive advantage, you really want to buy reliability rather than trying to build it.

VoiceOfUnreason
  • 52,766
  • 5
  • 49
  • 91