Running a local cluster

For testing clustering behavior and high availability scenarios, you can run your Akka service as a local cluster with multiple nodes. This allows you to simulate a distributed environment on your local machine. A cluster is a group of instances of the same service all running in high availability mode.

Prerequisites

In order to run a local Akka cluster, you will need all of the SDK requirements as well as the following:

  • The Akka CLI must be installed

  • You need to have Maven or the Maven wrapper (mvnw) installed

  • You will need Docker installed properly. Docker is used to run Postgres to support Akka’s persistence layer

Starting a cluster

Once you’ve met the prerequisites you will need to open a terminal window (command prompt) to the root directory of an Akka service. This is where the main pom.xml file will be. Running akka local cluster with no arguments will present you with output similar to the following:

$ akka local cluster

               Akka Cluster Configuration
───────────────────────────────────────────────────────────────────────────────
[✓] 1. Load project configuration
[→] 2. Configure cluster size
[ ] 3. Compile project
[ ] 4. Start Akka persistence
[ ] 5. Start cluster
───────────────────────────────────────────────────────────────────────────────

  Project: shopping-cart-quickstart
  Version: 1.0-SNAPSHOT

  How many instances would you like to start? (1-3)

  > 3

The preceding output was generated by running akka local cluster in the shopping-cart-quickstart sample folder.

If you choose to run with 1 node, that is still not quite the same thing as using mvn exec:java. A single node cluster still uses Postgres for persistence.

It will take a few moments for each of the service instances to start, but the interactive console will display the startup progress. As each service instance starts, that instance’s HTTP port number will be displayed.

You’re now ready to use the Akka local console or curl or your favorite HTTP client to start interacting with your service cluster.