0

I am working on Akka.net persistence and using MongoDb as the persistent store. One of the properties on the events that we persist is of custom struct type "Rational". We have configured a custom serializer for this Rational type that serializes rational type value into a decimal value. However, we don't see that custom serializer getting invoked at all. The MongoDb shows newly inserted document with rational value of type object instead of decimal.

Below is akka.hocon configuration;

akka {
  actor {
    serializers {
      my-rational = "RationalTypePersistence.RationalSerializer, RationalTypePersistence"
    }
    serialization-bindings {
      "RationalTypePersistence.Rational, RationalTypePersistence" = "my-rational"
    }
  }
}

In debugging session also, the breakpoints set in the custom serializer's "ToBinary" and "fromBinary" methods don't get hit. The breakpoint in the constructor get hits multiple times though.

The custom serializer is extending Akka.Serialization.Serializer, and has overriden Identifier, FromBinary, ToBinary properties/methods.

Are we missing any configuration ?

Suraj Gharat
  • 75
  • 1
  • 6
  • Could you show some of the code from the persistent actor calling the `Persist` method? Maybe it's not saving events that are of the same registered type as this? – Aaronontheweb Jan 20 '20 at 19:18
  • There is an akka configuartion for Mongodb with key name "stored-as". It decides on stored format, I believe. If its value is "binary", then only akka serializer gets invoked. This config is not mandatory and its default value is "Object". When it is "Object", then akka does not apply any serialization from its side, it just passes the object to data store driver which then serializes the passed object as needed. This is the reason I was not seeing my akka serializer getting invoked in "Persist" call. – Suraj Gharat Jan 27 '20 at 06:57
  • I ended up adding BsonSerializer (Because its Mongodb) for my type and it worked. – Suraj Gharat Jan 27 '20 at 07:02

0 Answers0