Search code examples
akka.netakka-remote-actor

Passing large byte[] between actors in Akka.net cluster


I'm new to Akka.net. I have got 2 actors, one is asking for a byte array and the other one getting it from the database and telling that to the sender. If the second actor is in the remote, it's not passing the lengthy array to the sender. If I want to send the byte array as chunks, I can Tell the sender in a loop from the 2nd actor, but I don't know how to make the 1st actor listen to all the chunk messages and aggregate them to a single byte array. Please help me with this.


Solution

  • One way to go about it would be for the first message from the 2nd actor to be something like a PrepareForIncomingData message, when received the first actor transitions into a WaitForDataToComplete state where it only receives specific message types, e.g. IncomingDataChunk and IncomingDataCompleted.

    While in this state any other messages are stashed, once you receive the IncomingDataCompleted message you transition back to a regular state and unstash any stashed messages.

    See the documentation for become/unbecome - http://getakka.net/articles/actors/receive-actor-api.html#becomeunbecome

    Or another option might be Finite State Machine - http://getakka.net/articles/actors/finite-state-machine.html

    Or maybe the data is written to a shared location and the message only contains the path to where the first actor can read the data from.