2.2 Spotlight: Configure Seed Nodes from Command Line
The Typesafe Config library has been updated to version 1.0.1 to support a new syntax for string lists from the command line. This is useful when defining the cluster seed nodes from a start script.
In the configuration file you would define:
akka.cluster.seed-nodes = [
"akka.tcp://ClusterSystem@host1:2552",
"akka.tcp://ClusterSystem@host2:2552"]
Corresponding command line parameters:
-Dakka.cluster.seed-nodes.0=akka.tcp://ClusterSystem@host1:2552
-Dakka.cluster.seed-nodes.1=akka.tcp://ClusterSystem@host2:2552
2.2 Spotlight: Immutable Everywhere
Akka has in 2.2 been refactored to require scala.collection.immutable data structures as much as possible, this leads to fewer bugs and more opportunity for sharing data safely.
Do you know that some of the collection types in Scala Predef are mutable? For example, a method defined with parameter of type Seq[String], without any import, can be used with both an immutable List and a mutable ListBuffer or an array. Such method signatures have been changed to scala.collection.immutable.Seq.
See the Migration Guide for more information.
2.2 Spotlight: Simpler use of Stash
With the addition of Mailbox requirements usage of the Stash trait became simpler, too: Stash based actors will pick up the correct mailbox type without the need of any additional documentation. Here is a simple example using Stash:
See the documentation on Stash for details, and if you feel adventurous take a look at the Mailboxes documentation section to see how you can customize the mailbox of actors using Stash.
2.2 Spotlight: Logging of Actor Failures
Previously every exception escalated to the a supervisor was logged in the child at ERROR level. This has been made more flexible by moving the logging into the parent’s supervisor strategy where it arguably also belonged in the first place: it is the supervisor which attributes severity to a failure.
See also the docs for a little more information.
2.2 Spotlight: Mailbox Requirements
Ensuring that an actor has a certain type of message queue in its mailbox can now easily be accomplished. Simply have the actor mix in the parameterized trait RequiresMessageQueue. Here is an example of an actor tha requires a bounded message queue.
In order for Akka to know which mailbox to create for the actor, you need to map the type parameter of RequiresMessageQueue to a mailbox configuration like this.
When you create a BoundedActor it will be given a bounded-mailbox mailbox. If the actor has a different mailbox configured in deployment, then that will override this mapping. The message queue of the created mailbox will be checked against the required type and actor creation will fail if the message queue doesn’t conform to the required type.
Read more in the Akka mailbox documentation.
2.2 Spotlight: Mailbox Configuration
Actor mailboxes can now be configured on a per actor basis independently from the dispatcher. Here is an example that defines a bounded mailbox configuration and an actor deployment in your application.conf:
Then you can easily use that actor deployment configuration like this:
or simply configure the mailbox directly on the Props like this:
Read more in the Akka mailbox documentation
2.2 Spotlight: New Remoting
The remoting layer of Akka has been redesigned from ground up in 2.2. Apart from the internal changes several new features were introduced. Most notably the transport layer is now fully pluggable and new protocols can be added by implementing a simple Transport interface and loading it from configuration. In addition it is now possible to load multiple transports for the same actor system therefore using different communication protocols to interface with other remote systems.
As a result, the remote address format has been changed, so an address of akka://remote-sys:1234 becomes akka.tcp://remote-sys:1234 if the TCP driver is used.
Also important to note that driver specific remoting settings now live inside their driver scoped namspace, particularly the configuration for the default netty TCP driver is under akka.remote.netty.tcp.
Connections are now monitored by a heartbeat driven accrual failure detector which adapts itself to network conditions and can be fine-tuned by configuration – or completely replaced by a user provided implementation.
See the remoting documentation and the migration guide for more information.
2.2 Spotlight: Cluster Singleton
Using a singleton should not be the first design choice, but for some use cases it is convenient and sometimes also mandatory to ensure that you have exactly one actor of a certain type running somewhere in the cluster.
Therefore, this specific use case is made easily accessible by the Cluster Singleton Pattern in the contrib module. It manages singleton actor instance among all cluster nodes or a group of nodes tagged with a specific role. The singleton actor is always running on the oldest member. The cluster failure detector will notice when oldest node becomes unreachable due to things like JVM crash, hard shut down, or network failure. Then a new oldest node will take over and a new singleton actor is created.
Read more in the documentation.
2.2 Spotlight: Oldest Cluster Member
The cluster knows the order members were added to the cluster. akka.cluster.Member has a method isOlderThan to compare two members by their age. This is useful when you need a stable order of the nodes.
For example, this is how you can keep track of the members, sort them by age, and send each message to the first 3 nodes:
2.2 Spotlight: Cluster Node Roles
Not all nodes of a cluster need to perform the same function: there might be one sub-set which runs the web front-end, one which runs the data access layer and one for the number-crunching. Deployment of actors—for example by cluster-aware routers—can take node roles into account to achieve this distribution of responsibilities.
The roles of a node is defined in the configuration property named akka.cluster.roles and it is typically defined in the start script as a system property.