You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2007/10/11 14:03:15 UTC

svn commit: r583787 - in /activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/discovery: ./ JmsDiscoveryTest.java MyRegistry.java MyService.java

Author: jstrachan
Date: Thu Oct 11 05:03:15 2007
New Revision: 583787

URL: http://svn.apache.org/viewvc?rev=583787&view=rev
Log:
added a little discovery example

Added:
    activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/discovery/
    activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/discovery/JmsDiscoveryTest.java   (with props)
    activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/discovery/MyRegistry.java   (with props)
    activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/discovery/MyService.java   (with props)

Added: activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/discovery/JmsDiscoveryTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/discovery/JmsDiscoveryTest.java?rev=583787&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/discovery/JmsDiscoveryTest.java (added)
+++ activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/discovery/JmsDiscoveryTest.java Thu Oct 11 05:03:15 2007
@@ -0,0 +1,81 @@
+/**
+ * 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.jms.discovery;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.jms.ConnectionFactory;
+import javax.naming.Context;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import static org.apache.camel.component.jms.JmsComponent.jmsComponentClientAcknowledge;
+
+/**
+ * @version $Revision: 574458 $
+ */
+public class JmsDiscoveryTest extends ContextTestSupport {
+
+    protected MyRegistry registry = new MyRegistry();
+
+    public void testDiscovery() throws Exception {
+        // lets wait to see if we get 3 services
+
+        Thread.sleep(3000);
+
+        Map<String, Map> map = new HashMap<String, Map>(registry.getServices());
+        System.out.println("Received map: " + map);
+
+        assertEquals("Size of map: " + map, 3, map.size());
+    }
+
+
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext camelContext = super.createCamelContext();
+
+        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
+        camelContext.addComponent("activemq", jmsComponentClientAcknowledge(connectionFactory));
+
+        return camelContext;
+    }
+
+    @Override
+    protected Context createJndiContext() throws Exception {
+        Context context = super.createJndiContext();
+        context.bind("service1", new MyService("service1"));
+        context.bind("service2", new MyService("service2"));
+        context.bind("service3", new MyService("service3"));
+        context.bind("registry", registry);
+        return context;
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                // lets setup the heartbeats
+                from("bean:service1?method=status").to("activemq:topic:registry.heartbeats");
+                from("bean:service2?method=status").to("activemq:topic:registry.heartbeats");
+                from("bean:service3?method=status").to("activemq:topic:registry.heartbeats");
+
+                from("activemq:topic:registry.heartbeats").to("bean:registry?method=onEvent");
+            }
+        };
+    }
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/discovery/JmsDiscoveryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/discovery/MyRegistry.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/discovery/MyRegistry.java?rev=583787&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/discovery/MyRegistry.java (added)
+++ activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/discovery/MyRegistry.java Thu Oct 11 05:03:15 2007
@@ -0,0 +1,40 @@
+/**
+ *
+ * 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.jms.discovery;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * A simple POJO showing how to create a simple registry
+ * 
+ * @version $Revision: 1.1 $
+ */
+public class MyRegistry {
+
+    private Map<String,Map> services = new HashMap<String, Map>();
+
+    public void onEvent(Map heartbeat) {
+        String key = (String) heartbeat.get("name");
+        services.put(key, heartbeat);
+    }
+
+    public Map<String, Map> getServices() {
+        return services;
+    }
+}

Propchange: activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/discovery/MyRegistry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/discovery/MyService.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/discovery/MyService.java?rev=583787&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/discovery/MyService.java (added)
+++ activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/discovery/MyService.java Thu Oct 11 05:03:15 2007
@@ -0,0 +1,40 @@
+/**
+ *
+ * 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.jms.discovery;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class MyService {
+    private String name;
+
+    public MyService(String name) {
+        this.name = name;
+    }
+
+    public Map status() {
+        Map answer = new HashMap();
+        answer.put("name", name);
+        answer.put("time", new Date());
+        return answer;
+    }
+}

Propchange: activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/discovery/MyService.java
------------------------------------------------------------------------------
    svn:eol-style = native