I have a conceptual doubt. I know the events for a particular entity are processed in sequence on the read-side but I think the processing of the next event does not wait till the previous event is successfully processed and database is updated.
Am I right? If I am, then is there a way to enforce that a event is processed on the read-side only when the previous events are successfully processed and read-side database updated?
Usually Lagom will process one event at a time, per event tag. There should not be a situation where processing of the next event starts before the previous one is committed successfully.
The only exception to this would be if you explicitly perform an asynchronous action inside your event handler. If you do, you'll need to handle this specially to ensure that the processing of the event waits for that action to complete. The specifics depend on which type of read-side you are using.
The Cassandra read-side API expects event handlers to return a CompletionStage<List<BoundStatement>>
. You'll need to ensure that this completion stage only completes after all asynchronous actions invoked by your event processor have completed. The CompletionStage
and CompletableFuture
APIs offer various ways to compose and sequence multiple asynchronous actions.
The JDBC and JPA read-side APIs expect your event handlers to be synchronous and blocking, and execute your code in a dedicated execution context to account for this. If you invoke asynchronous actions from your JDBC/JPA event handler, you should also explicitly block until they complete.