Lightbend Activator

Akka Camel Samples with Scala

Activator will be EOL-ed on May 24, 2017.

We’re making it easier and simpler for developers to get started with Lightbend technologies. This unfortunately means that future releases of Play, Akka and Scala will no longer include Activator support, and Lightbend’s Activator server will be decommissioned by the end of 2017. Instead of supporting Activator to create and set up development projects, we'll be supporting standard Giter8 templates for sbt users and Maven archetypes for Maven users. So going forward,

To create new Lightbend projects

Instead of using the Activator command, make sure you have sbt 0.13.13 (or higher), and use the “sbt new” command, providing the name of the template. For example, “$ sbt new akka/hello-akka.g8”. You can find a list of templates here.

Also, as a convenience, the Lightbend Project Starter allows you to quickly create a variety of example projects that you just unzip and run.

To create new templates

If you want to create new templates, you can now do that in Giter8.

To migrate templates from Activator to Giter8

If you created Activator templates in the past, please consider migrating them to Giter8 with this simple process.

Akka Camel Samples with Scala

Akka Team
September 30, 2016
akka camel scala sample

Akka Camel Samples with Scala

How to get "Akka Camel Samples with Scala" on your computer

There are several ways to get this template.

Option 1: Choose akka-sample-camel-scala in the Lightbend Activator UI.

Already have Lightbend Activator (get it here)? Launch the UI then search for akka-sample-camel-scala in the list of templates.

Option 2: Download the akka-sample-camel-scala project as a zip archive

If you haven't installed Activator, you can get the code by downloading the template bundle for akka-sample-camel-scala.

  1. Download the Template Bundle for "Akka Camel Samples with Scala"
  2. Extract the downloaded zip file to your system
  3. The bundle includes a small bootstrap script that can start Activator. To start Lightbend Activator's UI:

    In your File Explorer, navigate into the directory that the template was extracted to, right-click on the file named "activator.bat", then select "Open", and if prompted with a warning, click to continue:

    Or from a command line:

     C:\Users\typesafe\akka-sample-camel-scala> activator ui 
    This will start Lightbend Activator and open this template in your browser.

Option 3: Create a akka-sample-camel-scala project from the command line

If you have Lightbend Activator, use its command line mode to create a new project from this template. Type activator new PROJECTNAME akka-sample-camel-scala on the command line.

Option 4: View the template source

The creator of this template maintains it at

Option 5: Preview the tutorial below

We've included the text of this template's tutorial below, but it may work better if you view it inside Activator on your computer. Activator tutorials are often designed to be interactive.

Preview the tutorial

This tutorial contains 3 samples of Akka Camel.

  • Asynchronous routing and transformation
  • Custom Camel route
  • Quartz scheduler

Asynchronous routing and transformation

This example demonstrates how to implement consumer and producer actors that support Asynchronous routing with their Camel endpoints. The sample application transforms the content of the Akka homepage,, by replacing every occurrence of *Akka* with *AKKA*.

To run this example, go to the Run tab, and start the application main class sample.camel.HttpExample if it's not already started. Then direct the browser to http://localhost:8875 and the transformed Akka homepage should be displayed. Please note that this example will probably not work if you're behind an HTTP proxy.

The following figure gives an overview how the example actors interact with external systems and with each other. A browser sends a GET request to http://localhost:8875 which is the published endpoint of the HttpConsumer actor. The HttpConsumer actor forwards the requests to the HttpProducer actor which retrieves the Akka homepage from The retrieved HTML is then forwarded to the HttpTransformer actor which replaces all occurrences of *Akka* with *AKKA*. The transformation result is sent back the HttpConsumer which finally returns it to the browser.

Implementing the example actor classes and wiring them together is rather easy as shown in HttpExample.scala.

The jetty endpoints of HttpConsumer and HttpProducer support asynchronous in-out message exchanges and do not allocate threads for the full duration of the exchange. This is achieved by using Jetty continuations on the consumer-side and by using Jetty's asynchronous HTTP client on the producer side. The following high-level sequence diagram illustrates that.

Custom Camel route example

This section also demonstrates the combined usage of a RouteProducer and a RouteConsumer actor as well as the inclusion of a custom Camel route. The following figure gives an overview.

  • A consumer actor receives a message from an HTTP client
  • It forwards the message to another actor that transforms the message (encloses the original message into hyphens)
  • The transformer actor forwards the transformed message to a producer actor
  • The producer actor sends the message to a custom Camel route beginning at the direct:welcome endpoint
  • A processor (transformer) in the custom Camel route prepends "Welcome" to the original message and creates a result message
  • The producer actor sends the result back to the consumer actor which returns it to the HTTP client

The producer actor knows where to reply the message to because the consumer and transformer actors have forwarded the original sender reference as well. The application configuration and the route starting from direct:welcome are done in the code above.

To run this example, go to the Run tab, and start the application main class sample.camel.CustomRouteExample

POST a message to http://localhost:8877/camel/welcome.

   curl -H "Content-Type: text/plain" -d "Anke" http://localhost:8877/camel/welcome

The response should be:

   Welcome - Anke -

Quartz Scheduler Example

Here is an example showing how simple it is to implement a cron-style scheduler by using the Camel Quartz component in Akka.

Open QuartzExample.scala.

The example creates a "timer" actor which fires a message every 2 seconds.

For more information about the Camel Quartz component, see here: