Monday, 13 June 2011

My first camel processor in scala

First create a maven project with:
mvn archetype:generate -DarchetypeGroupId=org.apache.camel.archetypes \\
-DarchetypeArtifactId=camel-archetype-scala -DarchetypeVersion=2.7.2 \\
-DgroupId=com.unitest -DartifactId=my_test

It creates a my_test project with a route defined in src/main/scala/com/unitest/MyRouteBuilder.scala, which can be modified as:

"timer://foo?fixedRate=true&delay=5s&period=10s" ==> {
     bean("myBean") 
     to("log:bean")
   }

Where myBean is referenced in src/main/resources/META-INF/spring/camel-context.xml as:
<bean id="myBean" class="com.unitest.MyBean"/>

and class MyBean, in folder src/main/scala/com/unitest is:
package com.unitest

import org.apache.camel.Exchange

class MyBean {

  def process(exchange: Exchange) {
    exchange.getIn.setBody("EpiReplicaQuery test")
   }

Execute with mvn camel:run and that's all.

No comments: