Akka is an actor-based message-driven toolkit for managing concurrency, elasticity and resilience on the JVM. The toolkit supports both Java and Scala. Akka is an open-source project, available under the Apache 2 License.

PCF supports a variety of JVM-based frameworks (plus .NET, Go, NodeJS, and others). This makes Akka a natural workload for the platform.

Plus, you can run Akka Cluster with TCP or UDP - PCF supports both protocols.

Now you know why Akka is well-suited for PCF. How do you go about setting it up? Glad you asked. Let’s dive in!

Tutorial: Up and Running with Akka Cluster on PCF

What follows is a short guide to walk you through how to deploy and run Akka Cluster-based applications.

Akka Cluster is based on TCP communication. Or, you can opt for UDP in Akka versions 2.4.11 and higher. As mentioned earlier, PCF supports both options. That’s because the platform’s embedded container-to-container networking (C2C) mechanism allows apps to talk to other apps via TCP or UDP. Client applications can access the Akka Cluster via both HTTP(S) and TCP.

Akka Cluster's seed nodes are essential for starting the cluster. They serve as the first point of contact for other nodes joining the cluster. Which brings us to another benefit of running Akka Cluster on PCF. With PCF, there is no need to write code to register every seed node with an external system like etcd, Zookeeper, or Consul. Instead, we can use the new polyglot service discovery capabilities to generate index-based routes for each instance of that app. From there, you can access each seed node using instance-based DNS.

We will also demonstrate how easy it is to dynamically scale your Akka Cluster to handle an increase in demand. As an application is scaled, PCF updates the index-based routes automatically for you.

Build the Akka Application

You can deploy an Akka application using PCF’s java-buildpack. Our sample application is inspired by akka-sample-cluster. It has backend nodes that calculate a factorial upon receiving messages from frontend nodes. Frontend nodes also expose HTTP interface GET <frontend-hostname>/info that shows number of jobs completed.

To ensure the URL for your app is unique from other apps in PCF, please change the value of the seed-host entry in the file src/main/resources/application.conf from:

seed-host = "akka-backend.apps.internal" to something like:

seed-host = "akka-backend-[unique_name].apps.internal"

Now you are ready to compile and package both Akka backend and frontend components:

sbt backend:assembly # backendsbt frontend:assembly # frontend

Deploying Akka Backend Application

Deploy, but do not start yet, sample Akka backend: with --no-route and --health-check-type none options since backend doesn't expose any HTTP ports. Substitute akka-backend-[unique_name] with the name you chose for the seed-host property.

Note: the name of the Java buildpack varies depending on whether you are deploying on-premises (java_buildpack_offline) or on Pivotal Web Services (java_buildpack). Make sure you use the right name when you push your app.

In addition, the app uses a PCF shared domain for internal routes called apps.internal. Applications that use internal routes will be directly communicating over the container network, instead of having traffic routed out and back in through the load balancer and GoRouter. For more details on this capability, please check this cloudfoundry.org blog post.

Deploying Akka Frontend Application

Once again, the name of the Java buildpack varies depending on whether you are deploying on-premises (java_buildpack_offline) or on Pivotal Web Services (java_buildpack). Make sure you use the right name when you push your app.

Before starting the frontend app, open another terminal window and tail the app logs. Please note log messages will appear after you start the frontend app:

cf logs akka-frontend-[unique_name]

Start the fronted app:

cf start akka-frontend-[unique_name]

After the fronted app starts, switch to the other terminal windows to check logs from both frontend and backend apps to ensure all client/server and server-to-server communications are working fine.

Verify that the frontend and backend apps are working:

curl akka-frontend-[unique_name].<YOUR_PCF_DOMAIN>/info

If all is working as expected, it should show the number of completed jobs!

Summary

We’ve shown you how to get Akka Cluster up and running quickly. And you’ve seen how easy it is to scale according to load. Now, you are ready to deploy your own Akka Cluster to PCF. Run Akka Cluster on PCF, and immediately enjoy many production-grade features out-of-the-box!

Special thanks to our friends at Lightbend for their assistance on this post!

About the Author

Guillermo is an award-winning Enterprise Architecture practitioner with 20+ years of progressive experience in different industries. Since 2011, he has led the delivery of cloud-native and digital transformation initiatives with Cloud Foundry at numerous Fortune 500 organizations. He focuses on all aspects of distributed systems including defense-in-depth, Internet scale, multi-cloud and fault-tolerance capabilities. He has presented at multiple conferences including SpringOne Platform, Cloud Foundry Summit, Pivotal Internet-of-Things roadshows and VMware Partner Exchange. Guillermo is passionate about his family, business, technology and soccer.