Lagom / Akka readside Processor

210 Views Asked by At

I have implemented a readside processor to put the processed events and maintain a read side cassandra table. However found that the event sourcing fails after some time with this error.

[error] a.a.OneForOneStrategy - com.syn.common.akka.message.drive.CItem; local class incompatible: stream classdesc serialVersionUID = -2252861520543301684, local class serialVersionUID = -3725205170570257368
java.io.InvalidClassException: com.syn.common.akka.message.drive.CItem; local class incompatible: stream classdesc serialVersionUID = -2252861520543301684, local class serialVersionUID = -3725205170570257368
    at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:699) ~[na:1.8.0_181]
    at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1885) ~[na:1.8.0_181]
    at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1751) ~[na:1.8.0_181]
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2042) ~[na:1.8.0_181]
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1573) ~[na:1.8.0_181]
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:431) ~[na:1.8.0_181]
    at scala.collection.immutable.List$SerializationProxy.readObject(List.scala:479) ~[scala-library-2.11.8.jar:1.0.4]
    at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source) ~[na:na]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]

The class for CItem has not changed from the beginning... However the readsideProcessor fails to de-serialise the events.. Few events are processed and stored it the table.

case class CItem(q: JsValue, a: JsValue, d: Option[JsValue])

object CItem {
  implicit val format: Format[CItem] = Json.format[CItem]
}


object UDSerializerRegistry extends JsonSerializerRegistry {
  override def serializers: Seq[JsonSerializer[_]] = Seq(
    JsonSerializer[CRecord]
  )
}

And CRecord Contains a list of CItems

1

There are 1 best solutions below

6
On

The error you're seeing arises when there's a binary incompatibility when (de)serializing messages in akka-persistence.

Given that your message uses play-json in its fields (which I strongly do not recommend), it is likely that the version of play-json used in your project was changed and this broke your message class's binary compatibility.

To avoid this, I would refactor your code to not using play-json in your messages' fields. It couples you tightly to a JSON library which is used internally in Lagom, so you might run into shading issues when Lagom is upgraded, or more pragmatically, this binary compatibility issue.

In the case you decide to refactor your events, you can find a guide to event schema migration here.