You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2012/09/27 01:26:20 UTC
svn commit: r1390775 [2/2] - in
/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire:
./ jms-example-composite-destinations/
jms-example-composite-destinations/src/
jms-example-composite-destinations/src/main/ jms-example-co...
Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-queue/src/main/java/example/queue/Consumer.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-queue/src/main/java/example/queue/Consumer.java?rev=1390775&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-queue/src/main/java/example/queue/Consumer.java (added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-queue/src/main/java/example/queue/Consumer.java Wed Sep 26 23:26:16 2012
@@ -0,0 +1,82 @@
+/**
+ * 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.queue;
+
+import example.util.Util;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jms.*;
+
+/**
+ * @author <a href="http://www.christianposta.com/blog">Christian Posta</a>
+ */
+public class Consumer {
+
+ private static final Logger LOG = LoggerFactory.getLogger(Consumer.class);
+ private static final String BROKER_HOST = "tcp://localhost:%d";
+ private static final int BROKER_PORT = Util.getBrokerPort();
+ private static final String BROKER_URL = String.format(BROKER_HOST, BROKER_PORT);
+ private static final Boolean NON_TRANSACTED = false;
+ private static final long TIMEOUT = 20000;
+
+ public static void main(String[] args) {
+ LOG.info("\nWaiting to receive messages... will timeout after " + TIMEOUT / 1000 +"s");
+ ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("admin", "password", BROKER_URL);
+ Connection connection = null;
+
+ try {
+
+ connection = connectionFactory.createConnection();
+ connection.start();
+
+ Session session = connection.createSession(NON_TRANSACTED, Session.AUTO_ACKNOWLEDGE);
+ Destination destination = session.createQueue("test-queue");
+ MessageConsumer consumer = session.createConsumer(destination);
+
+ int i = 0;
+ while (true) {
+ Message message = consumer.receive(TIMEOUT);
+
+ if (message != null) {
+ if (message instanceof TextMessage) {
+ String text = ((TextMessage) message).getText();
+ LOG.info("Got " + i++ + ". message: " + text);
+ }
+ } else {
+ break;
+ }
+ }
+
+ consumer.close();
+ session.close();
+
+ } catch (Exception e) {
+ LOG.error("Caught exception!", e);
+ }
+ finally {
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (JMSException e) {
+ LOG.error("Could not close an open connection...", e);
+ }
+ }
+ }
+ }
+}
Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-queue/src/main/java/example/queue/Producer.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-queue/src/main/java/example/queue/Producer.java?rev=1390775&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-queue/src/main/java/example/queue/Producer.java (added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-queue/src/main/java/example/queue/Producer.java Wed Sep 26 23:26:16 2012
@@ -0,0 +1,76 @@
+/**
+ * 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.queue;
+
+import example.util.Util;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jms.*;
+
+/**
+ * @author <a href="http://www.christianposta.com/blog">Christian Posta</a>
+ */
+public class Producer {
+ private static final Logger LOG = LoggerFactory.getLogger(Producer.class);
+ private static final String BROKER_HOST = "tcp://localhost:%d";
+ private static final int BROKER_PORT = Util.getBrokerPort();
+ private static final String BROKER_URL = String.format(BROKER_HOST, BROKER_PORT);
+ private static final Boolean NON_TRANSACTED = false;
+ private static final int NUM_MESSAGES_TO_SEND = 100;
+ private static final long DELAY = 100;
+
+ public static void main(String[] args) {
+
+ ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("admin", "password", BROKER_URL);
+ Connection connection = null;
+
+ try {
+
+ connection = connectionFactory.createConnection();
+ connection.start();
+
+ Session session = connection.createSession(NON_TRANSACTED, Session.AUTO_ACKNOWLEDGE);
+ Destination destination = session.createQueue("test-queue");
+ MessageProducer producer = session.createProducer(destination);
+
+ for (int i = 0; i < NUM_MESSAGES_TO_SEND; i++) {
+ TextMessage message = session.createTextMessage("Message #" + i);
+ LOG.info("Sending message #" + i);
+ producer.send(message);
+ Thread.sleep(DELAY);
+ }
+
+ producer.close();
+ session.close();
+
+ } catch (Exception e) {
+ LOG.error("Caught exception!", e);
+ }
+ finally {
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (JMSException e) {
+ LOG.error("Could not close an open connection...", e);
+ }
+ }
+ }
+ }
+
+}
Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-queue/src/main/resources/log4j.properties
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-queue/src/main/resources/log4j.properties?rev=1390775&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-queue/src/main/resources/log4j.properties (added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-queue/src/main/resources/log4j.properties Wed Sep 26 23:26:16 2012
@@ -0,0 +1,37 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+#
+# Setup the default logging levels
+#
+log4j.rootLogger=INFO, console
+
+#
+# Uncomment one of the following to enable debug logging
+#
+#log4j.logger.org.apache.activemq.apollo=TRACE
+#log4j.logger.org.apache.activemq.apollo.openwire=TRACE
+#log4j.logger.org.apache.activemq.apollo.broker=TRACE
+#log4j.logger.org.apache.activemq.apollo.web=TRACE
+#log4j.logger.org.apache.activemq.apollo.cli=TRACE
+#log4j.logger.org.apache.activemq.transport=TRACE
+
+# Console Settings
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+log4j.appender.console.layout=org.apache.log4j.PatternLayout
+log4j.appender.console.layout.ConversionPattern=%C %-5p | %m%n
+log4j.appender.console.threshold=TRACE
Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-temp-destinations/pom.xml
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-temp-destinations/pom.xml?rev=1390775&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-temp-destinations/pom.xml (added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-temp-destinations/pom.xml Wed Sep 26 23:26:16 2012
@@ -0,0 +1,88 @@
+<?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/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>openwire-example</artifactId>
+ <groupId>example</groupId>
+ <version>0.1-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>jms-example-temp-destinations</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>jms-example-util</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+ <profiles>
+ <profile>
+ <id>consumer</id>
+ <build>
+ <defaultGoal>package</defaultGoal>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>java</goal>
+ </goals>
+ <configuration>
+ <mainClass>example.tempdest.Consumer</mainClass>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+
+ <profile>
+ <id>producer</id>
+ <build>
+ <defaultGoal>package</defaultGoal>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>java</goal>
+ </goals>
+ <configuration>
+ <mainClass>example.tempdest.ProducerRequestReply</mainClass>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+</project>
\ No newline at end of file
Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-temp-destinations/readme.md
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-temp-destinations/readme.md?rev=1390775&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-temp-destinations/readme.md (added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-temp-destinations/readme.md Wed Sep 26 23:26:16 2012
@@ -0,0 +1,28 @@
+## Overview
+
+This is an example of how to use the ActiveMQ 5.x / OpenWire protocol to communicate with Apollo
+
+This example shows how to do request response with temporary destinations
+
+## Prereqs
+
+- Install Java SDK
+- Install [Maven](http://maven.apache.org/download.html)
+
+## Building
+
+Run:
+
+ mvn install
+
+## Running the Examples
+
+In one terminal window run:
+
+ mvn -Pconsumer
+
+In another terminal window run:
+
+ mvn -Pproducer
+
+You'll notice that the producer received a reply for the request it sent.
Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-temp-destinations/src/main/java/example/tempdest/Consumer.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-temp-destinations/src/main/java/example/tempdest/Consumer.java?rev=1390775&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-temp-destinations/src/main/java/example/tempdest/Consumer.java (added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-temp-destinations/src/main/java/example/tempdest/Consumer.java Wed Sep 26 23:26:16 2012
@@ -0,0 +1,84 @@
+package example.tempdest; /**
+ * 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.
+ */
+
+import example.util.Util;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jms.*;
+
+/**
+ * @author <a href="http://www.christianposta.com/blog">Christian Posta</a>
+ */
+public class Consumer {
+ private static final Logger LOG = LoggerFactory.getLogger(Consumer.class);
+ private static final String BROKER_HOST = "tcp://localhost:%d";
+ private static final int BROKER_PORT = Util.getBrokerPort();
+ private static final String BROKER_URL = String.format(BROKER_HOST, BROKER_PORT);
+ private static final Boolean NON_TRANSACTED = false;
+ private static final long TIMEOUT = 20000;
+
+ public static void main(String[] args) {
+ LOG.info("\nWaiting to receive messages... will timeout after " + TIMEOUT / 1000 +"s");
+ ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("admin", "password", BROKER_URL);
+ Connection connection = null;
+
+ try {
+
+ connection = connectionFactory.createConnection();
+ connection.start();
+
+ final Session session = connection.createSession(NON_TRANSACTED, Session.AUTO_ACKNOWLEDGE);
+ Destination destination = session.createQueue("test-queue");
+ MessageConsumer consumer = session.createConsumer(destination);
+
+ int i = 0;
+ while (true) {
+ Message message = consumer.receive(TIMEOUT);
+
+ if (message != null) {
+ if (message instanceof TextMessage) {
+ String text = ((TextMessage) message).getText();
+ LOG.info("Got " + i++ + ". message: " + text);
+ Destination replyTo = message.getJMSReplyTo();
+ MessageProducer producer = session.createProducer(replyTo);
+ producer.send(session.createTextMessage("You made it to the consumer, here is your response"));
+ producer.close();
+ }
+ } else {
+ break;
+ }
+ }
+
+ consumer.close();
+ session.close();
+
+ } catch (Exception e) {
+ LOG.error("Caught exception!", e);
+ }
+ finally {
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (JMSException e) {
+ LOG.error("Could not close an open connection...", e);
+ }
+ }
+ }
+ }
+}
Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-temp-destinations/src/main/java/example/tempdest/ProducerRequestReply.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-temp-destinations/src/main/java/example/tempdest/ProducerRequestReply.java?rev=1390775&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-temp-destinations/src/main/java/example/tempdest/ProducerRequestReply.java (added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-temp-destinations/src/main/java/example/tempdest/ProducerRequestReply.java Wed Sep 26 23:26:16 2012
@@ -0,0 +1,88 @@
+package example.tempdest; /**
+ * 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.
+ */
+
+import example.util.Util;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jms.*;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author <a href="http://www.christianposta.com/blog">Christian Posta</a>
+ */
+public class ProducerRequestReply{
+
+ private static final Logger LOG = LoggerFactory.getLogger(ProducerRequestReply.class);
+ private static final String BROKER_HOST = "tcp://localhost:%d";
+ private static final int BROKER_PORT = Util.getBrokerPort();
+ private static final String BROKER_URL = String.format(BROKER_HOST, BROKER_PORT);
+ private static final Boolean NON_TRANSACTED = false;
+ private static final int NUM_MESSAGES_TO_SEND = 100;
+ private static final long DELAY = 100;
+
+ public static void main(String[] args) {
+
+ ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("admin", "password", BROKER_URL);
+ Connection connection = null;
+
+ try {
+
+ connection = connectionFactory.createConnection();
+ connection.start();
+
+ Session session = connection.createSession(NON_TRANSACTED, Session.AUTO_ACKNOWLEDGE);
+ Destination destination = session.createQueue("test-queue");
+ MessageProducer producer = session.createProducer(destination);
+ Destination replyDest = session.createTemporaryQueue();
+
+ // set up the consumer to handle the reply
+ MessageConsumer replyConsumer = session.createConsumer(replyDest);
+ replyConsumer.setMessageListener(new MessageListener() {
+ @Override
+ public void onMessage(Message message) {
+ System.out.println("*** REPLY *** ");
+ System.out.println(message.toString());
+ }
+ });
+
+ TextMessage message = session.createTextMessage("I need a response for this, please");
+ message.setJMSReplyTo(replyDest);
+
+ producer.send(message);
+
+ // wait for a response
+ TimeUnit.SECONDS.sleep(2);
+ producer.close();
+ session.close();
+
+ } catch (Exception e) {
+ LOG.error("Caught exception!", e);
+ }
+ finally {
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (JMSException e) {
+ LOG.error("Could not close an open connection...", e);
+ }
+ }
+ }
+ }
+
+}
Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-topic/pom.xml
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-topic/pom.xml?rev=1390775&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-topic/pom.xml (added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-topic/pom.xml Wed Sep 26 23:26:16 2012
@@ -0,0 +1,90 @@
+<?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/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>openwire-example</artifactId>
+ <groupId>example</groupId>
+ <version>0.1-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>jms-example-topic</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>jms-example-util</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+ <profiles>
+ <profile>
+ <id>subscriber</id>
+ <build>
+ <defaultGoal>package</defaultGoal>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>java</goal>
+ </goals>
+ <configuration>
+ <mainClass>example.topic.Subscriber</mainClass>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+
+ <profile>
+ <id>publisher</id>
+ <build>
+ <defaultGoal>package</defaultGoal>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>java</goal>
+ </goals>
+ <configuration>
+ <mainClass>example.topic.Publisher</mainClass>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+
+</project>
\ No newline at end of file
Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-topic/readme.md
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-topic/readme.md?rev=1390775&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-topic/readme.md (added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-topic/readme.md Wed Sep 26 23:26:16 2012
@@ -0,0 +1,26 @@
+## Overview
+
+This is an example of how to use the ActiveMQ 5.x / OpenWire protocol to communicate with Apollo
+
+This example does basic publish-subscribe messaging using Topics
+
+## Prereqs
+
+- Install Java SDK
+- Install [Maven](http://maven.apache.org/download.html)
+
+## Building
+
+Run:
+
+ mvn install
+
+## Running the Examples
+
+In one terminal window run:
+
+ mvn -Psubscriber
+
+In another terminal window run:
+
+ mvn -Ppublisher
Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-topic/src/main/java/example/topic/Publisher.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-topic/src/main/java/example/topic/Publisher.java?rev=1390775&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-topic/src/main/java/example/topic/Publisher.java (added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-topic/src/main/java/example/topic/Publisher.java Wed Sep 26 23:26:16 2012
@@ -0,0 +1,78 @@
+/**
+ * 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.topic;
+
+import example.util.Util;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jms.*;
+
+/**
+ * @author <a href="http://www.christianposta.com/blog">Christian Posta</a>
+ */
+public class Publisher {
+ private static final Logger LOG = LoggerFactory.getLogger(Publisher.class);
+ private static final String BROKER_HOST = "tcp://localhost:%d";
+ private static final int BROKER_PORT = Util.getBrokerPort();
+ private static final String BROKER_URL = String.format(BROKER_HOST, BROKER_PORT);
+ private static final Boolean NON_TRANSACTED = false;
+ private static final int NUM_MESSAGES_TO_SEND = 100;
+ private static final long DELAY = 100;
+
+ public static void main(String[] args) {
+
+ ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("admin", "password", BROKER_URL);
+ Connection connection = null;
+
+ try {
+
+ connection = connectionFactory.createConnection();
+ connection.start();
+
+ Session session = connection.createSession(NON_TRANSACTED, Session.AUTO_ACKNOWLEDGE);
+ Destination destination = session.createTopic("test-topic");
+ MessageProducer producer = session.createProducer(destination);
+
+ for (int i = 0; i < NUM_MESSAGES_TO_SEND; i++) {
+ TextMessage message = session.createTextMessage("Message #" + i);
+ LOG.info("Sending message #" + i);
+ producer.send(message);
+ Thread.sleep(DELAY);
+ }
+
+ // tell the subscribers we're done
+ producer.send(session.createTextMessage("END"));
+
+ producer.close();
+ session.close();
+
+ } catch (Exception e) {
+ LOG.error("Caught exception!", e);
+ }
+ finally {
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (JMSException e) {
+ LOG.error("Could not close an open connection...", e);
+ }
+ }
+ }
+ }
+}
Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-topic/src/main/java/example/topic/Subscriber.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-topic/src/main/java/example/topic/Subscriber.java?rev=1390775&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-topic/src/main/java/example/topic/Subscriber.java (added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-topic/src/main/java/example/topic/Subscriber.java Wed Sep 26 23:26:16 2012
@@ -0,0 +1,96 @@
+/**
+ * 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.topic;
+
+import example.util.Util;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jms.*;
+import java.util.concurrent.CountDownLatch;
+
+/**
+ * @author <a href="http://www.christianposta.com/blog">Christian Posta</a>
+ */
+public class Subscriber implements MessageListener {
+ private static final Logger LOG = LoggerFactory.getLogger(Subscriber.class);
+
+ private static final String BROKER_HOST = "tcp://localhost:%d";
+ private static final int BROKER_PORT = Util.getBrokerPort();
+ private static final String BROKER_URL = String.format(BROKER_HOST, BROKER_PORT);
+ private static final Boolean NON_TRANSACTED = false;
+
+
+ private final CountDownLatch countDownLatch;
+ public Subscriber(CountDownLatch latch) {
+ countDownLatch = latch;
+ }
+
+ public static void main(String[] args) {
+ LOG.info("\nWaiting to receive messages... Either waiting for END message or press Ctrl+C to exit");
+ ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("admin", "password", BROKER_URL);
+ Connection connection = null;
+ final CountDownLatch latch = new CountDownLatch(1);
+
+ try {
+
+ connection = connectionFactory.createConnection();
+ connection.start();
+
+ Session session = connection.createSession(NON_TRANSACTED, Session.AUTO_ACKNOWLEDGE);
+ Destination destination = session.createTopic("test-topic");
+
+ MessageConsumer consumer = session.createConsumer(destination);
+ consumer.setMessageListener(new Subscriber(latch));
+
+ latch.await();
+ consumer.close();
+ session.close();
+
+ } catch (Exception e) {
+ LOG.error("Caught exception!", e);
+ }
+ finally {
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (JMSException e) {
+ LOG.error("Could not close an open connection...", e);
+ }
+ }
+ }
+ }
+
+ @Override
+ public void onMessage(Message message) {
+ try {
+ if (message instanceof TextMessage) {
+ String text = ((TextMessage) message).getText();
+ if ("END".equalsIgnoreCase(text)) {
+ LOG.info("Received END message!");
+ countDownLatch.countDown();
+ }
+ else {
+ LOG.info("Received message:" +text);
+ }
+ }
+ } catch (JMSException e) {
+ LOG.error("Got a JMS Exception!", e);
+ }
+ }
+}
Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-topic/src/main/resources/log4j.properties
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-topic/src/main/resources/log4j.properties?rev=1390775&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-topic/src/main/resources/log4j.properties (added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-topic/src/main/resources/log4j.properties Wed Sep 26 23:26:16 2012
@@ -0,0 +1,37 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+#
+# Setup the default logging levels
+#
+log4j.rootLogger=INFO, console
+
+#
+# Uncomment one of the following to enable debug logging
+#
+#log4j.logger.org.apache.activemq.apollo=TRACE
+#log4j.logger.org.apache.activemq.apollo.openwire=TRACE
+#log4j.logger.org.apache.activemq.apollo.broker=TRACE
+#log4j.logger.org.apache.activemq.apollo.web=TRACE
+#log4j.logger.org.apache.activemq.apollo.cli=TRACE
+#log4j.logger.org.apache.activemq.transport=TRACE
+
+# Console Settings
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+log4j.appender.console.layout=org.apache.log4j.PatternLayout
+log4j.appender.console.layout.ConversionPattern=%C %-5p | %m%n
+log4j.appender.console.threshold=TRACE
Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-transaction/pom.xml
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-transaction/pom.xml?rev=1390775&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-transaction/pom.xml (added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-transaction/pom.xml Wed Sep 26 23:26:16 2012
@@ -0,0 +1,66 @@
+<?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/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>openwire-example</artifactId>
+ <groupId>example</groupId>
+ <version>0.1-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>jms-example-transaction</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>jms-example-util</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+ <profiles>
+ <profile>
+ <id>client</id>
+ <build>
+ <defaultGoal>package</defaultGoal>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>java</goal>
+ </goals>
+ <configuration>
+ <mainClass>example.transaction.Client</mainClass>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+</project>
\ No newline at end of file
Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-transaction/readme.md
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-transaction/readme.md?rev=1390775&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-transaction/readme.md (added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-transaction/readme.md Wed Sep 26 23:26:16 2012
@@ -0,0 +1,25 @@
+## Overview
+
+This is an example of how to use the ActiveMQ 5.x / OpenWire protocol to communicate with Apollo
+
+This example demos using JMS transactions
+
+## Prereqs
+
+- Install Java SDK
+- Install [Maven](http://maven.apache.org/download.html)
+
+## Building
+
+Run:
+
+ mvn install
+
+## Running the Examples
+
+ mvn -Pclient
+
+ You will be greeted with a prompt. You can type a message and press enter. Nothing will actually be sent to
+ a consumer until you type `COMMIT` and press enter. After doing so, you should see the built-in consumer
+ consume the message and output it. If you type `ROLLBACK`, your message will be rolledback and the consumer
+ will not have an opportunity to see it. Hit ^C to exit
Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-transaction/src/main/java/example/transaction/Client.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-transaction/src/main/java/example/transaction/Client.java?rev=1390775&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-transaction/src/main/java/example/transaction/Client.java (added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-transaction/src/main/java/example/transaction/Client.java Wed Sep 26 23:26:16 2012
@@ -0,0 +1,117 @@
+/**
+ * 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.transaction;
+
+import example.util.Util;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.command.ActiveMQTopic;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jms.*;
+import java.util.Scanner;
+
+/**
+ * @author <a href="http://www.christianposta.com/blog">Christian Posta</a>
+ */
+public class Client {
+ private static final Logger LOG = LoggerFactory.getLogger(Client.class);
+ private static final String BROKER_HOST = "tcp://localhost:%d";
+ private static final int BROKER_PORT = Util.getBrokerPort();
+ private static final String BROKER_URL = String.format(BROKER_HOST, BROKER_PORT);
+
+ // this is set to true
+ private static final Boolean TRANSACTED = true;
+ private static final Boolean NON_TRANSACTED = false;
+
+ public static void main(String[] args) {
+
+ ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("admin", "password", BROKER_URL);
+ Connection connection = null;
+
+ try {
+ connection = connectionFactory.createConnection();
+ connection.start();
+ Topic destination = new ActiveMQTopic("transacted.client.example");
+
+ Session senderSession = connection.createSession(TRANSACTED, Session.AUTO_ACKNOWLEDGE);
+ Session receiverSession = connection.createSession(NON_TRANSACTED, Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer receiver = receiverSession.createConsumer(destination);
+ receiver.setMessageListener(new MessageListener() {
+ @Override
+ public void onMessage(Message message) {
+ if (message instanceof TextMessage) {
+ try {
+ String value = ((TextMessage) message).getText();
+ LOG.info("We received a new message: " + value);
+ } catch (JMSException e) {
+ LOG.error("Could not read the receiver's topic because of a JMSException", e);
+ }
+ }
+ }
+ });
+
+ MessageProducer sender = senderSession.createProducer(destination);
+
+
+ connection.start();
+ acceptInputFromUser(senderSession, sender);
+ senderSession.close();
+ receiverSession.close();
+
+ } catch (Exception e) {
+ LOG.error("Caught exception!", e);
+ }
+ finally {
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (JMSException e) {
+ LOG.error("Could not close an open connection...", e);
+ }
+ }
+ }
+ }
+
+ private static void acceptInputFromUser(Session senderSession, MessageProducer sender) throws JMSException {
+ System.out.println("Type a message. Type COMMIT to send to receiver, type ROLLBACK to cancel");
+ Scanner inputReader = new Scanner(System.in);
+
+ while (true) {
+ String line = inputReader.nextLine();
+ if (line == null) {
+ LOG.info("Done!");
+ break;
+ } else if (line.length() > 0) {
+ if (line.trim().equals("ROLLBACK")) {
+ System.out.println("Rolling back...");
+ senderSession.rollback();
+ System.out.println("Messages have been rolledback");
+ } else if (line.trim().equals("COMMIT")) {
+ System.out.println("Committing... ");
+ senderSession.commit();
+ System.out.println("Messages should have been sent");
+ } else {
+ TextMessage message = senderSession.createTextMessage();
+ message.setText(line);
+ System.out.println("Batching up:'" + message.getText() + "'");
+ sender.send(message);
+ }
+ }
+ }
+ }
+}
Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-util/pom.xml
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-util/pom.xml?rev=1390775&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-util/pom.xml (added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-util/pom.xml Wed Sep 26 23:26:16 2012
@@ -0,0 +1,34 @@
+<?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/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>openwire-example</artifactId>
+ <groupId>example</groupId>
+ <version>0.1-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>jms-example-util</artifactId>
+
+
+</project>
\ No newline at end of file
Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-util/src/main/java/example/util/Util.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-util/src/main/java/example/util/Util.java?rev=1390775&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-util/src/main/java/example/util/Util.java (added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-util/src/main/java/example/util/Util.java Wed Sep 26 23:26:16 2012
@@ -0,0 +1,37 @@
+/**
+ * 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.util;
+
+/**
+ * @author <a href="http://www.christianposta.com/blog">Christian Posta</a>
+ */
+public class Util {
+ private static final String DEFAULT_PORT = "61613";
+
+ public static String env(String key, String defaultValue) {
+ String rc = System.getenv(key);
+ if (rc == null) {
+ return defaultValue;
+ } else {
+ return rc;
+ }
+ }
+
+ public static int getBrokerPort() {
+ return Integer.valueOf(Util.env("BROKER_PORT", DEFAULT_PORT));
+ }
+}
Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-wildcard-consumer/pom.xml
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-wildcard-consumer/pom.xml?rev=1390775&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-wildcard-consumer/pom.xml (added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-wildcard-consumer/pom.xml Wed Sep 26 23:26:16 2012
@@ -0,0 +1,64 @@
+<?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/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>openwire-example</artifactId>
+ <groupId>example</groupId>
+ <version>0.1-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>jms-example-wildcard-consumer</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>jms-example-util</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+ <profiles>
+ <profile>
+ <id>consumer</id>
+ <build>
+ <defaultGoal>package</defaultGoal>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>java</goal>
+ </goals>
+ <configuration>
+ <mainClass>example.wildcard.Client</mainClass>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+</project>
\ No newline at end of file
Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-wildcard-consumer/readme.md
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-wildcard-consumer/readme.md?rev=1390775&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-wildcard-consumer/readme.md (added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-wildcard-consumer/readme.md Wed Sep 26 23:26:16 2012
@@ -0,0 +1,31 @@
+## Overview
+
+This is an example of how to use the ActiveMQ 5.x / OpenWire protocol to communicate with Apollo
+
+This example demos using wildcards for consuming messages from hierarchies of destinations
+
+## Prereqs
+
+- Install Java SDK
+- Install [Maven](http://maven.apache.org/download.html)
+
+## Building
+
+Run:
+
+ mvn install
+
+## Running the Examples
+
+ Run one consumer specifying which topicName to produce to (topicName) and what sort of wildcard
+ you'd like to use to listen to that same topic hierarchy (wildcard)
+
+ For example, to publish to "hello.world" topic and listen to "hello.world.*":
+
+ mvn -Pconsumer -DtopicName="hello.world" -Dwildcard=".*"
+
+ You start another consumer that listens to:
+
+ mvn -Pconsumer -DtopicName="hello.world.hungray" -Dwildcard=".*"
+
+ And when you type a message on this prompt, you should see it in the first consumer you started
Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-wildcard-consumer/src/main/java/example/wildcard/Client.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-wildcard-consumer/src/main/java/example/wildcard/Client.java?rev=1390775&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-wildcard-consumer/src/main/java/example/wildcard/Client.java (added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/jms-example-wildcard-consumer/src/main/java/example/wildcard/Client.java Wed Sep 26 23:26:16 2012
@@ -0,0 +1,112 @@
+/**
+ * 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.wildcard;
+
+import example.util.Util;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.command.ActiveMQTopic;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jms.*;
+import java.util.Scanner;
+
+/**
+ * @author <a href="http://www.christianposta.com/blog">Christian Posta</a>
+ */
+public class Client {
+ private static final Logger LOG = LoggerFactory.getLogger(Client.class);
+ private static final Boolean NON_TRANSACTED = false;
+ private static final String BROKER_HOST = "tcp://localhost:%d";
+ private static final int BROKER_PORT = Util.getBrokerPort();
+ private static final String BROKER_URL = String.format(BROKER_HOST, BROKER_PORT);
+
+ public static void main(String[] args) {
+
+ ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("admin", "password", BROKER_URL);
+ Connection connection = null;
+
+ try {
+ Topic senderTopic = new ActiveMQTopic(System.getProperty("topicName"));
+
+ connection = connectionFactory.createConnection("admin", "password");
+
+ Session senderSession = connection.createSession(NON_TRANSACTED, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer sender = senderSession.createProducer(senderTopic);
+
+ Session receiverSession = connection.createSession(NON_TRANSACTED, Session.AUTO_ACKNOWLEDGE);
+
+ String policyType = System.getProperty("wildcard", ".*");
+ String receiverTopicName = senderTopic.getTopicName() + policyType;
+ Topic receiverTopic = receiverSession.createTopic(receiverTopicName);
+
+ MessageConsumer receiver = receiverSession.createConsumer(receiverTopic);
+ receiver.setMessageListener(new MessageListener() {
+ public void onMessage(Message message) {
+ try {
+ if (message instanceof TextMessage) {
+ String text = ((TextMessage) message).getText();
+ LOG.info("We received a new message: " + text);
+ }
+ } catch (JMSException e) {
+ LOG.error("Could not read the receiver's topic because of a JMSException", e);
+ }
+ }
+ });
+
+ connection.start();
+ System.out.println("Listening on '" + receiverTopicName + "'");
+ System.out.println("Enter a message to send: ");
+
+ Scanner inputReader = new Scanner(System.in);
+
+ while (true) {
+ String line = inputReader.nextLine();
+ if (line == null) {
+ LOG.info("Done!");
+ break;
+ } else if (line.length() > 0) {
+ try {
+ TextMessage message = senderSession.createTextMessage();
+ message.setText(line);
+ LOG.info("Sending a message: " + message.getText());
+ sender.send(message);
+ } catch (JMSException e) {
+ LOG.error("Exception during publishing a message: ", e);
+ }
+ }
+ }
+
+ receiver.close();
+ receiverSession.close();
+ sender.close();
+ senderSession.close();
+
+ } catch (Exception e) {
+ LOG.error("Caught exception!", e);
+ } finally {
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (JMSException e) {
+ LOG.error("When trying to close connection: ", e);
+ }
+ }
+ }
+
+ }
+}
Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/pom.xml
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/pom.xml?rev=1390775&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/pom.xml (added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/pom.xml Wed Sep 26 23:26:16 2012
@@ -0,0 +1,89 @@
+<?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>openwire-example</artifactId>
+ <packaging>pom</packaging>
+ <version>0.1-SNAPSHOT</version>
+ <modules>
+ <module>jms-example-queue</module>
+ <module>jms-example-topic</module>
+ <module>jms-example-exclusive-consumer</module>
+ <module>jms-example-transaction</module>
+ <module>jms-example-util</module>
+ <module>jms-example-durable-sub</module>
+ <module>jms-example-wildcard-consumer</module>
+ <module>jms-example-temp-destinations</module>
+ <module>jms-example-message-browser</module>
+ <module>jms-example-queue-selector</module>
+ <module>jms-example-composite-destinations</module>
+ </modules>
+
+ <name>OpenWire example</name>
+ <description>Apollo OpenWire Java Examples</description>
+
+ <properties>
+ <activemq.version>5.6.0</activemq.version>
+ </properties>
+
+ <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.activemq</groupId>
+ <artifactId>activemq-core</artifactId>
+ <version>${activemq.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.6.4</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>
+ </plugins>
+ </build>
+
+</project>
+
Propchange: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/pom.xml
------------------------------------------------------------------------------
svn:executable = *
Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/readme.md
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/readme.md?rev=1390775&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/readme.md (added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/openwire/readme.md Wed Sep 26 23:26:16 2012
@@ -0,0 +1,19 @@
+## Overview
+
+This is an example of how use the OpenWire Java implementation with Apollo.
+
+## Prereqs
+
+- Install Java SDK
+- Install [Maven](http://maven.apache.org/download.html)
+
+## Building
+
+Run:
+
+ mvn install
+
+## Running the Examples
+
+All of these examples require an externally running Apollo broker with a tcp connector
+listening on port 61613
\ No newline at end of file