akka.netconsistent-hashing

Can you decide which actors take which keys when using consistent hashing?


I've experimented a little with the Akka .NET consistent hashing router. It seems to me that although you can specify what key to use for the hashing, it is the router who decides how to allocate the keys across actors.

I would have liked to do something like Actor A takes messages of type A, Actor B takes messages of type B, etc. Is this at all possible with the consistent hashing router?


Solution

  • No, it's not possible for existing routers.

    You can subscribe your actors to a particular message types using EventBus (Context.System.EventStream.Subscribe(Self, typeof<MyMessage>);) and publish them by calling system.EventStream.Publish(new MyMessage()); - this way published message will be send to all subscribers. Limitation of that approach is that it works only in the scope of a single ActorSystem.

    For distributed publish/subscribe scenarios you may use Akka.Cluster.Tools plugin, which exposes such option. Remember however that in this case subscription key is string instead of message type.