score:6
Setting up the whole thing for the first time is a pain but if you do it once you will have a good skeleton that you will user on regular basis.
I've written in comment below the question user clustering not remoting.
Here is how I do it: I set up an sbt root project with three sub-projects.
- common
- frontend
- backend
In common
you put everything that is common to both projects e.g. the messages that they share, actor classes that are created in frontend and deployed to backend.
Put a reference.conf
to common project, here is mine:
akka {
loglevel = INFO
actor {
provider = "akka.cluster.ClusterActorRefProvider"
debug {
lifecycle = on
}
}
cluster {
seed-nodes = [
"akka.tcp://application@127.0.0.1:2558",
"akka.tcp://application@127.0.0.1:2559"
]
}
}
Now in the frontend:
akka {
remote {
log-remote-lifecycle-events = off
netty.tcp {
hostname = "127.0.0.1"
port = 2558
}
}
cluster {
auto-down = on
roles = [frontend]
}
}
and the backend
akka {
remote {
log-remote-lifecycle-events = off
netty.tcp {
hostname = "127.0.0.1"
port = 0
}
}
cluster {
auto-down = on
roles = [backend]
}
}
This will work like this: You start the fronted part first which will control the cluster. Then you can start any number of backends you want that will join automatically (look at the port, it's 0 so it will be chosen randomly).
Now you need to add the whole logic to the frontend main:
Create the actor system with name application
:
val system = ActorSystem("application")
Do the same at the backend main.
Now write your code in fronted so it will create your workers with a router, here's my example code:
context.actorOf(ServiceRuntimeActor.props(serviceName)
.withRouter(
ClusterRouterConfig(ConsistentHashingRouter(),
ClusterRouterSettings(
totalInstances = 10, maxInstancesPerNode = 3,
allowLocalRoutees = false, useRole = Some("backend"))
)
),
name = shortServiceName)
just change your ServiceRuntimeActor
to name of your worker. It will deploy workers to all backends that you've started and limit this to max 3 per node and max 10 in total.
Hope this will help.
Source: stackoverflow.com
Related Query
- how to create remote actors dynamically and control them by using AKKA
- How to create an Akka flow with backpressure and Control
- How do I create a class hierarchy of typed factory method constructors and access them from Scala using abstract types?
- when we initialize actor system and create an actor using actorOf method, how many actors are getting created?
- Scala: How do I dynamically instantiate an object and invoke a method using reflection?
- How to create annotations and get them in scala
- Play: How to remove the fields without value from JSON and create a new JSON with them
- How are "Closures" such a powerful abstraction that object systems and fundamental control structures are implemented using it?
- How to hide Akka remote actors from lookup?
- How do I parse xml into "messages" and print them out in scala using stream parsing?
- How to reaload scala application after code change using actors and sbt
- Akka 2.0 Remoting: How do I start/allocate remote actors at runtime
- Play framework Scala: Create infinite source using scala akka streams and keep Server sent events connection open on server
- How can I resolve conflicting actor systems while testing akka-http and akka actors at the same spec file?
- How to log on STDOUT and file using Play 2 and Akka
- How to send objects to remote akka actors in an asymmetric system
- how to create a connection between scala and mysql using jdbc
- Akka with Remote Actors and Durable mailboxes
- How to create new test report directory with timestamp every time I run a test and keep the old test reports using scalatest and sbt
- scala - how to create shared threadpools/executioncontext for futures, parallel collection, and akka
- how to create and download a file using play framework?
- Using a WebService with Akka Actors and the play framework
- How do I create a "Locator" for Akka Actors
- How to map multiple Futures and pass them as arguments to a view using Play with Scala
- How Do I Pass Replies Between Actors in Play! and Akka
- Using akka futures and actors for parallelizing a list
- How to create actors transparently across an Akka cluster
- Akka Streams - How do I create a runnable Graph dynamically at runtime?
- How to pass and consume Flow1 materialized value into Flow2 using Akka streams
- How do I create a tarball and a zip for a single module using distinct configurations?
More Query from same tag
- Play Framework: How to compile an application with the option "-Xlint:unchecked"?
- Reading Excel file with Scala
- How to group the list based on values in scala?
- Changing the compiler's classpath from a Scala macro?
- Replace null values in Spark DataFrame
- Scala Why am I getting a type mismatch with hashmap?
- What is the purpose of the annotation after equal sign?
- Obtaining type information after ToolBox.parse?
- Scala passing a case class as a function
- play json, recursive reads, npe
- Why does IDEA 14 report "Cannot load facet "Scala": Unknown type of facet "scala""?
- Is there a way to avoid to convert number types in Scala? Should I use Numeric, Integral?
- Spark: Logistic regression
- Mocking time for Scala Deadline during unit testing
- Value of an object
- Can implicit class also be Dynamic?
- is it possible to debug Camel Scala DSL on intellij
- Convert HOCON (.conf) to JSON with scala/play?
- Package object for type definintions
- Can't stop a defined recursive function using Scala
- Spark : converting Array[Byte] data to RDD or DataFrame
- Play ScalaJSON Reads[T] parsing ValidationError(error.path.missing,WrappedArray())
- Anonymous function as argument in scala
- Prevent PlayFramework's template engine from escaping my Strings
- How to set content type?
- Spark DataFrame from JSON swap columns with rows
- Scala type that is Iterable and has a length?
- Fill null values in a row with frequency of other column
- Akka for Asynchronous processing?
- Converting Gradle/IDEA project into multiple subprojects