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, http://akka.io, 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 http://akka.io. 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: http://camel.apache.org/quartz.html