Console Example

This is a beginner’s example that demonstrates how to get started with Apache Camel.

In this example we integrate with the console using the Stream component. The example is interactive - it reads input from the console, and then transforms the input to upper case and prints it back to the console.

This is implemented with a Camel route defined in the Spring XML markup shown below:

  <!-- camelContext is the Camel runtime, where we can host Camel routes -->
  <camelContext xmlns="http://camel.apache.org/schema/spring">
    <route>
      <!-- read input from the console using the stream component -->
      <from uri="stream:in?promptMessage=Enter something: "/>
      <!-- transform the input to upper case using the simple language -->
      <!-- you can also use other languages such as groovy, ognl, mvel, javascript etc. -->
      <transform>
        <simple>${body.toUpperCase()}</simple>
      </transform>
      <!-- and then print to the console -->
      <to uri="stream:out"/>
    </route>
  </camelContext>

This example can be launched from the command line using Maven:

mvn compile exec:java

In the console you can enter a message and press <ENTER>. Camel responds by echoing the input message in upper case, as shown below:

[onsole.CamelConsoleMain.main()] SpringCamelContext INFO Apache Camel 2.10 (CamelContext: camel-1) started in 0.455 seconds
Enter something: camel rocks
CAMEL ROCKS
Enter something: and we have fun
AND WE HAVE FUN
Enter something:

To stop the example, strike Control+C

You can also run this example from your editor. For example, from Eclipse you can import this project using: File → Import … → Existing Maven Project, and select pom.xml from the examples\camel-example-console directory.

Next, navigate to the org.apache.camel.example.console.CamelConsoleMain class, right-click, and select Run As → Java Application.