camel-scala-extra

Extra Scala helpers for Apache Camel

License

License

Categories

Categories

Scala Languages
GroupId

GroupId

com.osinka.camel
ArtifactId

ArtifactId

camel-scala-extra_2.9.2
Last Version

Last Version

1.4.1
Release Date

Release Date

Type

Type

jar
Description

Description

camel-scala-extra
Extra Scala helpers for Apache Camel
Project URL

Project URL

https://github.com/osinka/camel-scala-extra
Project Organization

Project Organization

Osinka
Source Code Management

Source Code Management

http://github.com/osinka/camel-scala-extra

Download camel-scala-extra_2.9.2

How to add to project

<!-- https://jarcasting.com/artifacts/com.osinka.camel/camel-scala-extra_2.9.2/ -->
<dependency>
    <groupId>com.osinka.camel</groupId>
    <artifactId>camel-scala-extra_2.9.2</artifactId>
    <version>1.4.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.osinka.camel/camel-scala-extra_2.9.2/
implementation 'com.osinka.camel:camel-scala-extra_2.9.2:1.4.1'
// https://jarcasting.com/artifacts/com.osinka.camel/camel-scala-extra_2.9.2/
implementation ("com.osinka.camel:camel-scala-extra_2.9.2:1.4.1")
'com.osinka.camel:camel-scala-extra_2.9.2:jar:1.4.1'
<dependency org="com.osinka.camel" name="camel-scala-extra_2.9.2" rev="1.4.1">
  <artifact name="camel-scala-extra_2.9.2" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.osinka.camel', module='camel-scala-extra_2.9.2', version='1.4.1')
)
libraryDependencies += "com.osinka.camel" % "camel-scala-extra_2.9.2" % "1.4.1"
[com.osinka.camel/camel-scala-extra_2.9.2 "1.4.1"]

Dependencies

compile (3)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.9.2
org.apache.camel : camel-core jar 2.10.1
org.apache.camel : camel-scala jar 2.10.1

test (3)

Group / Artifact Type Version
org.scalatest : scalatest_2.9.2 jar 1.8
junit : junit jar 4.10
org.slf4j : slf4j-simple jar 1.7.1

Project Modules

There are no modules declared in this project.

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

RouteHelper

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:

  • exchange.in = message instead of exchange.getIn.setBody(message)
  • val obj = exchange.in[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 = exchange.in("header") instead of val header = exchange.getIn.getHeader("header")

Processors

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{ cronJob.run }

Filters

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 })

“Unit”

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) })

Converters

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
com.osinka.camel

Osinka

Versions

Version
1.4.1