Multiple akka system in one PC

How can we run several akka nodes in one computer? I am currently following in my application.conf file. For each system, I added different port numbers, but I can not start more than one instance. The error says Address already in use failed to bind .

application.conf file

 remotelookup { include "common" akka { remote.server.port = 2500 cluster.nodename = "n1" } } 

Update: multiple akka nodes means that I have another separate server application that will communicate with the remote node wizard using akka.

+4
source share
3 answers

The problem was in determining the port. It should be like

 remotelookup { include "common" akka { remote.netty.port = 2500 cluster.nodename = "n1" } } 

In another way, akka will use the default port.

+1
source

Our approach:

Create various settings in application.conf for each of the systems:

 systemOne { akka { remote { enabled-transports = ["akka.remote.netty.tcp"] netty.tcp { hostname = ${public-hostname} port = 2552 } } } } systemTwo { akka { remote { enabled-transports = ["akka.remote.netty.tcp"] netty.tcp { hostname = ${public-hostname} port = 2553 } } } } 

application.conf is the default configuration file, so in your settings module add the configs for the systems:

 object Configs { private val root = ConfigFactory.load() val one = root.getConfig("systemOne") val two = root.getConfig("systemTwo") } 

and then create systems with these configurations:

 val one = ActorSystem("SystemName", one) val two = ActorSystem("AnotherSystemName", two) 

Remember that system names must be different

+12
source

If you do not want to hardcode the information into your application.conf , you can do this:

 def remoteConfig(hostname: String, port: Int, commonConfig: Config): Config = { val configStr = s""" |akka.remote.netty.hostname = $hostname |akka.remote.netty.port = $port """.stripMargin ConfigFactory.parseString(configStr).withFallback(commonConfig) } 

Then use it like:

 val appConfig = ConfigFactory.load val sys1 = ActorSystem("sys1", remoteConfig(args(0), args(1).toInt, appConfig)) val sys2 = ActorSystem("sys2", remoteConfig(args(0), args(2).toInt, appConfig)) 

If you use 0 for a port, Akka will assign a random # port to this ActorSystem .

+2
source

Source: https://habr.com/ru/post/1490853/


All Articles