Commits

Micha Kops committed c458919 Draft

JMS/ActiveMQ Example added.

Comments (0)

Files changed (3)

 version := "1.0.0"
 
 libraryDependencies += "org.apache.camel" % "camel-scala" % "2.10.1"
+
+libraryDependencies += "org.apache.activemq" % "activemq-core" % "5.6.0"
+
+libraryDependencies += "org.apache.camel" % "camel-jms" % "2.10.1"
+
+libraryDependencies += "ch.qos.logback" % "logback-core" % "1.0.9"
+
+libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.0.9"

src/main/scala/com/hascode/tutorial/ExampleWithMessagingUsingActiveMQ.scala

+package com.hascode.tutorial
+import org.apache.camel.scala.dsl.builder.RouteBuilder
+import org.apache.camel.CamelContext
+import org.apache.camel.impl.DefaultCamelContext
+import javax.jms.ConnectionFactory
+import org.apache.camel.component.jms.JmsComponent
+import org.apache.activemq.ActiveMQConnectionFactory
+import org.apache.camel.Processor
+import org.apache.camel.scala.dsl.builder.RouteBuilderSupport
+
+object ExampleWithMessagingUsingActiveMQ extends App with RouteBuilderSupport {
+  val context: CamelContext = new DefaultCamelContext
+  val connectionFactory: ConnectionFactory = new ActiveMQConnectionFactory("vm://localhost")
+  context.addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
+  val routeBuilder = new RouteBuilder {
+    from("file:data/inbox")
+      .choice {
+        when(_.in("CamelFileName") match {
+          case x: String => if (x.endsWith(".xml")) -->("jms.xmlOrders") else -->("jms:csvOrders")
+          case _ => -->("jms:invalidOrders")
+        })
+      }
+  }
+  context.addRoutes(routeBuilder)
+  context.start
+  while (true) {}
+}
+

src/main/scala/com/hascode/tutorial/SimpleFileEndpointExample.scala

 import org.apache.camel.scala.dsl.builder.RouteBuilder
 import org.apache.camel.CamelContext
 import org.apache.camel.impl.DefaultCamelContext
+import org.apache.camel.scala.dsl.builder.RouteBuilderSupport
 
 object SimpleFileEndpointExample extends App {
   val context: CamelContext = new DefaultCamelContext
-  context.addRoutes(new FileEndpointBuilder)
+  val routeBuilder = new RouteBuilder {
+    from("file:data/inbox") --> ("file:data/outbox")
+  }
+  context.addRoutes(routeBuilder)
   context.start
   while (true) {}
 }
 
-class FileEndpointBuilder extends RouteBuilder {
-  from("file:data/inbox") --> ("file:data/outbox")
-}