Posted on by & filed under Content - Highlights and Reviews, Information Technology, Web Development.

While Akka is an incredible library and framework for writing concurrent apps that run on a single machine, one of its greatest strengths is the power it gives you for creating distributed systems. Akka supports location transparency – what this means in plain English is that you can write your code so that it doesn’t matter whether your actors are running locally or remotely. Now this won’t always be the case with every part of your system, but when you design for it, it enables a great deal of flexibility.

The easiest way to see this is with a simple two-node example with one node acting as the worker while another makes requests for work to be done. I’ll use a trivial example in this article, but you should be able to see how this can be extended to something more useful.

On the worker node, we’ll define the following to start up the actor that does the work:

You’ll need to give it a configuration to tell it to listen for remote connections:

The requestor node that asks for work to be done would look like this:

The configuration for this node would include the following:

Notice how the code doesn’t contain any references that explicitly indicate the worker actor is remote. All of the important details are in the configuration. This makes it remarkably easy to get a simple app working and later configure it to work remotely.

One important caveat to be aware of here is that the code for the Worker needs to be available for RequestorApp to be able to start it. There’s nothing really magic going on here, but it’s something you need to keep in mind.

Once you combine this remoting capability with the fault-tolerance, routing and other features of Akka, you end up with a very flexible toolkit for building distributed systems that are highly resilient.

Safari Books Online has the content you need

Take advantage of these Scala mobile resources in Safari Books Online:

Scala is an object-oriented programming language for the Java Virtual Machine. In addition to being object-oriented, Scala is also a functional language, and combines the best approaches to OO and functional programming. Artima is very pleased to publish a new edition of the best-selling book, Programming in Scala, written by the designer of the language, Martin Odersky. Co-authored by Lex Spoon and Bill Venners, this book takes a step-by-step tutorial approach to teaching you Scala. Starting with the fundamental elements of the language, Programming in Scala introduces functional programming from the practitioner’s perspective, and describes advanced language features that can make you a better, more productive developer.
Beginning Scala introduces you to the Scala programming language and then guides you through Scala constructs and libraries that allow small and large teams to assemble small components into high-performance, scalable systems. You will learn why Scala is becoming the language of choice for Web 2.0 companies such as Twitter as well as enterprises such as Seimens and SAP.
Learn how to be more productive with Scala, a new multi-paradigm language for the Java Virtual Machine (JVM) that integrates features of both object-oriented and functional programming. With Programming Scala, you’ll discover why Scala is ideal for highly scalable, component-based applications that support concurrency and distribution. Programming Scala clearly explains the advantages of Scala as a JVM language. You’ll learn how to leverage the wealth of Java class libraries to meet the practical needs of enterprise and Internet projects more easily. Packed with code examples, this book provides useful information on Scala’s command-line tools, third-party tools, libraries, and available language-aware plugins for editors and IDEs.
Lift in Action: The Simply Functional Web Framework for Scala is a step-by-step exploration of the Lift framework. It moves through the subject quickly using carefully crafted, well-explained examples that make you comfortable from the start. This book is written for developers who are new to both Scala and Lift.

About this author

Thomas Lockney has been writing software professionally for over 15 years and has been playing with computers for even longer. He discovered Scala nearly 4 years ago and has been known to run screaming from Java in the years since. You can find him on Twitter as @tlockney when he’s not too busy going on adventures with his lovely wife and their canine companions.

Tags: Akka, remoting, resilient, Scala,

Comments are closed.