initializing akka actor systems with same name

1.5k views Asked by At

I am new to akka actor system. I am a bit confused about how a actor system is named. if I write

ActorSystem _system1 = ActorSystem.create("multi");
ActorSystem _system2 = ActorSystem.create("multi");
ActorSystem _system3 = ActorSystem.create("multi");

what is gonna happen in the background? Will there be 3 different instances of the actor system in the JVM? if yes, then how do I access the actors belonging to these actor systems over remoting?

2

There are 2 answers

0
cmbaxter On

Yes, it's possible (though probably not advised) to have 3 different ActorSystems contained in a single JVM. I say "not advised" because actor systems are heavy weight resources (thread pools etc...) and having multiple in a single JVM can be counter productive.

Now, in regards to remoting, in order to run these three in the same JVM, you will need to set up a different remoting bind port (property akka.remote.netty.tcp.port) for each actor system or else you will end up with port conflict issues. If you do that properly you should be able to differentiate the different actor systems because the port is included in the path. So for example, if you bound the first actor system to 2552, then the remote path to communicate with an actor bound to name "foo" under the root system would be:

akka.tcp://multi@someIpAddress:2552/user/foo

So it's certainly possible to do what you want, but again, it's not recommended...

0
Artur Nowak On

Answering your specific question about using the same name: they will be separate, disconnected actor systems.

The name serves only as a label, which can be verified by trying to access local actors between the systems.

As for remoting, as Akka guide states (emphasis mine):

The port number needs to be unique for each actor system on the same machine even if the actor systems have different names. This is because each actor system has its own networking subsystem listening for connections and handling messages as not to interfere with other actor systems.