http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/message-group/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/message-group/pom.xml b/examples/jms/message-group/pom.xml deleted file mode 100644 index cfd354c..0000000 --- a/examples/jms/message-group/pom.xml +++ /dev/null @@ -1,118 +0,0 @@ -<?xml version='1.0'?> -<!-- -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> - - <parent> - <groupId>org.apache.activemq.examples.jms</groupId> - <artifactId>jms-examples</artifactId> - <version>1.0.1-SNAPSHOT</version> - </parent> - - <artifactId>message-group</artifactId> - <packaging>jar</packaging> - <name>ActiveMQ Artemis JMS Message Group Example</name> - - <properties> - <activemq.basedir>${project.basedir}/../../..</activemq.basedir> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-jms-client</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - - <profiles> - <profile> - <!-- specify -PnoServer if you don't want to start the server --> - <id>noServer</id> - <properties> - <noServer>true</noServer> - </properties> - </profile> - </profiles> - <build> - <plugins> - <plugin> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-maven-plugin</artifactId> - <executions> - <execution> - <id>create</id> - <goals> - <goal>create</goal> - </goals> - <configuration> - <ignore>${noServer}</ignore> - </configuration> - </execution> - <execution> - <id>start</id> - <goals> - <goal>cli</goal> - </goals> - <configuration> - <ignore>${noServer}</ignore> - <spawn>true</spawn> - <testURI>tcp://localhost:61616</testURI> - <args> - <param>run</param> - </args> - </configuration> - </execution> - <execution> - <id>runClient</id> - <goals> - <goal>runClient</goal> - </goals> - <configuration> - <clientClass>org.apache.activemq.artemis.jms.example.MessageGroupExample</clientClass> - </configuration> - </execution> - <execution> - <id>stop</id> - <goals> - <goal>cli</goal> - </goals> - <configuration> - <ignore>${noServer}</ignore> - <args> - <param>stop</param> - </args> - </configuration> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>org.apache.activemq.examples.jms</groupId> - <artifactId>message-group</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - </plugin> - </plugins> - </build> - -</project>
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/message-group/readme.html ---------------------------------------------------------------------- diff --git a/examples/jms/message-group/readme.html b/examples/jms/message-group/readme.html deleted file mode 100644 index 3513e8e..0000000 --- a/examples/jms/message-group/readme.html +++ /dev/null @@ -1,152 +0,0 @@ -<!-- -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. ---> - -<html> - <head> - <title>ActiveMQ Artemis Message Group Example</title> - <link rel="stylesheet" type="text/css" href="../common/common.css" /> - <link rel="stylesheet" type="text/css" href="../common/prettify.css" /> - <script type="text/javascript" src="../common/prettify.js"></script> - </head> - <body onload="prettyPrint()"> - <h1>Message Group Example</h1> - - <pre>To run the example, simply type <b>mvn verify</b> from this directory, <br>or <b>mvn -PnoServer verify</b> if you want to start and create the server manually.</pre> - - <p>This example shows you how to configure and use message groups with ActiveMQ Artemis.</p> - - <p>Message groups are sets of messages that has the following characteristics: </p> - <li>Messages in a message group share the same group id, i.e. they have same JMSXGroupID string property values.</li> - <li>Messages in a message group will be all delivered to no more than one of the queue's consumers. The consumer that receives the - first message of a group will receive all the messages that belong to the group.</li> - - <p>You can make any message belong to a message group by setting its 'JMXGroupID' string property to the group id. - In this example we create a message group 'Group-0'. And make such a message group of 10 messages. It also create two consumers on the queue - where the 10 'Group-0' group messages are to be sent. You can see that with message grouping enabled, all the 10 messages will be received by - the first consumer. The second consumer will receive none. </p> - - <p>Alternatively, ActiveMQ's connection factories can be configured to <em>auto group</em> messages. By setting <code>autogroup</code> to </code>true</code> on the <code>ActiveMQConnectionFactory</code> - (or setting <code><autogroup>true</autogroup></code> in <code>activemq-jms.xml</code>'s connection factory settings), a random unique id - will be picked to create a message group. <em>Every messages</em> sent by a producer created from this connection factory will automatically - be part of this message group.</p> - - <h2>Example step-by-step</h2> - - <ol> - <li>First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the <code>client-jndi.properties</code> file in the directory <code>../common/config</code></li> - <pre class="prettyprint"> - <code>InitialContext initialContext = getContext();</code> - </pre> - - <li>We look-up the JMS queue object from JNDI</li> - <pre class="prettyprint"> - <code>Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");</code> - </pre> - - <li>We look-up the JMS connection factory object from JNDI</li> - <pre class="prettyprint"> - <code>ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");</code> - </pre> - - <li>We create a JMS connection</li> - <pre class="prettyprint"> - <code>connection = cf.createConnection();</code> - </pre> - - <li>We create a JMS session. The session is created as non transacted and will auto acknowledge messages.</li> - <pre class="prettyprint"> - <code>Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);</code> - </pre> - - <li>We create a JMS message producer on the session. This will be used to send the messages.</li> - <pre class="prettyprint"> - <code>MessageProducer messageProducer = session.createProducer(topic);</code> - </pre> - - <li>We create two consumers.</li> - <pre class="prettyprint"> - <code> - MessageConsumer consumer1 = session.createConsumer(queue); - consumer1.setMessageListener(new SimpleMessageListener("consumer-1")); - MessageConsumer consumer2 = session.createConsumer(queue); - consumer2.setMessageListener(new SimpleMessageListener("consumer-2")); - </code> - </pre> - - <li>We create and send 10 text messages with group id 'Group-0'</li> - <pre class="prettyprint"> - <code> - int msgCount = 10; - TextMessage[] groupMessages = new TextMessage[msgCount]; - for (int i = 0; i < msgCount; i++) - { - groupMessages[i] = session.createTextMessage("Group-0 message " + i); - groupMessages[i].setStringProperty("JMSXGroupID", "Group-0"); - producer.send(groupMessages[i]); - System.out.println("Sent message: " + groupMessages[i].getText()); - } - </code> - </pre> - - <li>We start the connection.</li> - <pre class="prettyprint"> - <code>connection.start();</code> - </pre> - - <li>We check the group messages are received by only one consumer</li> - <pre class="prettyprint"> - <code> - String trueReceiver = messageReceiverMap.get(groupMessages[0].getText()); - for (TextMessage grpMsg : groupMessages) - { - String receiver = messageReceiverMap.get(grpMsg.getText()); - if (!trueReceiver.equals(receiver)) - { - System.out.println("Group message [" + grpMsg.getText() + "[ went to wrong receiver: " + receiver); - result = false; - } - } - </code> - </pre> - - <li>And finally, <b>always</b> remember to close your JMS connections and resources after use, in a <code>finally</code> block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects</li> - - <pre class="prettyprint"> - <code>finally - { - if (initialContext != null) - { - initialContext.close(); - } - if (connection != null) - { - connection.close(); - } - }</code> - </pre> - </ol> - - <h2>More information</h2> - - <ul> - <li>User Manual's <a href="../../../docs/user-manual/en/html_single/index.html#message-grouping">Message Grouping chapter</a></li> - </ul> - - </body> -</html> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/message-group/src/main/java/org/apache/activemq/artemis/jms/example/MessageGroupExample.java ---------------------------------------------------------------------- diff --git a/examples/jms/message-group/src/main/java/org/apache/activemq/artemis/jms/example/MessageGroupExample.java b/examples/jms/message-group/src/main/java/org/apache/activemq/artemis/jms/example/MessageGroupExample.java deleted file mode 100644 index c614860..0000000 --- a/examples/jms/message-group/src/main/java/org/apache/activemq/artemis/jms/example/MessageGroupExample.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * 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.activemq.artemis.jms.example; - -import javax.jms.Connection; -import javax.jms.JMSException; -import javax.jms.Message; -import javax.jms.MessageConsumer; -import javax.jms.MessageListener; -import javax.jms.MessageProducer; -import javax.jms.Queue; -import javax.jms.Session; -import javax.jms.TextMessage; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; -import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; - -/** - * A simple JMS Queue example that sends and receives message groups. - */ -public class MessageGroupExample { - - public static void main(final String[] args) throws Exception { - final Map<String, String> messageReceiverMap = new ConcurrentHashMap<String, String>(); - Connection connection = null; - try { - - // Step 2. Perform a lookup on the queue - Queue queue = ActiveMQJMSClient.createQueue("queue/exampleQueue"); - - // Step 3. Perform a lookup on the Connection Factory - ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(); - - // Step 4. Create a JMS Connection - connection = cf.createConnection(); - - // Step 5. Create a JMS Session - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - - // Step 6. Create a JMS Message Producer - MessageProducer producer = session.createProducer(queue); - - // Step 7. Create two consumers - MessageConsumer consumer1 = session.createConsumer(queue); - consumer1.setMessageListener(new SimpleMessageListener("consumer-1", messageReceiverMap)); - MessageConsumer consumer2 = session.createConsumer(queue); - consumer2.setMessageListener(new SimpleMessageListener("consumer-2", messageReceiverMap)); - - // Step 8. Create and send 10 text messages with group id 'Group-0' - int msgCount = 10; - TextMessage[] groupMessages = new TextMessage[msgCount]; - for (int i = 0; i < msgCount; i++) { - groupMessages[i] = session.createTextMessage("Group-0 message " + i); - groupMessages[i].setStringProperty("JMSXGroupID", "Group-0"); - producer.send(groupMessages[i]); - System.out.println("Sent message: " + groupMessages[i].getText()); - } - - System.out.println("all messages are sent"); - - // Step 9. Start the connection - connection.start(); - - Thread.sleep(2000); - - // Step 10. check the group messages are received by only one consumer - String trueReceiver = messageReceiverMap.get(groupMessages[0].getText()); - for (TextMessage grpMsg : groupMessages) { - String receiver = messageReceiverMap.get(grpMsg.getText()); - if (!trueReceiver.equals(receiver)) { - throw new IllegalStateException("Group message [" + grpMsg.getText() + "[ went to wrong receiver: " + receiver); - } - } - - cf.close(); - } - finally { - // Step 11. Be sure to close our JMS resources! - if (connection != null) { - connection.close(); - } - } - } -} - -class SimpleMessageListener implements MessageListener { - - private final String name; - private final Map<String, String> messageReceiverMap; - - public SimpleMessageListener(final String listenerName, Map<String, String> messageReceiverMap) { - name = listenerName; - this.messageReceiverMap = messageReceiverMap; - } - - public void onMessage(final Message message) { - try { - TextMessage msg = (TextMessage) message; - System.out.format("Message: [%s] received by %s%n", msg.getText(), name); - messageReceiverMap.put(msg.getText(), name); - } - catch (JMSException e) { - e.printStackTrace(); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/message-group/src/main/resources/jndi.properties ---------------------------------------------------------------------- diff --git a/examples/jms/message-group/src/main/resources/jndi.properties b/examples/jms/message-group/src/main/resources/jndi.properties deleted file mode 100644 index 93537c4..0000000 --- a/examples/jms/message-group/src/main/resources/jndi.properties +++ /dev/null @@ -1,20 +0,0 @@ -# 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. - -java.naming.factory.initial=org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory -connectionFactory.ConnectionFactory=tcp://localhost:61616 -queue.queue/exampleQueue=exampleQueue http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/message-group2/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/message-group2/pom.xml b/examples/jms/message-group2/pom.xml deleted file mode 100644 index 46eed3a..0000000 --- a/examples/jms/message-group2/pom.xml +++ /dev/null @@ -1,118 +0,0 @@ -<?xml version='1.0'?> -<!-- -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> - - <parent> - <groupId>org.apache.activemq.examples.jms</groupId> - <artifactId>jms-examples</artifactId> - <version>1.0.1-SNAPSHOT</version> - </parent> - - <artifactId>message-group2</artifactId> - <packaging>jar</packaging> - <name>ActiveMQ Artemis JMS Message Group Example 2</name> - - <properties> - <activemq.basedir>${project.basedir}/../../..</activemq.basedir> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-jms-client</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - - <profiles> - <profile> - <!-- specify -PnoServer if you don't want to start the server --> - <id>noServer</id> - <properties> - <noServer>true</noServer> - </properties> - </profile> - </profiles> - <build> - <plugins> - <plugin> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-maven-plugin</artifactId> - <executions> - <execution> - <id>create</id> - <goals> - <goal>create</goal> - </goals> - <configuration> - <ignore>${noServer}</ignore> - </configuration> - </execution> - <execution> - <id>start</id> - <goals> - <goal>cli</goal> - </goals> - <configuration> - <ignore>${noServer}</ignore> - <spawn>true</spawn> - <testURI>tcp://localhost:61616</testURI> - <args> - <param>run</param> - </args> - </configuration> - </execution> - <execution> - <id>runClient</id> - <goals> - <goal>runClient</goal> - </goals> - <configuration> - <clientClass>org.apache.activemq.artemis.jms.example.MessageGroup2Example</clientClass> - </configuration> - </execution> - <execution> - <id>stop</id> - <goals> - <goal>cli</goal> - </goals> - <configuration> - <ignore>${noServer}</ignore> - <args> - <param>stop</param> - </args> - </configuration> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>org.apache.activemq.examples.jms</groupId> - <artifactId>message-group2</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - </plugin> - </plugins> - </build> - -</project> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/message-group2/readme.html ---------------------------------------------------------------------- diff --git a/examples/jms/message-group2/readme.html b/examples/jms/message-group2/readme.html deleted file mode 100644 index 911852c..0000000 --- a/examples/jms/message-group2/readme.html +++ /dev/null @@ -1,161 +0,0 @@ -<!-- -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. ---> - -<html> - <head> - <title>ActiveMQ Artemis Message Group Example</title> - <link rel="stylesheet" type="text/css" href="../common/common.css" /> - <link rel="stylesheet" type="text/css" href="../common/prettify.css" /> - <script type="text/javascript" src="../common/prettify.js"></script> - </head> - <body onload="prettyPrint()"> - <h1>Message Group Example</h1> - - <pre>To run the example, simply type <b>mvn verify</b> from this directory, <br>or <b>mvn -PnoServer verify</b> if you want to start and create the server manually.</pre> - - - <p>This example shows you how to configure and use message groups via a connection factory with ActiveMQ Artemis.</p> - - <p>Message groups are sets of messages that has the following characteristics: </p> - <li>Messages in a message group share the same group id, i.e. they have same JMSXGroupID string property values.</li> - <li>Messages in a message group will be all delivered to no more than one of the queue's consumers. The consumer that receives the - first message of a group will receive all the messages that belongs to the group.</li> - - <p>You can make any message belong to a message group by setting a 'group-id' on the connection factory. All producers created via this connection factory will set that group id on its messages. - In this example we set the group id 'Group-0'on a connection factory and send messages via 2 different producers and check that only 1 consumer receives them. </p> - - <p>Alternatively, ActiveMQ's connection factories can be configured to <em>auto group</em> messages. By setting <code>autogroup</code> to </code>true</code> on the <code>ActiveMQConnectionFactory</code> - (or setting <code><autogroup>true</autogroup></code> in <code>activemq-jms.xml</code>'s connection factory settings), a random unique id - will be picked to create a message group. <em>Every messages</em> sent by a producer created from this connection factory will automatically - be part of this message group.</p> - - <h2>Example step-by-step</h2> - <ol> - <li>First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the <code>client-jndi.properties</code> file in the directory <code>../common/config</code></li> - <pre class="prettyprint"> - <code>InitialContext initialContext = getContext();</code> - </pre> - - <li>We look-up the JMS queue object from JNDI</li> - <pre class="prettyprint"> - <code>Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");</code> - </pre> - - <li>We look-up the JMS connection factory object from JNDI</li> - <pre class="prettyprint"> - <code>ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");</code> - </pre> - - <li>We create a JMS connection</li> - <pre class="prettyprint"> - <code>connection = cf.createConnection();</code> - </pre> - - <li>We create a JMS session. The session is created as non transacted and will auto acknowledge messages.</li> - <pre class="prettyprint"> - <code>Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);</code> - </pre> - - <li>We create 2 JMS message producers on the session. This will be used to send the messages.</li> - <pre class="prettyprint"> - <code> - MessageProducer producer1 = session.createProducer(queue); - - MessageProducer producer2 = session.createProducer(queue);</code> - </pre> - - <li>We create two consumers.</li> - <pre class="prettyprint"> - <code> - MessageConsumer consumer1 = session.createConsumer(queue); - consumer1.setMessageListener(new SimpleMessageListener("consumer-1")); - MessageConsumer consumer2 = session.createConsumer(queue); - consumer2.setMessageListener(new SimpleMessageListener("consumer-2")); - </code> - </pre> - - <li>We create and send 10 text messages using each producer</li> - <pre class="prettyprint"> - <code> - int msgCount = 10; - for (int i = 0; i < msgCount; i++) - { - TextMessage m = session.createTextMessage("producer1 message " + i); - producer1.send(m); - System.out.println("Sent message: " + m.getText()); - TextMessage m2 = session.createTextMessage("producer2 message " + i); - producer2.send(m2); - System.out.println("Sent message: " + m2.getText()); - } - </code> - </pre> - - <li>We start the connection.</li> - <pre class="prettyprint"> - <code>connection.start();</code> - </pre> - - <li>We check the group messages are received by only one consumer</li> - <pre class="prettyprint"> - <code> - String trueReceiver = messageReceiverMap.get("producer1 message " + 0); - for (int i = 0; i < msgCount; i++) - { - String receiver = messageReceiverMap.get("producer1 message " + i); - if (!trueReceiver.equals(receiver)) - { - System.out.println("Group message [producer1 message " + i + "] went to wrong receiver: " + receiver); - result = false; - } - receiver = messageReceiverMap.get("producer2 message " + i); - if (!trueReceiver.equals(receiver)) - { - System.out.println("Group message [producer2 message " + i + "] went to wrong receiver: " + receiver); - result = false; - } - } - - </code> - </pre> - - <li>And finally, <b>always</b> remember to close your JMS connections and resources after use, in a <code>finally</code> block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects</li> - - <pre class="prettyprint"> - <code>finally - { - if (initialContext != null) - { - initialContext.close(); - } - if (connection != null) - { - connection.close(); - } - }</code> - </pre> - </ol> - - <h2>More information</h2> - - <ul> - <li>User Manual's <a href="../../../docs/user-manual/en/html_single/index.html#message-grouping2">Message Grouping chapter</a></li> - </ul> - - </body> -</html> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/message-group2/src/main/java/org/apache/activemq/artemis/jms/example/MessageGroup2Example.java ---------------------------------------------------------------------- diff --git a/examples/jms/message-group2/src/main/java/org/apache/activemq/artemis/jms/example/MessageGroup2Example.java b/examples/jms/message-group2/src/main/java/org/apache/activemq/artemis/jms/example/MessageGroup2Example.java deleted file mode 100644 index a2164cf..0000000 --- a/examples/jms/message-group2/src/main/java/org/apache/activemq/artemis/jms/example/MessageGroup2Example.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * 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.activemq.artemis.jms.example; - -import javax.jms.Connection; -import javax.jms.JMSException; -import javax.jms.Message; -import javax.jms.MessageConsumer; -import javax.jms.MessageListener; -import javax.jms.MessageProducer; -import javax.jms.Queue; -import javax.jms.Session; -import javax.jms.TextMessage; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; -import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; - -/** - * A simple JMS Queue example that sends and receives message groups. - */ -public class MessageGroup2Example { - - private boolean result = true; - - public static void main(String[] args) throws Exception { - final Map<String, String> messageReceiverMap = new ConcurrentHashMap<String, String>(); - Connection connection = null; - try { - //Step 2. Perform a lookup on the queue - Queue queue = ActiveMQJMSClient.createQueue("exampleQueue"); - - //Step 3. Perform a lookup on the Connection Factory - ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616?groupID=Group-0"); - - //Step 4. Create a JMS Connection - connection = cf.createConnection(); - - //Step 5. Create a JMS Session - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - - //Step 6. Create 2 JMS Message Producers - MessageProducer producer1 = session.createProducer(queue); - - MessageProducer producer2 = session.createProducer(queue); - - //Step 7. Create two consumers - MessageConsumer consumer1 = session.createConsumer(queue); - consumer1.setMessageListener(new SimpleMessageListener("consumer-1", messageReceiverMap)); - MessageConsumer consumer2 = session.createConsumer(queue); - consumer2.setMessageListener(new SimpleMessageListener("consumer-2", messageReceiverMap)); - - //Step 8. Create and send 10 text messages with each producer - int msgCount = 10; - for (int i = 0; i < msgCount; i++) { - TextMessage m = session.createTextMessage("producer1 message " + i); - producer1.send(m); - System.out.println("Sent message: " + m.getText()); - TextMessage m2 = session.createTextMessage("producer2 message " + i); - producer2.send(m2); - System.out.println("Sent message: " + m2.getText()); - } - - System.out.println("all messages are sent"); - - //Step 9. Start the connection - connection.start(); - - Thread.sleep(2000); - - //Step 10. check the group messages are received by only one consumer - - String trueReceiver = messageReceiverMap.get("producer1 message " + 0); - for (int i = 0; i < msgCount; i++) { - String receiver = messageReceiverMap.get("producer1 message " + i); - if (!trueReceiver.equals(receiver)) { - throw new IllegalStateException("Group message [producer1 message " + i + "] went to wrong receiver: " + receiver); - } - receiver = messageReceiverMap.get("producer2 message " + i); - if (!trueReceiver.equals(receiver)) { - throw new IllegalStateException("Group message [producer2 message " + i + "] went to wrong receiver: " + receiver); - } - } - } - finally { - //Step 11. Be sure to close our JMS resources! - if (connection != null) { - connection.close(); - } - } - } -} - -class SimpleMessageListener implements MessageListener { - - private final String name; - final Map<String, String> messageReceiverMap; - - public SimpleMessageListener(String listenerName, Map<String, String> messageReceiverMap) { - name = listenerName; - this.messageReceiverMap = messageReceiverMap; - } - - public void onMessage(Message message) { - try { - TextMessage msg = (TextMessage) message; - System.out.format("Message: [%s] received by %s%n", msg.getText(), name); - messageReceiverMap.put(msg.getText(), name); - } - catch (JMSException e) { - e.printStackTrace(); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/message-priority/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/message-priority/pom.xml b/examples/jms/message-priority/pom.xml deleted file mode 100644 index b7a4d05..0000000 --- a/examples/jms/message-priority/pom.xml +++ /dev/null @@ -1,118 +0,0 @@ -<?xml version='1.0'?> -<!-- -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> - - <parent> - <groupId>org.apache.activemq.examples.jms</groupId> - <artifactId>jms-examples</artifactId> - <version>1.0.1-SNAPSHOT</version> - </parent> - - <artifactId>message-priority</artifactId> - <packaging>jar</packaging> - <name>ActiveMQ Artemis JMS MessagePriorityExample Example</name> - - <properties> - <activemq.basedir>${project.basedir}/../../..</activemq.basedir> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-jms-client</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - - <profiles> - <profile> - <!-- specify -PnoServer if you don't want to start the server --> - <id>noServer</id> - <properties> - <noServer>true</noServer> - </properties> - </profile> - </profiles> - <build> - <plugins> - <plugin> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-maven-plugin</artifactId> - <executions> - <execution> - <id>create</id> - <goals> - <goal>create</goal> - </goals> - <configuration> - <ignore>${noServer}</ignore> - </configuration> - </execution> - <execution> - <id>start</id> - <goals> - <goal>cli</goal> - </goals> - <configuration> - <ignore>${noServer}</ignore> - <spawn>true</spawn> - <testURI>tcp://localhost:61616</testURI> - <args> - <param>run</param> - </args> - </configuration> - </execution> - <execution> - <id>runClient</id> - <goals> - <goal>runClient</goal> - </goals> - <configuration> - <clientClass>org.apache.activemq.artemis.jms.example.MessagePriorityExample</clientClass> - </configuration> - </execution> - <execution> - <id>stop</id> - <goals> - <goal>cli</goal> - </goals> - <configuration> - <ignore>${noServer}</ignore> - <args> - <param>stop</param> - </args> - </configuration> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>org.apache.activemq.examples.jms</groupId> - <artifactId>message-priority</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - </plugin> - </plugins> - </build> - -</project> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/message-priority/readme.html ---------------------------------------------------------------------- diff --git a/examples/jms/message-priority/readme.html b/examples/jms/message-priority/readme.html deleted file mode 100644 index 9dd995c..0000000 --- a/examples/jms/message-priority/readme.html +++ /dev/null @@ -1,159 +0,0 @@ -<!-- -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. ---> - -<html> - <head> - <title>ActiveMQ Artemis JMS Message Priority Example</title> - <link rel="stylesheet" type="text/css" href="../common/common.css" /> - <link rel="stylesheet" type="text/css" href="../common/prettify.css" /> - <script type="text/javascript" src="../common/prettify.js"></script> - </head> - <body onload="prettyPrint()"> - <h1>JMS Message Priority Example</h1> - - <pre>To run the example, simply type <b>mvn verify</b> from this directory, <br>or <b>mvn -PnoServer verify</b> if you want to start and create the server manually.</pre> - - - <p>This example shows how messages with different priorities are delivered in different orders.</p> - - <p>The Message Priority property carries the delivery preference of sent messages. It can be set by the message's - standard header field 'JMSPriority' as defined in JMS specification version 1.1. The value is of type - integer, ranging from 0 (the lowest) to 9 (the highest). When messages are being delivered, their priorities - will effect their order of delivery. Messages of higher priorities will likely be delivered before those - of lower priorities. Messages of equal priorities are delivered in the natural order of their arrival at - their destinations. Please consult the JMS 1.1 specification for full details.</p> - - <p>In this example, three messages are sent to a queue with different priorities. The first message is sent - with default priority (4), the second is sent with a higher priority (5), and the third has the highest - priority (9). At the receiving end, we will show the order of receiving of the three messages. You will - see that the third message, though last sent, will 'jump' forward to be the first one received. The second - is also received ahead of the message first sent, but behind the third message. The first message, regardless - of its being sent first, arrives last.</p> - - <h2>Example step-by-step</h2> - <p><i>To run the example, simply type <code>mvn verify -Pexample</code> from this directory</i></p> - - <ol> - <li>First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the <code>client-jndi.properties</code> file in the directory <code>../common/config</code></li> - <pre class="prettyprint"> - <code>InitialContext initialContext = getContext();</code> - </pre> - - <li>We look-up the JMS queue object from JNDI</li> - <pre class="prettyprint"> - <code>Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");</code> - </pre> - - <li>We look-up the JMS connection factory object from JNDI</li> - <pre class="prettyprint"> - <code>ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");</code> - </pre> - - <li>We create a JMS connection</li> - <pre class="prettyprint"> - <code>connection = cf.createConnection();</code> - </pre> - - <li>We create a JMS session. The session is created as non transacted and will auto acknowledge messages.</li> - <pre class="prettyprint"> - <code>Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);</code> - </pre> - - <li>We create a JMS message producer on the session. This will be used to send the messages.</li> - <pre class="prettyprint"> - <code>MessageProducer messageProducer = session.createProducer(topic);</code> - </pre> - - <li>We Create a JMS Message Consumer.</li> - <pre class="prettyprint"> - <code> - MessageConsumer redConsumer = session.createConsumer(queue); - redConsumer.setMessageListener(new SimpleMessageListener()); - </code> - </pre> - - <li>We Create three messages.</li> - <pre class="prettyprint"> - <code> - TextMessage[] sentMessages = new TextMessage[3]; - sentMessages[0] = session.createTextMessage("first message"); - sentMessages[1] = session.createTextMessage("second message"); - sentMessages[2] = session.createTextMessage("third message"); - </code> - </pre> - - <li>Send the Messages, each has a different priority.</li> - <pre class="prettyprint"> - <code> - producer.send(sentMessages[0]); - System.out.println("Message sent: " + sentMessages[0].getText() + " with priority: " + sentMessages[0].getJMSPriority()); - producer.send(sentMessages[1], DeliveryMode.NON_PERSISTENT, 5, 0); - System.out.println("Message sent: " + sentMessages[1].getText() + "with priority: " + sentMessages[1].getJMSPriority()); - producer.send(sentMessages[2], DeliveryMode.NON_PERSISTENT, 9, 0); - System.out.println("Message sent: " + sentMessages[2].getText() + "with priority: " + sentMessages[2].getJMSPriority()); - </code> - </pre> - - <li>We start the connection now.</li> - <pre class="prettyprint"> - <code> - connection.start(); - </code> - </pre> - - <li>We wait for message delivery completion</li> - <pre class="prettyprint"> - <code> - Thread.sleep(5000); - </code> - </pre> - - <li>We wait for message delivery completion</li> - <pre class="prettyprint"> - <code> - for (int i = 0; i < 3; i++) - { - TextMessage rm = msgReceived.get(i); - if (!rm.getText().equals(sentMessages[2-i].getText())) - { - System.err.println("Priority is broken!"); - result = false; - } - } - </code> - </pre> - - <li>And finally, <b>always</b> remember to close your JMS connections and resources after use, in a <code>finally</code> block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects</li> - - <pre class="prettyprint"> - <code>finally - { - if (initialContext != null) - { - initialContext.close(); - } - if (connection != null) - { - connection.close(); - } - }</code> - </pre> - </ol> - </body> -</html> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/message-priority/src/main/java/org/apache/activemq/artemis/jms/example/MessagePriorityExample.java ---------------------------------------------------------------------- diff --git a/examples/jms/message-priority/src/main/java/org/apache/activemq/artemis/jms/example/MessagePriorityExample.java b/examples/jms/message-priority/src/main/java/org/apache/activemq/artemis/jms/example/MessagePriorityExample.java deleted file mode 100644 index f54e5ed..0000000 --- a/examples/jms/message-priority/src/main/java/org/apache/activemq/artemis/jms/example/MessagePriorityExample.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * 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.activemq.artemis.jms.example; - -import java.util.ArrayList; -import java.util.concurrent.atomic.AtomicBoolean; - -import javax.jms.Connection; -import javax.jms.ConnectionFactory; -import javax.jms.DeliveryMode; -import javax.jms.JMSException; -import javax.jms.Message; -import javax.jms.MessageConsumer; -import javax.jms.MessageListener; -import javax.jms.MessageProducer; -import javax.jms.Queue; -import javax.jms.Session; -import javax.jms.TextMessage; -import javax.naming.InitialContext; - -import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; -import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; - -/** - * A simple JMS example that shows the delivery order of messages with priorities. - */ -public class MessagePriorityExample { - - public static void main(final String[] args) throws Exception { - AtomicBoolean result = new AtomicBoolean(true); - final ArrayList<TextMessage> msgReceived = new ArrayList<TextMessage>(); - Connection connection = null; - try { - - // Step 2. look-up the JMS queue object from JNDI - Queue queue = ActiveMQJMSClient.createQueue("exampleQueue"); - - // Step 3. look-up the JMS connection factory object from JNDI - ConnectionFactory cf = new ActiveMQConnectionFactory(); - - // Step 4. Create a JMS Connection - connection = cf.createConnection(); - - // Step 5. Create a JMS Session - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - - // Step 6. Create a JMS Message Producer - MessageProducer producer = session.createProducer(queue); - - // Step 7. Create a JMS Message Consumer - MessageConsumer redConsumer = session.createConsumer(queue); - redConsumer.setMessageListener(new SimpleMessageListener(msgReceived, result)); - - // Step 8. Create three messages - TextMessage[] sentMessages = new TextMessage[3]; - sentMessages[0] = session.createTextMessage("first message"); - sentMessages[1] = session.createTextMessage("second message"); - sentMessages[2] = session.createTextMessage("third message"); - - // Step 9. Send the Messages, each has a different priority - producer.send(sentMessages[0]); - System.out.println("Message sent: " + sentMessages[0].getText() + - " with priority: " + - sentMessages[0].getJMSPriority()); - producer.send(sentMessages[1], DeliveryMode.NON_PERSISTENT, 5, 0); - System.out.println("Message sent: " + sentMessages[1].getText() + - "with priority: " + - sentMessages[1].getJMSPriority()); - producer.send(sentMessages[2], DeliveryMode.NON_PERSISTENT, 9, 0); - System.out.println("Message sent: " + sentMessages[2].getText() + - "with priority: " + - sentMessages[2].getJMSPriority()); - - // Step 10. Start the connection now. - connection.start(); - - // Step 11. Wait for message delivery completion - Thread.sleep(5000); - - // Step 12. Examine the order - for (int i = 0; i < 3; i++) { - TextMessage rm = msgReceived.get(i); - if (!rm.getText().equals(sentMessages[2 - i].getText())) { - throw new IllegalStateException("Priority is broken!"); - } - } - - if (!result.get()) - throw new IllegalStateException(); - } - finally { - // Step 13. Be sure to close our JMS resources! - if (connection != null) { - connection.close(); - } - } - } -} - -class SimpleMessageListener implements MessageListener { - - ArrayList<TextMessage> msgReceived; - AtomicBoolean result; - - public SimpleMessageListener(ArrayList<TextMessage> msgReceived, AtomicBoolean result) { - this.msgReceived = msgReceived; - this.result = result; - } - - public void onMessage(final Message msg) { - TextMessage textMessage = (TextMessage) msg; - try { - System.out.println("Received message : [" + textMessage.getText() + "]"); - } - catch (JMSException e) { - result.set(false); - } - msgReceived.add(textMessage); - } - -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/multiple-failover-failback/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/multiple-failover-failback/pom.xml b/examples/jms/multiple-failover-failback/pom.xml deleted file mode 100644 index c44a63f..0000000 --- a/examples/jms/multiple-failover-failback/pom.xml +++ /dev/null @@ -1,121 +0,0 @@ -<?xml version='1.0'?> -<!-- -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> - - <parent> - <groupId>org.apache.activemq.examples.jms</groupId> - <artifactId>jms-examples</artifactId> - <version>1.0.1-SNAPSHOT</version> - </parent> - - <artifactId>multiple-failover-failback</artifactId> - <packaging>jar</packaging> - <name>ActiveMQ Artemis JMS Multiple Failover Failback Example</name> - - <properties> - <activemq.basedir>${project.basedir}/../../..</activemq.basedir> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-cli</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-jms_2.0_spec</artifactId> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-maven-plugin</artifactId> - <executions> - <execution> - <id>create0</id> - <goals> - <goal>create</goal> - </goals> - <configuration> - <instance>${basedir}/target/server0</instance> - <sharedStore>true</sharedStore> - <slave>false</slave> - <dataFolder>../data</dataFolder> - <failoverOnShutdown>true</failoverOnShutdown> - </configuration> - </execution> - <execution> - <id>create1</id> - <goals> - <goal>create</goal> - </goals> - <configuration> - <instance>${basedir}/target/server1</instance> - <sharedStore>true</sharedStore> - <slave>true</slave> - <dataFolder>../data</dataFolder> - <failoverOnShutdown>true</failoverOnShutdown> - </configuration> - </execution> - <execution> - <id>create2</id> - <goals> - <goal>create</goal> - </goals> - <configuration> - <instance>${basedir}/target/server2</instance> - <sharedStore>true</sharedStore> - <slave>true</slave> - <dataFolder>../data</dataFolder> - </configuration> - </execution> - <execution> - <id>runClient</id> - <goals> - <goal>runClient</goal> - </goals> - <configuration> - <clientClass>org.apache.activemq.artemis.jms.example.MultipleFailoverFailbackExample</clientClass> - <args> - <param>${basedir}/target/server0</param> - <param>${basedir}/target/server1</param> - <param>${basedir}/target/server2</param> - </args> - </configuration> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>org.apache.activemq.examples.jms</groupId> - <artifactId>multiple-failover-failback</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - </plugin> - </plugins> - </build> - -</project> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/multiple-failover-failback/src/main/java/org/apache/activemq/artemis/jms/example/MultipleFailoverFailbackExample.java ---------------------------------------------------------------------- diff --git a/examples/jms/multiple-failover-failback/src/main/java/org/apache/activemq/artemis/jms/example/MultipleFailoverFailbackExample.java b/examples/jms/multiple-failover-failback/src/main/java/org/apache/activemq/artemis/jms/example/MultipleFailoverFailbackExample.java deleted file mode 100644 index ab0baec..0000000 --- a/examples/jms/multiple-failover-failback/src/main/java/org/apache/activemq/artemis/jms/example/MultipleFailoverFailbackExample.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * 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.activemq.artemis.jms.example; - -import org.apache.activemq.artemis.util.ServerUtil; - -import javax.jms.Connection; -import javax.jms.ConnectionFactory; -import javax.jms.JMSException; -import javax.jms.MessageConsumer; -import javax.jms.MessageProducer; -import javax.jms.Queue; -import javax.jms.Session; -import javax.jms.TextMessage; -import javax.naming.InitialContext; - -public class MultipleFailoverFailbackExample { - - public static void main(final String[] args) throws Exception { - final int numMessages = 30; - - Connection connection = null; - - InitialContext initialContext = null; - - Process[] servers = new Process[3]; - - try { - for (int i = 0; i < args.length; i++) { - servers[i] = ServerUtil.startServer(args[i], MultipleFailoverFailbackExample.class.getSimpleName() + i, i, 5000); - } - - // Step 1. Get an initial context for looking up JNDI from the server #1 - initialContext = new InitialContext(); - - // Step 2. Look up the JMS resources from JNDI - Queue queue = (Queue) initialContext.lookup("queue/exampleQueue"); - ConnectionFactory connectionFactory = (ConnectionFactory) initialContext.lookup("ConnectionFactory"); - - // Step 3. Create a JMS Connection - connection = connectionFactory.createConnection(); - - // Step 4. Create a *non-transacted* JMS Session with client acknowledgement - Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); - - // Step 5. Start the connection to ensure delivery occurs - connection.start(); - - // Step 6. Create a JMS MessageProducer and a MessageConsumer - MessageProducer producer = session.createProducer(queue); - MessageConsumer consumer = session.createConsumer(queue); - - // Step 7. Send some messages to server #1, the live server - for (int i = 0; i < numMessages; i++) { - TextMessage message = session.createTextMessage("This is text message " + i); - producer.send(message); - System.out.println("Sent message: " + message.getText()); - } - - // Step 8. Receive and acknowledge a third of the sent messages - TextMessage message0 = null; - for (int i = 0; i < numMessages / 3; i++) { - message0 = (TextMessage) consumer.receive(5000); - System.out.println("Got message: " + message0.getText()); - } - message0.acknowledge(); - - // Step 9. Receive the rest third of the sent messages but *do not* acknowledge them yet - for (int i = numMessages / 3; i < numMessages; i++) { - message0 = (TextMessage) consumer.receive(5000); - System.out.println("Got message: " + message0.getText()); - } - - // Step 10. Crash server #1, the live server, and wait a little while to make sure - // it has really crashed - ServerUtil.killServer(servers[0]); - - // Step 11. Acknowledging the 2nd half of the sent messages will fail as failover to the - // backup server has occurred - try { - message0.acknowledge(); - } - catch (JMSException e) { - System.err.println("Got exception while acknowledging message: " + e.getMessage()); - } - - // Step 12. Consume again the 2nd third of the messages again. Note that they are not considered as redelivered. - for (int i = numMessages / 3; i < (numMessages / 3) * 2; i++) { - message0 = (TextMessage) consumer.receive(5000); - System.out.printf("Got message: %s (redelivered?: %s)%n", message0.getText(), message0.getJMSRedelivered()); - } - message0.acknowledge(); - - servers[0] = ServerUtil.startServer(args[0], MultipleFailoverFailbackExample.class.getSimpleName() + 0, 0, 5000); - - // Step 11. Acknowledging the 2nd half of the sent messages will fail as failover to the - // backup server has occurred - try { - message0.acknowledge(); - } - catch (JMSException e) { - System.err.println("Got exception while acknowledging message: " + e.getMessage()); - } - - // Step 12. Consume again the 2nd third of the messages again. Note that they are not considered as redelivered. - for (int i = (numMessages / 3) * 2; i < numMessages; i++) { - message0 = (TextMessage) consumer.receive(5000); - System.out.printf("Got message: %s (redelivered?: %s)%n", message0.getText(), message0.getJMSRedelivered()); - } - message0.acknowledge(); - } - finally { - // Step 13. Be sure to close our resources! - - if (connection != null) { - connection.close(); - } - - if (initialContext != null) { - initialContext.close(); - } - - for (int i = 0; i < args.length; i++) { - ServerUtil.killServer(servers[i]); - } - } - } -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/multiple-failover-failback/src/main/resources/jndi.properties ---------------------------------------------------------------------- diff --git a/examples/jms/multiple-failover-failback/src/main/resources/jndi.properties b/examples/jms/multiple-failover-failback/src/main/resources/jndi.properties deleted file mode 100644 index 7f7a19f..0000000 --- a/examples/jms/multiple-failover-failback/src/main/resources/jndi.properties +++ /dev/null @@ -1,20 +0,0 @@ -# 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. - -java.naming.factory.initial=org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory -connectionFactory.ConnectionFactory=tcp://localhost:61616?ha=true&retryInterval=1000&retryIntervalMultiplier=1.0&reconnectAttempts=-1 -queue.queue/exampleQueue=exampleQueue http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/multiple-failover/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/multiple-failover/pom.xml b/examples/jms/multiple-failover/pom.xml deleted file mode 100644 index 3323ad5..0000000 --- a/examples/jms/multiple-failover/pom.xml +++ /dev/null @@ -1,121 +0,0 @@ -<?xml version='1.0'?> -<!-- -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> - - <parent> - <groupId>org.apache.activemq.examples.jms</groupId> - <artifactId>jms-examples</artifactId> - <version>1.0.1-SNAPSHOT</version> - </parent> - - <artifactId>multiple-failover</artifactId> - <packaging>jar</packaging> - <name>ActiveMQ Artemis JMS Multiple Failover Example</name> - - <properties> - <activemq.basedir>${project.basedir}/../../..</activemq.basedir> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-cli</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-jms_2.0_spec</artifactId> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-maven-plugin</artifactId> - <executions> - <execution> - <id>create0</id> - <goals> - <goal>create</goal> - </goals> - <configuration> - <instance>${basedir}/target/server0</instance> - <sharedStore>true</sharedStore> - <slave>false</slave> - <dataFolder>../data</dataFolder> - <failoverOnShutdown>true</failoverOnShutdown> - </configuration> - </execution> - <execution> - <id>create1</id> - <goals> - <goal>create</goal> - </goals> - <configuration> - <instance>${basedir}/target/server1</instance> - <sharedStore>true</sharedStore> - <slave>true</slave> - <dataFolder>../data</dataFolder> - <failoverOnShutdown>true</failoverOnShutdown> - </configuration> - </execution> - <execution> - <id>create2</id> - <goals> - <goal>create</goal> - </goals> - <configuration> - <instance>${basedir}/target/server2</instance> - <sharedStore>true</sharedStore> - <slave>true</slave> - <dataFolder>../data</dataFolder> - </configuration> - </execution> - <execution> - <id>runClient</id> - <goals> - <goal>runClient</goal> - </goals> - <configuration> - <clientClass>org.apache.activemq.artemis.jms.example.MultipleFailoverExample</clientClass> - <args> - <param>${basedir}/target/server0</param> - <param>${basedir}/target/server1</param> - <param>${basedir}/target/server2</param> - </args> - </configuration> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>org.apache.activemq.examples.jms</groupId> - <artifactId>multiple-failover</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - </plugin> - </plugins> - </build> - -</project> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/multiple-failover/src/main/java/org/apache/activemq/artemis/jms/example/MultipleFailoverExample.java ---------------------------------------------------------------------- diff --git a/examples/jms/multiple-failover/src/main/java/org/apache/activemq/artemis/jms/example/MultipleFailoverExample.java b/examples/jms/multiple-failover/src/main/java/org/apache/activemq/artemis/jms/example/MultipleFailoverExample.java deleted file mode 100644 index 41d9e52..0000000 --- a/examples/jms/multiple-failover/src/main/java/org/apache/activemq/artemis/jms/example/MultipleFailoverExample.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * 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.activemq.artemis.jms.example; - -import org.apache.activemq.artemis.util.ServerUtil; - -import javax.jms.Connection; -import javax.jms.ConnectionFactory; -import javax.jms.JMSException; -import javax.jms.MessageConsumer; -import javax.jms.MessageProducer; -import javax.jms.Queue; -import javax.jms.Session; -import javax.jms.TextMessage; -import javax.naming.InitialContext; - -public class MultipleFailoverExample { - - public static void main(final String[] args) throws Exception { - final int numMessages = 30; - - Connection connection = null; - - InitialContext initialContext = null; - - Process[] servers = new Process[3]; - - try { - for (int i = 0; i < args.length; i++) { - servers[i] = ServerUtil.startServer(args[i], MultipleFailoverExample.class.getSimpleName() + i, i, 5000); - } - - // Step 1. Get an initial context for looking up JNDI from the server #1 - initialContext = new InitialContext(); - - // Step 2. Look up the JMS resources from JNDI - Queue queue = (Queue) initialContext.lookup("queue/exampleQueue"); - ConnectionFactory connectionFactory = (ConnectionFactory) initialContext.lookup("ConnectionFactory"); - - // Step 3. Create a JMS Connection - connection = connectionFactory.createConnection(); - - // Step 4. Create a *non-transacted* JMS Session with client acknowledgement - Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); - - // Step 5. Start the connection to ensure delivery occurs - connection.start(); - - // Step 6. Create a JMS MessageProducer and a MessageConsumer - MessageProducer producer = session.createProducer(queue); - MessageConsumer consumer = session.createConsumer(queue); - - // Step 7. Send some messages to server #1, the live server - for (int i = 0; i < numMessages; i++) { - TextMessage message = session.createTextMessage("This is text message " + i); - producer.send(message); - System.out.println("Sent message: " + message.getText()); - } - - // Step 8. Receive and acknowledge a third of the sent messages - TextMessage message0 = null; - for (int i = 0; i < numMessages / 3; i++) { - message0 = (TextMessage) consumer.receive(5000); - System.out.println("Got message: " + message0.getText()); - } - message0.acknowledge(); - - // Step 9. Receive the rest third of the sent messages but *do not* acknowledge them yet - for (int i = numMessages / 3; i < numMessages; i++) { - message0 = (TextMessage) consumer.receive(5000); - System.out.println("Got message: " + message0.getText()); - } - - // Step 10. Crash server #1, the live server, and wait a little while to make sure - // it has really crashed - ServerUtil.killServer(servers[0]); - - // Step 11. Acknowledging the 2nd half of the sent messages will fail as failover to the - // backup server has occurred - try { - message0.acknowledge(); - } - catch (JMSException e) { - System.err.println("Got exception while acknowledging message: " + e.getMessage()); - } - - // Step 12. Consume again the 2nd third of the messages again. Note that they are not considered as redelivered. - for (int i = numMessages / 3; i < (numMessages / 3) * 2; i++) { - message0 = (TextMessage) consumer.receive(5000); - System.out.printf("Got message: %s (redelivered?: %s)%n", message0.getText(), message0.getJMSRedelivered()); - } - message0.acknowledge(); - - ServerUtil.killServer(servers[ServerUtil.getServer(connection)]); - - // Step 11. Acknowledging the 2nd half of the sent messages will fail as failover to the - // backup server has occurred - try { - message0.acknowledge(); - } - catch (JMSException e) { - throw new IllegalStateException("Got exception while acknowledging message: " + e.getMessage()); - } - - // Step 12. Consume again the 2nd third of the messages again. Note that they are not considered as redelivered. - for (int i = (numMessages / 3) * 2; i < numMessages; i++) { - message0 = (TextMessage) consumer.receive(5000); - System.out.printf("Got message: %s (redelivered?: %s)%n", message0.getText(), message0.getJMSRedelivered()); - } - message0.acknowledge(); - } - finally { - // Step 13. Be sure to close our resources! - - if (connection != null) { - connection.close(); - } - - if (initialContext != null) { - initialContext.close(); - } - - for (int i = 0; i < args.length; i++) { - ServerUtil.killServer(servers[i]); - } - } - } -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/multiple-failover/src/main/resources/jndi.properties ---------------------------------------------------------------------- diff --git a/examples/jms/multiple-failover/src/main/resources/jndi.properties b/examples/jms/multiple-failover/src/main/resources/jndi.properties deleted file mode 100644 index 7f7a19f..0000000 --- a/examples/jms/multiple-failover/src/main/resources/jndi.properties +++ /dev/null @@ -1,20 +0,0 @@ -# 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. - -java.naming.factory.initial=org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory -connectionFactory.ConnectionFactory=tcp://localhost:61616?ha=true&retryInterval=1000&retryIntervalMultiplier=1.0&reconnectAttempts=-1 -queue.queue/exampleQueue=exampleQueue http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/no-consumer-buffering/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/no-consumer-buffering/pom.xml b/examples/jms/no-consumer-buffering/pom.xml deleted file mode 100644 index dcd0236..0000000 --- a/examples/jms/no-consumer-buffering/pom.xml +++ /dev/null @@ -1,117 +0,0 @@ -<?xml version='1.0'?> -<!-- -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> - - <parent> - <groupId>org.apache.activemq.examples.jms</groupId> - <artifactId>jms-examples</artifactId> - <version>1.0.1-SNAPSHOT</version> - </parent> - - <artifactId>no-consumer-buffering</artifactId> - <packaging>jar</packaging> - <name>ActiveMQ Artemis JMS No Consumer Buffering Example</name> - - <properties> - <activemq.basedir>${project.basedir}/../../..</activemq.basedir> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-jms-client</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - - <profiles> - <profile> - <!-- specify -PnoServer if you don't want to start the server --> - <id>noServer</id> - <properties> - <noServer>true</noServer> - </properties> - </profile> - </profiles> - <build> - <plugins> - <plugin> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-maven-plugin</artifactId> - <executions> - <execution> - <id>create</id> - <goals> - <goal>create</goal> - </goals> - <configuration> - <ignore>${noServer}</ignore> - </configuration> - </execution> - <execution> - <id>start</id> - <goals> - <goal>cli</goal> - </goals> - <configuration> - <ignore>${noServer}</ignore> - <spawn>true</spawn> - <testURI>tcp://localhost:61616</testURI> - <args> - <param>run</param> - </args> - </configuration> - </execution> - <execution> - <id>runClient</id> - <goals> - <goal>runClient</goal> - </goals> - <configuration> - <clientClass>org.apache.activemq.artemis.jms.example.NoConsumerBufferingExample</clientClass> - </configuration> - </execution> - <execution> - <id>stop</id> - <goals> - <goal>cli</goal> - </goals> - <configuration> - <ignore>${noServer}</ignore> - <args> - <param>stop</param> - </args> - </configuration> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>org.apache.activemq.examples.jms</groupId> - <artifactId>no-consumer-buffering</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - </plugin> - </plugins> - </build> -</project>
