Commits

Micha Kops  committed f21ccb5 Draft

sbt build file restructured, examples for resequencer api and load-balancing added.

  • Participants
  • Parent commits 16c6e88

Comments (0)

Files changed (4)

 .settings
 target
 .classpath
-.cache
+.cache
+activemq-data
+.camel
+data/outbox/*
 
 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"
-
-libraryDependencies += "javax.mail" % "mail" % "1.4.5"
-
-libraryDependencies += "com.icegreen" % "greenmail" % "1.3"
-
-libraryDependencies += "org.apache.camel" % "camel-mail" % "2.10.3"
+libraryDependencies ++= Seq(
+	"org.apache.camel" % "camel-scala" % "2.10.1",
+	"org.apache.activemq" % "activemq-core" % "5.6.0",
+	"org.apache.camel" % "camel-jms" % "2.10.1",
+	"ch.qos.logback" % "logback-core" % "1.0.9",
+	"ch.qos.logback" % "logback-classic" % "1.0.9",
+	"javax.mail" % "mail" % "1.4.5",
+	"com.icegreen" % "greenmail" % "1.3",
+	"org.apache.camel" % "camel-mail" % "2.10.3"
+)

File src/main/scala/com/hascode/tutorial/LoadBalancerExample.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 LoadBalancerExample 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("jms:incoming").loadBalance().
+      roundRobin().to("jms:worker-queue-1", "jms:worker-queue-2", "jms:worker-queue-3");
+
+    from("jms:worker-queue-1")
+      .process(exchange => println("Handler 1 recevied a message with number flag: " + exchange.getIn().getHeader("my-number")))
+    from("jms:worker-queue-2")
+      .process(exchange => println("Handler 2 recevied a message with number flag: " + exchange.getIn().getHeader("my-number")))
+    from("jms:worker-queue-3")
+      .process(exchange => println("Handler 3 recevied a message with number flag: " + exchange.getIn().getHeader("my-number")))
+  }
+  context.addRoutes(routeBuilder)
+  context.start
+
+  Thread.sleep(2000)
+  val tpl = context.createProducerTemplate
+  tpl.setDefaultEndpointUri("jms:incoming")
+  tpl.sendBodyAndHeader("foo1", "my-number", 1)
+  tpl.sendBodyAndHeader("foo2", "my-number", 2)
+  tpl.sendBodyAndHeader("foo3", "my-number", 3)
+  tpl.sendBodyAndHeader("foo4", "my-number", 4)
+  tpl.sendBodyAndHeader("foo5", "my-number", 5)
+  tpl.sendBodyAndHeader("foo6", "my-number", 6)
+  while (true) {}
+}
+

File src/main/scala/com/hascode/tutorial/ResequencerExample.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 ResequencerExample 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("jms:wip").resequence(header("custom-priority")).batch().timeout(10000).reverse().to("jms:wip-inorder")
+
+    from("jms:wip-inorder")
+      .process(exchange => println("Message received with priority: " + exchange.getIn().getHeader("custom-priority")))
+  }
+  context.addRoutes(routeBuilder)
+  context.start
+
+  Thread.sleep(2000)
+  val tpl = context.createProducerTemplate
+  tpl.setDefaultEndpointUri("jms:wip")
+  tpl.sendBodyAndHeader("foo1", "custom-priority", 1)
+  tpl.sendBodyAndHeader("foo2", "custom-priority", 5)
+  tpl.sendBodyAndHeader("foo3", "custom-priority", 6)
+  tpl.sendBodyAndHeader("foo4", "custom-priority", 3)
+  tpl.sendBodyAndHeader("foo5", "custom-priority", 4)
+  tpl.sendBodyAndHeader("foo6", "custom-priority", 2)
+  while (true) {}
+}
+