You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2020/12/23 14:08:21 UTC

[camel] 02/03: CAMEL-15984: camel-activemq to support DynamicAware with toD

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 6e7992bfbcfddc48f59c5a0f891333052af940f1
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Dec 23 14:43:24 2020 +0100

    CAMEL-15984: camel-activemq to support DynamicAware with toD
---
 .../org/apache/camel/send-dynamic/activemq         |  2 +
 .../activemq/ActiveMQSendDynamicAware.java         | 25 ++++++++++
 .../activemq/ActiveMQToDSendDynamicTwoTest.java    | 56 ++++++++++++++++++++++
 3 files changed, 83 insertions(+)

diff --git a/components/camel-activemq/src/generated/resources/META-INF/services/org/apache/camel/send-dynamic/activemq b/components/camel-activemq/src/generated/resources/META-INF/services/org/apache/camel/send-dynamic/activemq
new file mode 100644
index 0000000..904f34c
--- /dev/null
+++ b/components/camel-activemq/src/generated/resources/META-INF/services/org/apache/camel/send-dynamic/activemq
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.activemq.ActiveMQSendDynamicAware
diff --git a/components/camel-activemq/src/main/java/org/apache/camel/component/activemq/ActiveMQSendDynamicAware.java b/components/camel-activemq/src/main/java/org/apache/camel/component/activemq/ActiveMQSendDynamicAware.java
new file mode 100644
index 0000000..cac9412
--- /dev/null
+++ b/components/camel-activemq/src/main/java/org/apache/camel/component/activemq/ActiveMQSendDynamicAware.java
@@ -0,0 +1,25 @@
+/*
+ * 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.component.activemq;
+
+import org.apache.camel.component.jms.JmsSendDynamicAware;
+import org.apache.camel.spi.annotations.SendDynamic;
+
+@SendDynamic("activemq")
+public class ActiveMQSendDynamicAware extends JmsSendDynamicAware {
+
+}
diff --git a/components/camel-activemq/src/test/java/org/apache/camel/component/activemq/ActiveMQToDSendDynamicTwoTest.java b/components/camel-activemq/src/test/java/org/apache/camel/component/activemq/ActiveMQToDSendDynamicTwoTest.java
new file mode 100644
index 0000000..7cc5653
--- /dev/null
+++ b/components/camel-activemq/src/test/java/org/apache/camel/component/activemq/ActiveMQToDSendDynamicTwoTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.component.activemq;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.apache.camel.component.activemq.ActiveMQComponent.activeMQComponent;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ActiveMQToDSendDynamicTwoTest extends CamelTestSupport {
+
+    @Test
+    public void testToD() throws Exception {
+        template.sendBodyAndHeader("direct:start", "Hello bar", "where", "bar");
+        template.sendBodyAndHeader("direct:start", "Hello beer", "where", "beer");
+        template.sendBodyAndHeader("direct:start", "Hello gin", "where", "gin");
+
+        template.sendBodyAndHeader("direct:start2", "Hello beer", "where2", "beer");
+        template.sendBodyAndHeader("direct:start2", "Hello whiskey", "where2", "whiskey");
+
+        // there should be 2 activemq endpoint
+        long count = context.getEndpoints().stream().filter(e -> e.getEndpointUri().startsWith("activemq:")).count();
+        assertEquals(2, count, "There should only be 2 activemq endpoint");
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                context.addComponent("activemq", activeMQComponent("vm://localhost?broker.persistent=false"));
+
+                // route message dynamic using toD
+                from("direct:start").toD("activemq:queue:${header.where}");
+
+                from("direct:start2").toD("activemq:queue:${header.where2}");
+            }
+        };
+    }
+}