Search code examples
serializationakkaigniteakka-persistence

Akka persistance custom TCK plugin , How to support non java serialization for Tagged type?


I am building Akka persistence plugin with Apache ignite , I have a question when it comes to event tagging , if i disable java serialization(allow-java-serialization = no) , Tagged type failed to be serialized properly as i am using Protobuf for events , is there a way to configure specific serialization for Event Tagged wrapper or it need to be handled in the plugin itself? The GitHub for my plugin : https://github.com/Romeh/akka-persistance-ignite

The exception I get is :

[2018-11-21 21:20:48] [orderManagerSystem-akka.actor.default-dispatcher-27] ERROR a.p.i.journal.IgniteWriteJournal - Attempted to serialize message using Java serialization while akka.actor.allow-java-serialization was disabled. Check WARNING logs for more details. akka.serialization.DisabledJavaSerializer$JavaSerializationException: Attempted to serialize message using Java serialization while akka.actor.allow-java-serialization was disabled. Check WARNING logs for more details. [2018-11-21 21:20:48] [orderManagerSystem-akka.actor.default-dispatcher-11] WARN a.s.DisabledJavaSerializer - Outgoing message attempted to use Java Serialization even though akka.actor.allow-java-serialization = off was set! Message type was: [class akka.persistence.journal.Tagged]

I have a sample application where this issue is happening for me where I use Protobuf for events serialization , do I need to do the same for event Tagged type ?

GitHub URL example code : https://github.com/Romeh/spring-boot-akka-event-sourcing-starter/tree/master/spring-event-sourcing-example

In Apache ignite , it is binary serialization .

Thx a lot for your help!


Solution

  • Actually the issue got fixed by checking the msg type if it is Tagged event or not before doing the actual event storing in the journal , something like :

    private JournalItem convert(PersistentRepr p) {
        if (p.payload() instanceof Tagged) {
            Tagged taggedMsg = (Tagged) p.payload();
            PersistentRepr persistentReprWithoutTag = new PersistentImpl(taggedMsg.payload(), p.sequenceNr(), p.persistenceId(), p.manifest(), p.deleted(), p.sender(), p.writerUuid());
            return new JournalItem(persistentReprWithoutTag.sequenceNr(), persistentReprWithoutTag.persistenceId(), serializer.toBinary(persistentReprWithoutTag), JavaConverters.asJavaCollection(taggedMsg.tags()));
        } else {
            return new JournalItem(p.sequenceNr(), p.persistenceId(), serializer.toBinary(p), null);
        }
    

    }