activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r1422926 - in /activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp: ./ java/ java/src/ java/src/main/ java/src/main/java/ java/src/main/java/example/
Date Mon, 17 Dec 2012 13:36:26 GMT
Author: chirino
Date: Mon Dec 17 13:36:25 2012
New Revision: 1422926

URL: http://svn.apache.org/viewvc?rev=1422926&view=rev
Log:
Add some AMQP java examples.

Added:
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/pom.xml
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/readme.md
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/src/
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/src/main/
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/src/main/java/
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/src/main/java/example/
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/src/main/java/example/Listener.java
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/src/main/java/example/Publisher.java

Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/pom.xml
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/pom.xml?rev=1422926&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/pom.xml
(added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/pom.xml
Mon Dec 17 13:36:25 2012
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+  
+  <groupId>example</groupId>
+  <artifactId>amqp-example</artifactId>
+  <version>0.1-SNAPSHOT</version>
+  
+  <name>example</name>
+  <description>Apollo AMQP Java Examples</description>
+
+  <repositories>
+    <repository>
+      <id>Fusesource Snapshots</id>
+      <url>http://repo.fusesource.com/nexus/content/repositories/snapshots</url>
+    </repository>
+  </repositories>
+  
+  <dependencies>
+    
+    <dependency>
+      <groupId>org.apache.geronimo.specs</groupId>
+      <artifactId>geronimo-jms_1.1_spec</artifactId>
+      <version>1.1</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.qpid</groupId>
+      <artifactId>qpid-amqp-1-0-client-jms</artifactId>
+      <version>${qpid-jms-version}</version>
+    </dependency>
+
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>2.1</version>
+        <configuration>
+          <source>1.6</source>
+          <target>1.6</target>
+        </configuration>
+      </plugin>
+
+      <!-- include all the dependencies into the jar so it's easier to execute the example
-->
+      <plugin>
+        <groupId>org.fusesource.mvnplugins</groupId>
+        <artifactId>maven-uberize-plugin</artifactId>
+        <version>1.14</version>
+        <executions>
+          <execution>
+            <phase>package</phase>
+            <goals><goal>uberize</goal></goals>
+          </execution>
+        </executions>
+      </plugin>
+      
+    </plugins>
+  </build>
+  
+</project>
+

Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/readme.md
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/readme.md?rev=1422926&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/readme.md
(added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/readme.md
Mon Dec 17 13:36:25 2012
@@ -0,0 +1,32 @@
+## Overview
+
+This is an example of how use the Java JMS api with Apollo via the AMQP protocol.
+
+## Prereqs
+
+- Install Java SDK
+- Install [Maven](http://maven.apache.org/download.html) 
+
+## Building
+
+Run:
+
+    mvn install
+
+## Running the Examples
+
+In one terminal window run:
+
+    java -cp target/amqp-example-0.1-SNAPSHOT.jar example.Listener
+
+In another terminal window run:
+
+    java -cp target/amqp-example-0.1-SNAPSHOT.jar example.Publisher
+
+You can control to which AMQP server the examples try to connect to by
+setting the following environment variables: 
+
+* `APOLLO_HOST`
+* `APOLLO_PORT`
+* `APOLLO_USER`
+* `APOLLO_PASSWORD`

Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/src/main/java/example/Listener.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/src/main/java/example/Listener.java?rev=1422926&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/src/main/java/example/Listener.java
(added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/src/main/java/example/Listener.java
Mon Dec 17 13:36:25 2012
@@ -0,0 +1,90 @@
+/**
+ * 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 example;
+
+import org.apache.qpid.amqp_1_0.jms.impl.*;
+import javax.jms.*;
+
+class Listener {
+
+    public static void main(String []args) throws JMSException {
+
+        String user = env("APOLLO_USER", "admin");
+        String password = env("APOLLO_PASSWORD", "password");
+        String host = env("APOLLO_HOST", "localhost");
+        int port = Integer.parseInt(env("APOLLO_PORT", "61613"));
+        String destination = arg(args, 0, "topic://event");
+
+        ConnectionFactoryImpl factory = new ConnectionFactoryImpl(host, port, user, password);
+        Destination dest = null;
+        if( destination.startsWith("topic://") ) {
+            dest = new TopicImpl(destination);
+        } else {
+            dest = new QueueImpl(destination);
+        }
+
+        Connection connection = factory.createConnection(user, password);
+        connection.start();
+        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        MessageConsumer consumer = session.createConsumer(dest);
+        long start = System.currentTimeMillis();
+        long count = 1;
+        System.out.println("Waiting for messages...");
+        while(true) {
+            Message msg = consumer.receive();
+            if( msg instanceof  TextMessage ) {
+                String body = ((TextMessage) msg).getText();
+                if( "SHUTDOWN".equals(body)) {
+                    long diff = System.currentTimeMillis() - start;
+                    System.out.println(String.format("Received %d in %.2f seconds", count,
(1.0*diff/1000.0)));
+                    break;
+                } else {
+                    if( count != msg.getIntProperty("id") ) {
+                        System.out.println("mismatch: "+count+"!="+msg.getIntProperty("id"));
+                    }
+                    count = msg.getIntProperty("id");
+
+                    if( count == 0 ) {
+                        start = System.currentTimeMillis();
+                    }
+                    if( count % 1000 == 0 ) {
+                        System.out.println(String.format("Received %d messages.", count));
+                    }
+                    count ++;
+                }
+
+            } else {
+                System.out.println("Unexpected message type: "+msg.getClass());
+            }
+        }
+        connection.close();
+    }
+
+    private static String env(String key, String defaultValue) {
+        String rc = System.getenv(key);
+        if( rc== null )
+            return defaultValue;
+        return rc;
+    }
+
+    private static String arg(String []args, int index, String defaultValue) {
+        if( index < args.length )
+            return args[index];
+        else
+            return defaultValue;
+    }
+}
\ No newline at end of file

Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/src/main/java/example/Publisher.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/src/main/java/example/Publisher.java?rev=1422926&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/src/main/java/example/Publisher.java
(added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/src/main/java/example/Publisher.java
Mon Dec 17 13:36:25 2012
@@ -0,0 +1,83 @@
+/**
+ * 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 example;
+
+import org.apache.qpid.amqp_1_0.jms.impl.*;
+import javax.jms.*;
+
+class Publisher {
+
+    public static void main(String []args) throws JMSException {
+
+        String user = env("APOLLO_USER", "admin");
+        String password = env("APOLLO_PASSWORD", "password");
+        String host = env("APOLLO_HOST", "localhost");
+        int port = Integer.parseInt(env("APOLLO_PORT", "61613"));
+        String destination = arg(args, 0, "topic://event");
+
+        int messages = 10000;
+        int size = 256;
+
+        String DATA = "abcdefghijklmnopqrstuvwxyz";
+        String body = "";
+        for( int i=0; i < size; i ++) {
+            body += DATA.charAt(i%DATA.length());
+        }
+
+        ConnectionFactoryImpl factory = new ConnectionFactoryImpl(host, port, user, password);
+        Destination dest = null;
+        if( destination.startsWith("topic://") ) {
+            dest = new TopicImpl(destination);
+        } else {
+            dest = new QueueImpl(destination);
+        }
+
+        Connection connection = factory.createConnection(user, password);
+        connection.start();
+        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        MessageProducer producer = session.createProducer(dest);
+        producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+        for( int i=1; i <= messages; i ++) {
+            TextMessage msg = session.createTextMessage(body);
+            msg.setIntProperty("id", i);
+            producer.send(msg);
+            if( (i % 1000) == 0) {
+                System.out.println(String.format("Sent %d messages", i));
+            }
+        }
+
+        producer.send(session.createTextMessage("SHUTDOWN"));
+        connection.close();
+
+    }
+
+    private static String env(String key, String defaultValue) {
+        String rc = System.getenv(key);
+        if( rc== null )
+            return defaultValue;
+        return rc;
+    }
+
+    private static String arg(String []args, int index, String defaultValue) {
+        if( index < args.length )
+            return args[index];
+        else
+            return defaultValue;
+    }
+
+}
\ No newline at end of file



Mime
View raw message