Author: gertv
Date: Mon Oct 6 10:08:14 2008
New Revision: 702201
URL: http://svn.apache.org/viewvc?rev=702201&view=rev
Log:
CAMEL-463: Adding idempotentconsumer support
Added:
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SIdempotentConsumerType.scala
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/IdempotentConsumerTest.scala
Modified:
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractType.scala
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
Modified:
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala?rev=702201&r1=702200&r2=702201&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala
(original)
+++
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala
Mon Oct 6 10:08:14 2008
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.scala.dsl
+package org.apache.camel.scala.dsl
/**
* Defines the 'keywords' in our Scala DSL
@@ -38,5 +38,6 @@
def delay(delay: Period) : SDelayerType
def resequence(expression: Exchange => Any) : SResequencerType
def aggregate(expression: Exchange => Any) : SAggregatorType
+ def idempotentconsumer(expression: Exchange => Any): SIdempotentConsumerType
}
Modified:
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractType.scala
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractType.scala?rev=702201&r1=702200&r2=702201&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractType.scala
(original)
+++
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractType.scala
Mon Oct 6 10:08:14 2008
@@ -19,6 +19,7 @@
import org.apache.camel.model.ProcessorType
import org.apache.camel.model.FilterType
import org.apache.camel.model.ChoiceType
+import org.apache.camel.model.IdempotentConsumerType
import org.apache.camel.scala.dsl.builder.RouteBuilder
@@ -72,6 +73,7 @@
def otherwise : SChoiceType =
throw new Exception("otherwise is only supported in a choice block or
after a when statement")
+ def idempotentconsumer(expression: Exchange => Any) = new
SIdempotentConsumerType(target.idempotentConsumer(expression, null))
def multicast = new SMulticastType(target.multicast)
Added:
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SIdempotentConsumerType.scala
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SIdempotentConsumerType.scala?rev=702201&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SIdempotentConsumerType.scala
(added)
+++
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SIdempotentConsumerType.scala
Mon Oct 6 10:08:14 2008
@@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.scala.dsl;
+
+import org.apache.camel.model.IdempotentConsumerType
+import org.apache.camel.processor.idempotent.MemoryMessageIdRepository
+import org.apache.camel.scala.dsl.builder.RouteBuilder
+
+/**
+ * Scala enrichment for Camel's IdempotentConsumerType
+ */
+class SIdempotentConsumerType(val target: IdempotentConsumerType)(implicit val
builder: RouteBuilder) extends SAbstractType with
Wrapper[IdempotentConsumerType] {
+
+ val unwrap = target
+
+ def memory(size: Int) = {
+
target.setMessageIdRepository(MemoryMessageIdRepository.memoryMessageIdRepository(size))
+ this
+ }
+
+}
Modified:
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala?rev=702201&r1=702200&r2=702201&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
(original)
+++
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
Mon Oct 6 10:08:14 2008
@@ -63,6 +63,7 @@
def when(filter: Exchange => Boolean) = stack.top.when(filter)
def as[Target](toType: Class[Target]) = stack.top.as(toType)
def recipients(expression: Exchange => Any) =
stack.top.recipients(expression)
+ def idempotentconsumer(expression: Exchange => Any) =
stack.top.idempotentconsumer(expression)
def splitter(expression: Exchange => Any) = stack.top.splitter(expression)
def otherwise = stack.top.otherwise
def multicast = stack.top.multicast
Added:
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/IdempotentConsumerTest.scala
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/IdempotentConsumerTest.scala?rev=702201&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/IdempotentConsumerTest.scala
(added)
+++
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/IdempotentConsumerTest.scala
Mon Oct 6 10:08:14 2008
@@ -0,0 +1,68 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.scala.dsl;
+
+import scala.dsl.builder.RouteBuilder
+import org.apache.camel.processor.idempotent.MemoryMessageIdRepository._;
+
+/**
+ * Test for an idempotent consumer
+ */
+class IdempotentConsumerTest extends ScalaTestSupport {
+
+ def testSimple() = doTest("direct:a", "mock:a")
+ def testBlock() = doTest("direct:b", "mock:b")
+
+
+ def doTest(from: String, to: String) = {
+ to expect { _.received("message 1", "message 2", "message 3")}
+ def send = sendMessage(from, _:String, _:String)
+ test {
+ send("1", "message 1")
+ send("2", "message 2")
+ send("1", "message 1")
+ send("2", "message 2")
+ send("1", "message 1")
+ send("3", "message 3")
+ }
+ }
+
+ def sendMessage(from: String, header: String, body: String) = {
+ template.send(from, new Processor() {
+ def process(exchange: Exchange) = {
+ val in = exchange.getIn()
+ in.setBody(body)
+ in.setHeader("messageId", header)
+ }
+ })
+ }
+
+ val builder = new RouteBuilder {
+ //START SNIPPET: simple
+ "direct:a" idempotentconsumer(_.in("messageId")) memory(200) to ("mock:a")
+ //END SNIPPET: simple
+
+ //START SNIPPET: block
+ "direct:b" ==> {
+ idempotentconsumer(_.in("messageId")) memory(200) apply {
+ to ("mock:b")
+ }
+ }
+ //END SNIPPET: block
+ }
+
+}