Issue with Custom DurableStore in Akka Cluster: Deserialization Error for DurableDataEnvelope

Issue with Custom DurableStore in Akka Cluster: Deserialization Error for DurableDataEnvelope

I’m working on a custom DurableStore implementation in Akka Cluster using Java. My goal is to persist Akka’s Distributed Data (ddata) using a custom logic that serializes the data and stores it in a file.

Here’s the relevant configuration I’ve set up:

Akka Configuration:

akka.cluster {
    sharding {
        remember-entities = on
        remember-entities-store = ddata

        distributed-data {
            durable.keys = ["*"]
            durable.store-actor-class=com.zoho.actor.cluster.durable.CustomDurableStore
        }
    }
}

akka.actor {
    serializers {
        proto = "akka.cluster.ddata.protobuf.ReplicatorMessageSerializer"
    }

    serialization-bindings {
        "akka.cluster.ddata.DurableStore$DurableDataEnvelope" = proto
    }
}

Serialization Logic:
I am able to serialize DurableDataEnvelope successfully:

public static byte[] serializeToString(DurableDataEnvelope envelope) throws Exception {
    serializer = serialization.findSerializerFor(envelope);
    // Serialize to byte array
    byte[] serializedBytes = serializer.toBinary(envelope);
    return serializedBytes;
}

Deserialization Logic:
However, when I try to deserialize the data, I encounter the following error:

java.io.NotSerializableException: Unimplemented deserialization of message with manifest [akka.cluster.ddata.DurableStore$DurableDataEnvelope] in [akka.cluster.ddata.protobuf.ReplicatorMessageSerializer]

Here is the code for deserialization:

public static DurableDataEnvelope deserializeFromString(byte[] serializedBytes) throws Exception {
    DurableDataEnvelope ddata = (DurableDataEnvelope) serialization.deserialize(serializedBytes, DurableDataEnvelope.class).get();
    return ddata;
}

I have configured the serializer binding for DurableDataEnvelope as shown above. Despite that, it seems that deserialization is not correctly implemented or there’s something I’m missing.

Question:
What could be causing this deserialization issue, and how can I resolve it? Is there a specific step I’m missing when configuring or handling the deserialization for DurableDataEnvelope?

TIA!


The problem is that the serializer works with string based manifests and not class names.

You can extract the manifest using akka.serialization.Serializers#manifestFor on the serialization side, the serializer id by looking up the serializer for the object akka.serialization.Serialization#findSerializerFor and call identifier on that, store all three values in your file and then use them to call akka.serialization.Serialization#deserialize(byte[], int, String) when deserializing

1 Like

is there any documentation how to do this? any help wiki? @johanandren

I’m afraid not, reading sources of the existing LmdbDurableStore implementation is what is available.

1 Like

That was in Scala but im working in java which is bit confusing. And thank for the help. @johanandren will look into that.

Update: able to serialize and deserialize now.