Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple akka system in a single pc

How can we run multiple akka nodes in a single pc? Currently, I've following in my application.conf file. For each system, I added different port numbers, but, I can't start more than one instance. 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, I have different different stand alone server application, which will communicate to remote master node using akka.

like image 447
Abimaran Kugathasan Avatar asked Dec 06 '22 06:12

Abimaran Kugathasan


2 Answers

The approach we are using is:

Create different settings in your 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 config file, so in your settings module add configs for you systems:

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

and then create systems with this configs:

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

Don't forget that system names must differ

like image 163
4lex1v Avatar answered Dec 21 '22 01:12

4lex1v


If you don't want to hardcode the info 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 the port Akka will assign a random port # to that ActorSystem.

like image 23
sourcedelica Avatar answered Dec 21 '22 03:12

sourcedelica