ES and CQRS not working correctly with Mysql Lagom application
See original GitHub issueLagom Version : 1.4.7 API Scala Version : 2.12.6 Operating System : Ubuntu 16.04 JDK : java version “1.8.0_201” MySQL: Ver 14.14 Distrib 5.7.27
I am facing the same issue as mentioned by @PallaviSingh1992 in this issue. So, I tried adding a readside in Processor and using a builder setEventHandler() to handle multiple events.
Processor
override def buildHandler(): ReadSideProcessor.ReadSideHandler[EsEvent] = readSide .builder
[EsEvent]("EventOffset")
.setGlobalPrepare(globalPrepare) .setEventHandler(handleEventsChanged) .build()
val handleEventsChanged: (Connection, EventStreamElement[EsEvent]) => Unit = { (conn, evt) => evt.event match { case addEvent: UserAdded => processUserAdded(conn, addEvent) case userPasswordUpdatedEvent: UserPasswordUpdated => processSetPassword(userPasswordUpdatedEvent) case userStatusUpdatedEvent: UserStatusUpdated => processUserStatusUpdated(userStatusUpdatedEvent) } }
Expected Behavior
Whatever event is coming to handleEventsChanged(), it should match and execute the particular case.
Actual Behavior
For one event it is working perfectly but when we are using multiple events using pattern matching, it will execute the last event and skips other events above it.
@renatocaval @TimMoore Do you have any suggestion about what we are doing wrong here?
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
Hi @ignasi35, I want to make clear that my comment was in a friendly note 😃
What I meant is that in Java it is not possible a pattern match like in Scala (yes, you can always
if-instanceof-else
). I’m not familiar with the inner working on the Java side of Lagom and for me, what’s happening in the Scala side is expected behavior since it’s how it’s implemented.Now, I see your point framework design wise, I just happen to think a little bit different.
I guess the answer is we chose scala-to-java similarity (since the Java API was developed first) over introducing a difference for scala users where they could only register a single handler implemented with a pattern match.