How to send messages to appropriate actors by routing. (Content-based routing, solved?)

I would like to know if it’s possible to automate the .tell method somehow by sending messages through an actor which routes them to the appropriate actors without having defined the routing actor’s createReceive method.

To clarify:
childActor is a child of routingActor.
childActor’s createReceive is defined as:

public Receive createReceive() {
	ReceiveBuilder receive = receiveBuilder();
	receive.match(SomeMessage.class, message -> doSomething(message));
	return receive.build();
}

Now, is it possible to let routingActor just route messages of class SomeMessage to actors — like childActor, which match the class — while not sending them to other actors that don’t match SomeMessage in their createReceive method?

I have looked at akka’s routing options which doesn’t seem to be what I need. The only thing that comes close appears to be broadcasting. But I thought that’d be a rather inefficient solution for something like this.

Thank you in advance and hope to hear from you soon!

Edit: Seems like this could be something? Must have looked it over!
I’ll try it tomorrow.

The event bus may be interesting for you to look into as well, it has a classifier system where subscribers can say what type of messages they are interested in (may not be the most straight forward API in Akka though): https://doc.akka.io/docs/akka/current/event-bus.html#event-bus

1 Like

Thanks Johan! Got to say, Akka is absolutely wonderful to work with. LookupEventBus seems to be what I’m looking for.

Also, besides the overhead that is most-likely unavoidable in this. Do you see any pitfalls of using the consistent hashing exclusively to route messages in an Akka system? I’m quite new to this, and programming overall.

Great to hear that :)

Not sure about “using exclusively”, there are likely many interaction patterns in a single application, but if it fit’s the use case you are trying to solve with actors that seems fine.

If routing is local I can’t think of any pitfalls, when using cluster it is important to understand that consistent hashing will not give the same guarantees as sharding when the cluster topology changes (nodes are added or removed)

1 Like