Skip to content
This repository has been archived by the owner. It is now read-only.
The code has been merged into Apache Camel 2.11 Scala component, camel-scala
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Announcement. “camel-scala-extra” code has been merged into Apache Camel camel-scala component due to release as version 2.11, see ticket This effectively means camel-scala-extra’s end of life.

Extra Apache Camel methods for Scala

Despite the fact this project relies on camel-scala component from Apache Camel, it provides its own alternative way to write routes. Instead of using beta DSL from camel-scala, you use very limited choice of implicits (certainly you can always use more from “camel-scala”) to beautify ordinary Java DSL a little, but keep it mostly intact.

Basically this project provides:

  • few pimps for writing RouteBuilder
  • few Camel converters for Scala types and collections


com.osinka.camel.scala.RouteBuilderHelper trait is provided to ease writing RouteBuilders. To start:

class MyRouteBuilder extends RouteBuilder with RouteBuilderHelper {
  override def configure {

or just import them anywhere you’d like, e.g. your test suite:

import com.osinka.camel.scala.Implicits._

Rich objects

“camel-scala” is a sub-project of Apache Camel and provides useful implicit conversions to enrich Exchange and Message objects. Unfortunately you will need to consult the project’s source code because javadoc/scaladoc is not published. Basically you can do the following and alike:

  • = message instead of exchange.getIn.setBody(message)
  • val obj =[Type] instead of val obj = exchange.getIn.getBody(classOf[Type])
  • val out: Any = exchange.out instead of val out: Any = exchange.getOut.getBody
  • val header ="header") instead of val header = exchange.getIn.getHeader("header")


Many processors / filters in routes operate on only one part of Exchange, e.g. on “in” only. You can express such processor/filters with short wrappers like:

  • process(in(classOf[Int]) { 1+ }) will try to convert “in” message of the exchange to Int, increment by 1 and write it back to “in”. The is the same as process(in(classOf[Int]) { 1+ } .toIn) or more verbose process(in(classOf[Int]).by { 1+ }.toIn)
  • Otherwise, you can process “out”: process(out(classOf[Int]) {1+}) will write the result into “in”. To write it into “out”: process(out(classOf[Int]) {1+} .toOut)

You can make use of wonderful Scala "PartialFunction"s:

  • process(in(classOf[Int]) collect { case i if i % 2 == 0 => "even" })

Sometimes you just need a side-effect which does not depend on Exchange:

  • process{ }


Use the same DSL for filters:

  • filter(in(classOf[Int]) {0==})

You can use “PartialFunctions” for filters as well:

  • filter(in(classOf[Int]) collect { case i if i % 2 == 0 => true })


If your function returns Unit, you should not append .toIn or .toOut: I doubt you wanted to set the message’s body to Unit. You should not use such functions in filter as well. You will get runtime exception if you’d try to.

Otherwise it is absolutely fine to use functions with Unit return value: process(in(classOf[Int]) { x => println("x="+x) })


Few Camel type converters for Scala types:

  • Scala Symbol <=> String

Immutable collections conversions:

  • Scala Iterator <=> Java Iterator
  • Scala Iterator <=> Java Enumeration
  • Scala Iterable <=> Java Iterable
  • Scala Iterable <=> Java Collection
  • Scala List <=> Java Collection (copy occurs when converting from Java to Scala)
  • Scala List <=> Java List (copy occurs when converting from Java to Scala)
  • Scala Set => Java Set
  • Scala Map => Java Map
  • Scala Seq => Java List

Mutable collections conversions:

  • Scala Buffer <=> Java List
  • Scala Set <=> Java Set
  • Scala Map <=> Java Dictionary
  • Scala Map <=> Java Map
  • Scala ConcurrentMap <=> Java ConcurrentMap
  • Scala Seq => Java List

Option conversions:

  • Option => Iterable
  • Option => Iterable
  • Option => List
  • Option => Java List
  • Option => Java Collection
  • Option => Java Iterator
  • Option => Java Iterable
You can’t perform that action at this time.