Message based router

Hi,
I went through routing in akka cluster.

There are few akka routers available which are,

RoundRobinRoutingLogic
RandomRoutingLogic
SmallestMailboxRoutingLogic
BroadcastRoutingLogic
ScatterGatherFirstCompletedRoutingLogic
TailChoppingRoutingLogic
ConsistentHashingRoutingLogic

Do we have any message based router group ?

consider the below case

akka.actor.deployment {
/masterActor/remoteGroup {
router = round-robin-group
routees.paths = [
“akka.tcp://ClusterSystem@127.0.0.1:3000/user/masterActor/w1”, # machine 1
“akka.tcp://ClusterSystem@127.0.0.75:3000/user/masterActor/w1”, # machine 2
“akka.tcp://ClusterSystem@127.0.28.132:3000/user/masterActor/w1”] # machine 3
}
}

Say if my message is “Type 1” then route the message to machine1 if it is “Type 2” then route it to machine 2 else machine 3

Do we have any router available in akka to satisfy the above case. If not can you please advice me to write a custom router to satisfy the above case.

Hi @anilkumble

If you already know the types of messages that you will receive then you can use Akka Cluster Roles They fit the use case better.

An alternative approach would be to use Akka Streams and use groupBy operator to route messages to a different substream based on type.

Thank you so much @hungai
I’ll go through Akka Cluster Roles and Streams

Hi @hungai

I have one more doubt. Below I am using round-robin-group to route the message. Unfortunately my node (127.0.0.57:3000) got disconnected from the cluster.
What will happen in these scenarios. Whether the message will drop itself?

If so how to handle these cases

akka.actor.deployment {
/masterActor/remoteGroup {
router = round-robin-group
routees.paths = [
“akka.tcp://ClusterSystem@127.0.0.57:3000/user/masterActor/w1”,
“akka.tcp://ClusterSystem@127.0.0.78:3000/user/masterActor/w1”,
“akka.tcp://ClusterSystem@127.0.56.67:3000/user/masterActor/w1”]
}
}

First, you should use the cluster aware routers and not define routee paths with addresses like that in config.

Consistent hashing group router is a kind of message based router.

The cluster routers will avoid unreachable nodes, but there can always be a short time before that is detected and then messages routed to such node will be sent to the void.

Thanks @patriknw

I went through Consistent hashing group router, I don’t know how ConsistentHashableEnvelope routerActor chooses routees.
I ran the sample code calculating meanWordLength.

for (String word : words) {
workerRouter.tell(new ConsistentHashableEnvelope(word, word),
aggregator);

}

I gave as 2551, 2552 and 2553 ports

This is the text that will be analyzed - this is the text to find meanWordLength

If my all three members are up then,
text, be will be done by worker actor running on port 2551
is will be done by worker actor running on port 2552
this, the, that, will, analyzed will be done by worker actor running on port 2553

So finally all the words in the text are processed and aggregatorActor calculates meanWordLength.

So my doubt is how ConsistentHashableEnvelope is working, how every time it delegates the word to same node without change.

If anyone of my node stopped (say 2553) then those words are automatically passed to other nodes (either 2551 or 2552)

Please advice me if anything am wrong
Thanks

It will send the word to the same place as long as there are no changes in the cluster membership (adding/removing nodes) and also then it will reduce the number of relocations. Described in more detail in the documentation.

Yes I understood this. I want to know how it will send the particular word to same place. Is there any mapping happening internally. If so how to override that

Thanks