http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/clustered-static-oneway/readme.html ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-static-oneway/readme.html b/examples/jms/clustered-static-oneway/readme.html index 4aacbbd..d19ba03 100644 --- a/examples/jms/clustered-static-oneway/readme.html +++ b/examples/jms/clustered-static-oneway/readme.html @@ -26,6 +26,7 @@ under the License. </head> <body onload="prettyPrint()"> <h1>JMS Load Balanced Static Clustered One Way Queue 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 demonstrates a JMS queue deployed on three different nodes. The three nodes are configured to form a one way cluster from a <em>static</em> list of nodes. </p> @@ -59,190 +60,5 @@ under the License. </pre> <p>For more information on ActiveMQ Artemis load balancing, and clustering in general, please see the clustering section of the user manual.</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> Get an initial context for looking up JNDI from server 0.</li> - <pre class="prettyprint"> - <code> - ic0 = getContext(0); - </code> - </pre> - - <li>Look-up the JMS Queue object from JNDI</li> - <pre class="prettyprint"> - <code> - Queue queue = (Queue)ic0.lookup("/queue/exampleQueue"); - </code> - </pre> - - <li>Look-up a JMS Connection Factory object from JNDI on server 0</li> - <pre class="prettyprint"> - <code> - ConnectionFactory cf0 = (ConnectionFactory)ic0.lookup("/ConnectionFactory"); - </code> - </pre> - - - <li>grab an initial connection and wait, in reality you wouldn't do it this way but since we want to ensure an - equal load balance we do this and then create 4 connections round robined</li> - <pre class="prettyprint"> - <code> - initialConnection = cf0.createConnection(); - </code> - </pre> - - <li>We create a JMS Connection connection0 which is a connection to server 0</li> - <pre class="prettyprint"> - <code> - connection0 = cf0.createConnection() - </code> - </pre> - - <li>We create a JMS Connection connection0 which is a connection to server 1</li> - <pre class="prettyprint"> - <code> - connection1 = cf0.createConnection() - </code> - </pre> - - <li>We create a JMS Connection connection0 which is a connection to server 2</li> - <pre class="prettyprint"> - <code> - connection2 = cf0.createConnection() - </code> - </pre> - - <li>We create a JMS Session on server 0</li> - <pre class="prettyprint"> - <code> - Session session0 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE); - </code> - </pre> - - <li>We create a JMS Session on server 1</li> - <pre class="prettyprint"> - <code> - Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE); - </code> - </pre> - - <li>We create a JMS Session on server 1</li> - <pre class="prettyprint"> - <code> - Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE); - </code> - </pre> - <li>We start the connections to ensure delivery occurs on them</li> - <pre class="prettyprint"> - <code> - connection0.start(); - - connection1.start(); - - connection2.start(); - </code> - </pre> - - - <li>We create JMS MessageConsumer objects on server 0 and server 1</li> - <pre class="prettyprint"> - <code> - MessageConsumer consumer0 = session0.createConsumer(queue); - - MessageConsumer consumer2 = session2.createConsumer(queue); - - MessageConsumer consumer3 = session3.createConsumer(queue); - </code> - </pre> - - - <li>We create a JMS MessageProducer object on server 0.</li> - <pre class="prettyprint"> - <code> - Session sendSession = getServerConnection(0, connection0, connection1, connection2).createSession(false, Session.AUTO_ACKNOWLEDGE); - - MessageProducer producer = sendSession.createProducer(queue); - </code> - </pre> - - <li>We send some messages to server 0.</li> - <pre class="prettyprint"> - <code> - final int numMessages = 18; - - for (int i = 0; i < numMessages; i++) - { - TextMessage message = session0.createTextMessage("This is text message " + i); - - producer.send(message); - - System.out.println("Sent message: " + message.getText()); - } - </code> - </pre> - - <li>We now consume those messages on *both* server 0 and server 1. - We note the messages have been distributed between servers in a round robin fashion. - ActiveMQ Artemis has <b>load balanced</b> the messages between the available consumers on the different nodes. - ActiveMQ Artemis can be configured to always load balance messages to all nodes, or to only balance messages - to nodes which have consumers with no or matching selectors. See the user manual for more details.</li> - JMS Queues implement point-to-point message where each message is only ever consumed by a - maximum of one consumer. - <pre class="prettyprint"> - <code> - for (int i = 0; i < numMessages; i += 2) - { - TextMessage message0 = (TextMessage)consumer0.receive(5000); - - System.out.println("Got message: " + message0.getText() + " from node 0"); - - TextMessage message1 = (TextMessage)consumer1.receive(5000); - - System.out.println("Got message: " + message1.getText() + " from node 1"); - - TextMessage message2 = (TextMessage)consumer2.receive(5000); - - System.out.println("Got message: " + message2.getText() + " from node " + con2Node); - } - </code> - </pre> - - <li>And finally (no pun intended), <b>always</b> remember to close your JMS 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 (initialConnection != null) - { - initialConnection.close(); - } - - if (connection0 != null) - { - connection0.close(); - } - - if (connection1 != null) - { - connection1.close(); - } - - if (connection2 != null) - { - connection2.close(); - } - - if (ic0 != null) - { - ic0.close(); - } - } - </code> - </pre> - - </ol> </body> </html>
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/clustered-static-oneway/src/main/java/org/apache/activemq/artemis/jms/example/ClusterStaticOnewayExample.java ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-static-oneway/src/main/java/org/apache/activemq/artemis/jms/example/ClusterStaticOnewayExample.java b/examples/jms/clustered-static-oneway/src/main/java/org/apache/activemq/artemis/jms/example/ClusterStaticOnewayExample.java index e061722..53d98bc 100644 --- a/examples/jms/clustered-static-oneway/src/main/java/org/apache/activemq/artemis/jms/example/ClusterStaticOnewayExample.java +++ b/examples/jms/clustered-static-oneway/src/main/java/org/apache/activemq/artemis/jms/example/ClusterStaticOnewayExample.java @@ -16,8 +16,6 @@ */ 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.MessageConsumer; @@ -25,8 +23,10 @@ import javax.jms.MessageProducer; import javax.jms.Queue; import javax.jms.Session; import javax.jms.TextMessage; -import javax.naming.InitialContext; -import java.util.Hashtable; + +import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; +import org.apache.activemq.artemis.util.ServerUtil; /** * A simple example that demonstrates server side load-balancing of messages between the queue instances on different @@ -44,22 +44,13 @@ public class ClusterStaticOnewayExample Connection connection2 = null; - InitialContext ic0 = null; - try { - // Step 1. Get an initial context for looking up JNDI from server 0 - Hashtable<String, Object> properties = new Hashtable<String, Object>(); - properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); - properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61616"); - properties.put("queue.queue/exampleQueue", "exampleQueue"); - ic0 = new InitialContext(properties); - - // Step 2. Look-up the JMS Queue object from JNDI - Queue queue = (Queue)ic0.lookup("queue/exampleQueue"); + // Step 2. Instantiate Queue + Queue queue = ActiveMQJMSClient.createQueue("exampleQueue"); // Step 3. Look-up a JMS Connection Factory object from JNDI on server 0 - ConnectionFactory cf0 = (ConnectionFactory)ic0.lookup("ConnectionFactory"); + ConnectionFactory cf0 = new ActiveMQConnectionFactory("tcp://localhost:61616"); //step 4. grab an initial connection and wait, in reality you wouldn't do it this way but since we want to ensure an // equal load balance we do this and then create 4 connections round robined @@ -173,11 +164,6 @@ public class ClusterStaticOnewayExample { connection2.close(); } - - if (ic0 != null) - { - ic0.close(); - } } } } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/clustered-static-oneway/src/main/resources/activemq/server0/broker.xml ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-static-oneway/src/main/resources/activemq/server0/broker.xml b/examples/jms/clustered-static-oneway/src/main/resources/activemq/server0/broker.xml index 2d77bb1..3e86ed3 100644 --- a/examples/jms/clustered-static-oneway/src/main/resources/activemq/server0/broker.xml +++ b/examples/jms/clustered-static-oneway/src/main/resources/activemq/server0/broker.xml @@ -26,13 +26,13 @@ <core xmlns="urn:activemq:core"> - <bindings-directory>${data.dir:./data}/bindings</bindings-directory> + <bindings-directory>./data/bindings</bindings-directory> - <journal-directory>${data.dir:./data}/journal</journal-directory> + <journal-directory>./data/journal</journal-directory> - <large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory> + <large-messages-directory>./data/largemessages</large-messages-directory> - <paging-directory>${data.dir:./data}/paging</paging-directory> + <paging-directory>./data/paging</paging-directory> <!-- Connectors --> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/clustered-static-oneway/src/main/resources/activemq/server1/broker.xml ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-static-oneway/src/main/resources/activemq/server1/broker.xml b/examples/jms/clustered-static-oneway/src/main/resources/activemq/server1/broker.xml index 9b5fdf8..1464ea9 100644 --- a/examples/jms/clustered-static-oneway/src/main/resources/activemq/server1/broker.xml +++ b/examples/jms/clustered-static-oneway/src/main/resources/activemq/server1/broker.xml @@ -26,13 +26,13 @@ <core xmlns="urn:activemq:core"> - <bindings-directory>${data.dir:./data}/bindings</bindings-directory> + <bindings-directory>./data/bindings</bindings-directory> - <journal-directory>${data.dir:./data}/journal</journal-directory> + <journal-directory>./data/journal</journal-directory> - <large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory> + <large-messages-directory>./data/largemessages</large-messages-directory> - <paging-directory>${data.dir:./data}/paging</paging-directory> + <paging-directory>./data/paging</paging-directory> <!-- Connectors --> <connectors> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/clustered-static-oneway/src/main/resources/activemq/server2/broker.xml ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-static-oneway/src/main/resources/activemq/server2/broker.xml b/examples/jms/clustered-static-oneway/src/main/resources/activemq/server2/broker.xml index 147a9b9..b1043f5 100644 --- a/examples/jms/clustered-static-oneway/src/main/resources/activemq/server2/broker.xml +++ b/examples/jms/clustered-static-oneway/src/main/resources/activemq/server2/broker.xml @@ -26,13 +26,13 @@ <core xmlns="urn:activemq:core"> - <bindings-directory>${data.dir:./data}/bindings</bindings-directory> + <bindings-directory>./data/bindings</bindings-directory> - <journal-directory>${data.dir:./data}/journal</journal-directory> + <journal-directory>./data/journal</journal-directory> - <large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory> + <large-messages-directory>./data/largemessages</large-messages-directory> - <paging-directory>${data.dir:./data}/paging</paging-directory> + <paging-directory>./data/paging</paging-directory> <!-- Connectors --> <connectors> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/clustered-topic/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-topic/pom.xml b/examples/jms/clustered-topic/pom.xml index 418d98f..2982b21 100644 --- a/examples/jms/clustered-topic/pom.xml +++ b/examples/jms/clustered-topic/pom.xml @@ -18,7 +18,8 @@ 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"> +<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> @@ -27,7 +28,7 @@ under the License. <version>1.0.1-SNAPSHOT</version> </parent> - <artifactId>artemis-jms-clustered-topic-example</artifactId> + <artifactId>clustered-topic</artifactId> <packaging>jar</packaging> <name>ActiveMQ Artemis JMS Clustered Topic Example</name> @@ -37,115 +38,125 @@ under the License. <dependencies> <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-jms_2.0_spec</artifactId> + <groupId>org.apache.activemq</groupId> + <artifactId>artemis-jms-client</artifactId> + <version>${project.version}</version> </dependency> </dependencies> <profiles> <profile> - <id>example</id> - <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> - <configuration>${basedir}/target/classes/activemq/server0</configuration> - </configuration> - </execution> - <execution> - <id>create1</id> - <goals> - <goal>create</goal> - </goals> - <configuration> - <instance>${basedir}/target/server1</instance> - <configuration>${basedir}/target/classes/activemq/server1</configuration> - </configuration> - </execution> - <execution> - <id>start0</id> - <goals> - <goal>cli</goal> - </goals> - <configuration> - <spawn>true</spawn> - <location>${basedir}/target/server0</location> - <testURI>tcp://localhost:61616</testURI> - <args> - <param>run</param> - </args> - <name>server0</name> - </configuration> - </execution> - <execution> - <id>start1</id> - <goals> - <goal>cli</goal> - </goals> - <configuration> - <spawn>true</spawn> - <location>${basedir}/target/server1</location> - <testURI>tcp://localhost:61617</testURI> - <args> - <param>run</param> - </args> - <name>server1</name> - </configuration> - </execution> - <execution> - <id>runClient</id> - <goals> - <goal>runClient</goal> - </goals> - <configuration> - <clientClass>org.apache.activemq.artemis.jms.example.ClusteredTopicExample</clientClass> - </configuration> - </execution> - <execution> - <id>stop0</id> - <goals> - <goal>cli</goal> - </goals> - <configuration> - <location>${basedir}/target/server0</location> - <args> - <param>stop</param> - </args> - </configuration> - </execution> - <execution> - <id>stop1</id> - <goals> - <goal>cli</goal> - </goals> - <configuration> - <location>${basedir}/target/server1</location> - <args> - <param>stop</param> - </args> - </configuration> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>org.apache.activemq.examples.jms</groupId> - <artifactId>artemis-jms-clustered-topic-example</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - </plugin> - </plugins> - </build> + <!-- 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>create0</id> + <goals> + <goal>create</goal> + </goals> + <configuration> + <ignore>${noServer}</ignore> + <instance>${basedir}/target/server0</instance> + <configuration>${basedir}/target/classes/activemq/server0</configuration> + </configuration> + </execution> + <execution> + <id>create1</id> + <goals> + <goal>create</goal> + </goals> + <configuration> + <ignore>${noServer}</ignore> + <instance>${basedir}/target/server1</instance> + <configuration>${basedir}/target/classes/activemq/server1</configuration> + </configuration> + </execution> + <execution> + <id>start0</id> + <goals> + <goal>cli</goal> + </goals> + <configuration> + <ignore>${noServer}</ignore> + <spawn>true</spawn> + <location>${basedir}/target/server0</location> + <testURI>tcp://localhost:61616</testURI> + <args> + <param>run</param> + </args> + <name>server0</name> + </configuration> + </execution> + <execution> + <id>start1</id> + <goals> + <goal>cli</goal> + </goals> + <configuration> + <ignore>${noServer}</ignore> + <spawn>true</spawn> + <location>${basedir}/target/server1</location> + <testURI>tcp://localhost:61617</testURI> + <args> + <param>run</param> + </args> + <name>server1</name> + </configuration> + </execution> + <execution> + <id>runClient</id> + <goals> + <goal>runClient</goal> + </goals> + <configuration> + <clientClass>org.apache.activemq.artemis.jms.example.ClusteredTopicExample</clientClass> + </configuration> + </execution> + <execution> + <id>stop0</id> + <goals> + <goal>cli</goal> + </goals> + <configuration> + <ignore>${noServer}</ignore> + <location>${basedir}/target/server0</location> + <args> + <param>stop</param> + </args> + </configuration> + </execution> + <execution> + <id>stop1</id> + <goals> + <goal>cli</goal> + </goals> + <configuration> + <ignore>${noServer}</ignore> + <location>${basedir}/target/server1</location> + <args> + <param>stop</param> + </args> + </configuration> + </execution> + </executions> + <dependencies> + <dependency> + <groupId>org.apache.activemq.examples.jms</groupId> + <artifactId>clustered-topic</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> </project> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/clustered-topic/readme.html ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-topic/readme.html b/examples/jms/clustered-topic/readme.html index bf92e08..cd29bb4 100644 --- a/examples/jms/clustered-topic/readme.html +++ b/examples/jms/clustered-topic/readme.html @@ -26,6 +26,7 @@ under the License. </head> <body onload="prettyPrint()"> <h1>JMS Clustered Topic 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 demonstrates a JMS Topic deployed on two different nodes. The two nodes are configured to form a cluster.</p> <p>We then create a subscriber on the topic on each node, and we create a producer on only one of the nodes.</p> @@ -50,144 +51,5 @@ under the License. </pre> <p>For more information on ActiveMQ Artemis load balancing, and clustering in general, please see the clustering section of the user manual.</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> Get an initial context for looking up JNDI from server 0.</li> - <pre class="prettyprint"> - <code> - ic0 = getContext(0); - </code> - </pre> - - <li>Look-up the JMS Topic object from JNDI</li> - <pre class="prettyprint"> - <code>Topic topic = (Topic)ic0.lookup("/topic/exampleTopic");</code> - </pre> - - <li>Look-up a JMS Connection Factory object from JNDI on server 0</li> - <pre class="prettyprint"> - <code>ConnectionFactory cf0 = (ConnectionFactory)ic0.lookup("/ConnectionFactory");</code> - </pre> - - <li>Get an initial context for looking up JNDI from server 1.</li> - <pre class="prettyprint"> - <code>ic1 = getContext(1);</code> - </pre> - - <li>Look-up a JMS Connection Factory object from JNDI on server 1</li> - <pre class="prettyprint"> - <code>ConnectionFactory cf1 = (ConnectionFactory)ic1.lookup("/ConnectionFactory"); - </code> - </pre> - - <li>We create a JMS Connection connection0 which is a connection to server 0</li> - <pre class="prettyprint"> - <code> - connection0 = cf0.createConnection(); - </code> - </pre> - - <li>We create a JMS Connection connection1 which is a connection to server 1</li> - <pre class="prettyprint"> - <code> - connection1 = cf1.createConnection(); - </code> - </pre> - - <li>We create a JMS Session on server 0</li> - <pre class="prettyprint"> - <code> - Session session0 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE); - </code> - </pre> - - <li>We create a JMS Session on server 1</li> - <pre class="prettyprint"> - <code> - Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE); - </code> - </pre> - - <li>We start the connections to ensure delivery occurs on them</li> - <pre class="prettyprint"> - <code> - connection0.start(); - - connection1.start(); - </code> - </pre> - - <li>We create JMS MessageConsumer (Topic subscriber) objects on server 0 and server 1</li> - <pre class="prettyprint"> - <code> - MessageConsumer consumer0 = session0.createConsumer(topic); - - MessageConsumer consumer1 = session1.createConsumer(topic); - </code> - </pre> - - <li>We create a JMS MessageProducer object on server 0.</li> - <pre class="prettyprint"> - <code> - MessageProducer producer = session0.createProducer(topic);</code> - </pre> - - <li>We send some messages to server 0.</li> - <pre class="prettyprint"> - <code> - final int numMessages = 10; - - for (int i = 0; i < numMessages; i++) - { - TextMessage message = session0.createTextMessage("This is text message " + i); - - producer.send(message); - - System.out.println("Sent message: " + message.getText()); - } - </code> - </pre> - - <li> - We now consume those messages on <b>both</b> server 0 and server 1. - We note that all messages have been consumed by <b>both</b> consumers. - JMS Topics implement <b>publish-subscribe</b> messaging where all consumers get a copy of all messages. - <pre class="prettyprint"> - <code> - for (int i = 0; i < numMessages; i ++) - { - TextMessage message0 = (TextMessage)consumer0.receive(5000); - - System.out.println("Got message: " + message0.getText() + " from node 0"); - - TextMessage message1 = (TextMessage)consumer1.receive(5000); - - System.out.println("Got message: " + message1.getText() + " from node 1"); - } - </code> - </pre> - - <li>And finally (no pun intended), <b>always</b> remember to close your JMS 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 (connection0 != null) - { - connection0.close(); - } - - if (connection1 != null) - { - connection1.close(); - } - } - </code> - </pre> - - </ol> </body> </html> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/clustered-topic/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredTopicExample.java ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-topic/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredTopicExample.java b/examples/jms/clustered-topic/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredTopicExample.java index 31b3d41..a12fedd 100644 --- a/examples/jms/clustered-topic/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredTopicExample.java +++ b/examples/jms/clustered-topic/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredTopicExample.java @@ -24,7 +24,9 @@ import javax.jms.Session; import javax.jms.TextMessage; import javax.jms.Topic; import javax.naming.InitialContext; -import java.util.Hashtable; + +import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; /** * A simple example that shows a JMS Topic clustered across two nodes of a cluster. @@ -44,56 +46,44 @@ public class ClusteredTopicExample try { - // Step 1. Get an initial context for looking up JNDI from server 0 - Hashtable<String, Object> properties = new Hashtable<String, Object>(); - properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); - properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61616"); - properties.put("topic.topic/exampleTopic", "exampleTopic"); - ic0 = new InitialContext(properties); - - // Step 2. Look-up the JMS Topic object from JNDI - Topic topic = (Topic)ic0.lookup("topic/exampleTopic"); - // Step 3. Look-up a JMS Connection Factory object from JNDI on server 0 - ConnectionFactory cf0 = (ConnectionFactory)ic0.lookup("ConnectionFactory"); + // Step 1. Instantiate topic + Topic topic = ActiveMQJMSClient.createTopic("exampleTopic"); - // Step 4. Get an initial context for looking up JNDI from server 1 - properties = new Hashtable<String, Object>(); - properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); - properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61617"); - ic1 = new InitialContext(properties); + // Step 2. Look-up a JMS Connection Factory object from JNDI on server 0 + ConnectionFactory cf0 = new ActiveMQConnectionFactory("tcp://localhost:61616"); - // Step 5. Look-up a JMS Connection Factory object from JNDI on server 1 - ConnectionFactory cf1 = (ConnectionFactory)ic1.lookup("ConnectionFactory"); + // Step 3. Look-up a JMS Connection Factory object from JNDI on server 1 + ConnectionFactory cf1 = new ActiveMQConnectionFactory("tcp://localhost:61617"); - // Step 6. We create a JMS Connection connection0 which is a connection to server 0 + // Step 4. We create a JMS Connection connection0 which is a connection to server 0 connection0 = cf0.createConnection(); - // Step 7. We create a JMS Connection connection1 which is a connection to server 1 + // Step 5. We create a JMS Connection connection1 which is a connection to server 1 connection1 = cf1.createConnection(); - // Step 8. We create a JMS Session on server 0 + // Step 6. We create a JMS Session on server 0 Session session0 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE); - // Step 9. We create a JMS Session on server 1 + // Step 7. We create a JMS Session on server 1 Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE); - // Step 10. We start the connections to ensure delivery occurs on them + // Step 8. We start the connections to ensure delivery occurs on them connection0.start(); connection1.start(); - // Step 11. We create JMS MessageConsumer objects on server 0 and server 1 + // Step 9. We create JMS MessageConsumer objects on server 0 and server 1 MessageConsumer consumer0 = session0.createConsumer(topic); MessageConsumer consumer1 = session1.createConsumer(topic); Thread.sleep(1000); - // Step 12. We create a JMS MessageProducer object on server 0 + // Step 10. We create a JMS MessageProducer object on server 0 MessageProducer producer = session0.createProducer(topic); - // Step 13. We send some messages to server 0 + // Step 11. We send some messages to server 0 final int numMessages = 10; @@ -106,7 +96,7 @@ public class ClusteredTopicExample System.out.println("Sent message: " + message.getText()); } - // Step 14. We now consume those messages on *both* server 0 and server 1. + // Step 12. We now consume those messages on *both* server 0 and server 1. // We note that all messages have been consumed by *both* consumers. // JMS Topics implement *publish-subscribe* messaging where all consumers get a copy of all messages http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/clustered-topic/src/main/resources/activemq/server0/broker.xml ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-topic/src/main/resources/activemq/server0/broker.xml b/examples/jms/clustered-topic/src/main/resources/activemq/server0/broker.xml index 452b412..a4e8dde 100644 --- a/examples/jms/clustered-topic/src/main/resources/activemq/server0/broker.xml +++ b/examples/jms/clustered-topic/src/main/resources/activemq/server0/broker.xml @@ -29,13 +29,13 @@ under the License. <core xmlns="urn:activemq:core"> - <bindings-directory>${data.dir:./data}/bindings</bindings-directory> + <bindings-directory>./data/bindings</bindings-directory> - <journal-directory>${data.dir:./data}/journal</journal-directory> + <journal-directory>./data/journal</journal-directory> - <large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory> + <large-messages-directory>./data/largemessages</large-messages-directory> - <paging-directory>${data.dir:./data}/paging</paging-directory> + <paging-directory>./data/paging</paging-directory> <!-- Connectors --> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/clustered-topic/src/main/resources/activemq/server1/broker.xml ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-topic/src/main/resources/activemq/server1/broker.xml b/examples/jms/clustered-topic/src/main/resources/activemq/server1/broker.xml index c1a763b..78beec3 100644 --- a/examples/jms/clustered-topic/src/main/resources/activemq/server1/broker.xml +++ b/examples/jms/clustered-topic/src/main/resources/activemq/server1/broker.xml @@ -29,13 +29,13 @@ under the License. <core xmlns="urn:activemq:core"> - <bindings-directory>${data.dir:./data}/bindings</bindings-directory> + <bindings-directory>./data/bindings</bindings-directory> - <journal-directory>${data.dir:./data}/journal</journal-directory> + <journal-directory>./data/journal</journal-directory> - <large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory> + <large-messages-directory>./data/largemessages</large-messages-directory> - <paging-directory>${data.dir:./data}/paging</paging-directory> + <paging-directory>./data/paging</paging-directory> <!-- Connectors --> <connectors> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/colocated-failover-scale-down/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/colocated-failover-scale-down/pom.xml b/examples/jms/colocated-failover-scale-down/pom.xml index ea1fb10..d2947c4 100644 --- a/examples/jms/colocated-failover-scale-down/pom.xml +++ b/examples/jms/colocated-failover-scale-down/pom.xml @@ -18,7 +18,8 @@ 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"> +<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> @@ -42,65 +43,61 @@ under the License. <version>${project.version}</version> </dependency> <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-jms_2.0_spec</artifactId> + <groupId>org.apache.activemq</groupId> + <artifactId>artemis-jms-client</artifactId> + <version>${project.version}</version> </dependency> </dependencies> - - <profiles> - <profile> - <id>example</id> - <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> - <configuration>${basedir}/target/classes/activemq/server0</configuration> - </configuration> - </execution> - <execution> - <id>create1</id> - <goals> - <goal>create</goal> - </goals> - <configuration> - <instance>${basedir}/target/server1</instance> - <configuration>${basedir}/target/classes/activemq/server1</configuration> - </configuration> - </execution> - <execution> - <id>runClient</id> - <goals> - <goal>runClient</goal> - </goals> - <configuration> - <clientClass>org.apache.activemq.artemis.jms.example.ColocatedFailoverScaleDownExample</clientClass> - <args> - <param>${basedir}/target/server0</param> - <param>${basedir}/target/server1</param> - </args> - </configuration> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>org.apache.activemq.examples.jms</groupId> - <artifactId>colocated-failover-scale-down</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - </plugin> - </plugins> - </build> - </profile> - </profiles> + <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> + <configuration>${basedir}/target/classes/activemq/server0</configuration> + </configuration> + </execution> + <execution> + <id>create1</id> + <goals> + <goal>create</goal> + </goals> + <configuration> + <instance>${basedir}/target/server1</instance> + <configuration>${basedir}/target/classes/activemq/server1</configuration> + </configuration> + </execution> + <execution> + <id>runClient</id> + <goals> + <goal>runClient</goal> + </goals> + <configuration> + <clientClass>org.apache.activemq.artemis.jms.example.ColocatedFailoverScaleDownExample + </clientClass> + <args> + <param>${basedir}/target/server0</param> + <param>${basedir}/target/server1</param> + </args> + </configuration> + </execution> + </executions> + <dependencies> + <dependency> + <groupId>org.apache.activemq.examples.jms</groupId> + <artifactId>colocated-failover-scale-down</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> </project> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/colocated-failover-scale-down/readme.html ---------------------------------------------------------------------- diff --git a/examples/jms/colocated-failover-scale-down/readme.html b/examples/jms/colocated-failover-scale-down/readme.html index 46eeef6..ffcd73b 100644 --- a/examples/jms/colocated-failover-scale-down/readme.html +++ b/examples/jms/colocated-failover-scale-down/readme.html @@ -26,6 +26,8 @@ under the License. </head> <body onload="prettyPrint()"> <h1>JMS Colocated Failover Recover Only Example</h1> + <pre>To run the example, simply type <b>mvn verify</b> from this directory. This example will always spawn and stop multiple servers.</pre> + <p>This example demonstrates how you can colocate live and backup servers in the same VM. We do this by creating an HA Policy that is colocated. colocated means that backup servers can be created and maintained by live servers on behalf @@ -59,133 +61,5 @@ under the License. from the list of available connectors which in this case is the first INVM connector</p> <p> One other thing to notice is that the cluster connection has its reconnect attempts set to 5, this is so it will disconnect instead of trying to reconnect to a backup that doesn't exist.</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> Get an initial context for looking up JNDI for both servers</li> - <pre class="prettyprint"> - <code> - initialContext1 = getContext(1); - initialContext = getContext(0); - </code> - </pre> - - <li>Look up the JMS resources from JNDI</li> - <pre class="prettyprint"> - <code> - Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue"); - ConnectionFactory connectionFactory = (ConnectionFactory)initialContext.lookup("/ConnectionFactory"); - ConnectionFactory connectionFactory1 = (ConnectionFactory)initialContext1.lookup("/ConnectionFactory"); - </code> - </pre> - - <li>Create a JMS Connections</li> - <pre class="prettyprint"> - <code> - connection = connectionFactory.createConnection(); - connection1 = connectionFactory1.createConnection(); - </code> - </pre> - - <li>Create a *non-transacted* JMS Session with client acknowledgement</li> - <pre class="prettyprint"> - <code> - Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); - Session session1 = connection1.createSession(false, Session.CLIENT_ACKNOWLEDGE); - </code> - </pre> - - <li>Create a JMS MessageProducer</li> - <pre class="prettyprint"> - <code> - MessageProducer producer = session.createProducer(queue); - MessageProducer producer1 = session1.createProducer(queue); - </code> - </pre> - - <li>Send some messages to both servers</li> - <pre class="prettyprint"> - <code> - 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()); - message = session1.createTextMessage("This is another text message " + i); - producer1.send(message); - System.out.println("Sent message: " + message.getText()); - } - </code> - </pre> - - <li>Crash server #0, the live server</li> - <pre class="prettyprint"> - <code> - killServer(0); - </code> - </pre> - - <li>start the connection ready to receive messages</li> - <pre class="prettyprint"> - <code> - connection1.start(); - </code> - </pre> - - <li>create a consumer</li> - <pre class="prettyprint"> - <code> - MessageConsumer consumer = session1.createConsumer(queue); - </code> - </pre> - - <li>Receive and acknowledge all of the sent messages, notice that they will be out of order, this is - because they were initially round robined to both nodes then when the server failed were reloaded into the - live server.</li> - <pre class="prettyprint"> - <code> - TextMessage message0 = null; - for (int i = 0; i < numMessages * 2; i++) - { - message0 = (TextMessage)consumer.receive(5000); - System.out.println("Got message: " + message0.getText()); - } - message0.acknowledge(); - </code> - </pre> - - - </pre> - - <li>And finally (no pun intended), <b>always</b> remember to close your JMS 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 (connection != null) - { - connection.close(); - } - - if (initialContext != null) - { - initialContext.close(); - } - if (connection1 != null) - { - connection1.close(); - } - - if (initialContext1 != null) - { - initialContext1.close(); - } - } - </code> - </pre> - - </ol> </body> </html> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/colocated-failover/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/colocated-failover/pom.xml b/examples/jms/colocated-failover/pom.xml index a501d38..121b296 100644 --- a/examples/jms/colocated-failover/pom.xml +++ b/examples/jms/colocated-failover/pom.xml @@ -18,7 +18,8 @@ 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"> +<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> @@ -42,64 +43,60 @@ under the License. <version>${project.version}</version> </dependency> <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-jms_2.0_spec</artifactId> + <groupId>org.apache.activemq</groupId> + <artifactId>artemis-jms-client</artifactId> + <version>${project.version}</version> </dependency> </dependencies> - <profiles> - <profile> - <id>example</id> - <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> - <configuration>${basedir}/target/classes/activemq/server0</configuration> - </configuration> - </execution> - <execution> - <id>create1</id> - <goals> - <goal>create</goal> - </goals> - <configuration> - <instance>${basedir}/target/server1</instance> - <configuration>${basedir}/target/classes/activemq/server1</configuration> - </configuration> - </execution> - <execution> - <id>runClient</id> - <goals> - <goal>runClient</goal> - </goals> - <configuration> - <clientClass>org.apache.activemq.artemis.jms.example.ColocatedFailoverExample</clientClass> - <args> - <param>${basedir}/target/server0</param> - <param>${basedir}/target/server1</param> - </args> - </configuration> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>org.apache.activemq.examples.jms</groupId> - <artifactId>colocated-failover</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - </plugin> - </plugins> - </build> - </profile> - </profiles> + <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> + <configuration>${basedir}/target/classes/activemq/server0</configuration> + </configuration> + </execution> + <execution> + <id>create1</id> + <goals> + <goal>create</goal> + </goals> + <configuration> + <instance>${basedir}/target/server1</instance> + <configuration>${basedir}/target/classes/activemq/server1</configuration> + </configuration> + </execution> + <execution> + <id>runClient</id> + <goals> + <goal>runClient</goal> + </goals> + <configuration> + <clientClass>org.apache.activemq.artemis.jms.example.ColocatedFailoverExample</clientClass> + <args> + <param>${basedir}/target/server0</param> + <param>${basedir}/target/server1</param> + </args> + </configuration> + </execution> + </executions> + <dependencies> + <dependency> + <groupId>org.apache.activemq.examples.jms</groupId> + <artifactId>colocated-failover</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> </project> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/colocated-failover/readme.html ---------------------------------------------------------------------- diff --git a/examples/jms/colocated-failover/readme.html b/examples/jms/colocated-failover/readme.html index 9e787d5..dceae4f 100644 --- a/examples/jms/colocated-failover/readme.html +++ b/examples/jms/colocated-failover/readme.html @@ -26,6 +26,7 @@ under the License. </head> <body onload="prettyPrint()"> <h1>JMS Colocated Failover Shared Store Example</h1> + <pre>To run the example, simply type <b>mvn verify</b> from this directory. This example will always spawn and stop multiple servers.</pre> <p>This example demonstrates how you can colocate live and backup servers in the same VM. We do this by creating an HA Policy that is colocated. colocated means that backup servers can be created and maintained by live servers on behalf @@ -51,143 +52,5 @@ under the License. </pre> <p>notice that we have used a template to set some sensible defaults but overridden the backup strategy so back ups are full servers</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> Get an initial context for looking up JNDI for both servers</li> - <pre class="prettyprint"> - <code> - initialContext1 = getContext(1); - initialContext = getContext(0); - </code> - </pre> - - <li>Look up the JMS resources from JNDI</li> - <pre class="prettyprint"> - <code> - Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue"); - ConnectionFactory connectionFactory = (ConnectionFactory)initialContext.lookup("/ConnectionFactory"); - ConnectionFactory connectionFactory1 = (ConnectionFactory)initialContext1.lookup("/ConnectionFactory"); - </code> - </pre> - - <li>Create a JMS Connections</li> - <pre class="prettyprint"> - <code> - connection = connectionFactory.createConnection(); - connection1 = connectionFactory1.createConnection(); - </code> - </pre> - - <li>Create a *non-transacted* JMS Session with client acknowledgement</li> - <pre class="prettyprint"> - <code> - Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); - Session session1 = connection1.createSession(false, Session.CLIENT_ACKNOWLEDGE); - </code> - </pre> - - <li>Create a JMS MessageProducer</li> - <pre class="prettyprint"> - <code> - MessageProducer producer = session.createProducer(queue); - MessageProducer producer1 = session1.createProducer(queue); - </code> - </pre> - - <li>Send some messages to both servers</li> - <pre class="prettyprint"> - <code> - 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()); - message = session1.createTextMessage("This is another text message " + i); - producer1.send(message); - System.out.println("Sent message: " + message.getText()); - } - </code> - </pre> - - <li>Crash server #0, the live server</li> - <pre class="prettyprint"> - <code> - killServer(0); - </code> - </pre> - - <li>start the connection ready to receive messages</li> - <pre class="prettyprint"> - <code> - connection1.start(); - </code> - </pre> - - <li>create a consumer</li> - <pre class="prettyprint"> - <code> - MessageConsumer consumer = session1.createConsumer(queue); - </code> - </pre> - - <li>Receive and acknowledge all of the sent messages, the backup server that is colocated with server 1 - will have become live and is now handling messages for server 0.</li> - <pre class="prettyprint"> - <code> - TextMessage message0 = null; - for (int i = 0; i < numMessages; i++) - { - message0 = (TextMessage)consumer.receive(5000); - System.out.println("Got message: " + message0.getText()); - } - message0.acknowledge(); - </code> - </pre> - - <li>Receive and acknowledge the rest of the sent messages from server 1.</li> - <pre class="prettyprint"> - <code> - for (int i = 0; i < numMessages; i++) - { - message0 = (TextMessage)consumer1.receive(5000); - System.out.println("Got message: " + message0.getText()); - } - message0.acknowledge(); - </code> - </pre> - - </pre> - - <li>And finally (no pun intended), <b>always</b> remember to close your JMS 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 (connection != null) - { - connection.close(); - } - - if (initialContext != null) - { - initialContext.close(); - } - if (connection1 != null) - { - connection1.close(); - } - - if (initialContext1 != null) - { - initialContext1.close(); - } - } - </code> - </pre> - - </ol> </body> </html> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/consumer-rate-limit/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/consumer-rate-limit/pom.xml b/examples/jms/consumer-rate-limit/pom.xml index b6442a0..32bce35 100644 --- a/examples/jms/consumer-rate-limit/pom.xml +++ b/examples/jms/consumer-rate-limit/pom.xml @@ -18,7 +18,8 @@ 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"> +<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> @@ -27,7 +28,7 @@ under the License. <version>1.0.1-SNAPSHOT</version> </parent> - <artifactId>artemis-jms-consumer-rate-limit-example</artifactId> + <artifactId>consumer-rate-limit</artifactId> <packaging>jar</packaging> <name>ActiveMQ Artemis JMS Consumer Rate Limit Example</name> @@ -37,71 +38,81 @@ under the License. <dependencies> <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-jms_2.0_spec</artifactId> + <groupId>org.apache.activemq</groupId> + <artifactId>artemis-jms-client</artifactId> + <version>${project.version}</version> </dependency> </dependencies> <profiles> <profile> - <id>example</id> - <build> - <plugins> - <plugin> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-maven-plugin</artifactId> - <executions> - <execution> - <id>create</id> - <goals> - <goal>create</goal> - </goals> - </execution> - <execution> - <id>start</id> - <goals> - <goal>cli</goal> - </goals> - <configuration> - <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.ConsumerRateLimitExample</clientClass> - </configuration> - </execution> - <execution> - <id>stop</id> - <goals> - <goal>cli</goal> - </goals> - <configuration> - <args> - <param>stop</param> - </args> - </configuration> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>org.apache.activemq.examples.jms</groupId> - <artifactId>artemis-jms-consumer-rate-limit-example</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - </plugin> - </plugins> - </build> + <!-- 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.ConsumerRateLimitExample</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>consumer-rate-limit</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> </project> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/consumer-rate-limit/readme.html ---------------------------------------------------------------------- diff --git a/examples/jms/consumer-rate-limit/readme.html b/examples/jms/consumer-rate-limit/readme.html index 6492b37..8b7c9e2 100644 --- a/examples/jms/consumer-rate-limit/readme.html +++ b/examples/jms/consumer-rate-limit/readme.html @@ -26,6 +26,7 @@ under the License. </head> <body onload="prettyPrint()"> <h1>JMS Message Consumer Rate Limiting</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>With ActiveMQ Artemis you can specify a maximum consume rate at which a JMS MessageConsumer will consume messages. This can be specified when creating or configuring the connection factory. See <code>jndi.properties</code>.</p> @@ -42,131 +43,5 @@ connectionFactory.ConnectionFactory=tcp://localhost:61616?consumerMaxRate=10 <p>We then simply consume as many messages as we can in 10 seconds and note how many messages are actually consumed.</p> <p>We note that the number of messages consumed per second never exceeds the specified value of <code>10</code> messages per second.</p> - <p><i>To run the example, simply type <code>mvn verify -Pexample</code> from this directory</i></p> - - <ol> - <li>Create an initial context to perform the JNDI lookup.</li> - <pre class="prettyprint"> - <code>initialContext = getContext(0);</code> - </pre> - - <li>Perfom a lookup on the queue</li> - <pre class="prettyprint"> - <code>Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue");</code> - </pre> - - <li>Perform a lookup on the Connection Factory</li> - <pre class="prettyprint"> - <code>ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");</code> - </pre> - - <li>Create a JMS Connection</li> - <pre class="prettyprint"> - <code>connection = cf.createConnection();</code> - </pre> - - <li>Create a JMS Session</li> - <pre class="prettyprint"> - <code>Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);</code> - </pre> - - <li>Create a JMS MessageProducer</li> - <pre class="prettyprint"> - <code>MessageProducer producer = session.createProducer(queue);</code> - </pre> - - <li>Create a JMS MessageConsumer</li> - <pre class="prettyprint"> - <code>MessageConsumer consumer = session.createConsumer(queue);</code> - </pre> - - <li>Start the connection</li> - - <pre class="prettyprint"> - <code> - connection.start(); - </code> - </pre> - - - <li>Send a bunch of messages</li> - <pre class="prettyprint"> - <code> - final int numMessages = 150; - - for (int i = 0; i < numMessages; i++) - { - TextMessage message = session.createTextMessage("This is text message: " + i); - - producer.send(message); - } - </code> - </pre> - - <li>Consume as many messages as we can in 10 seconds</li> - - <pre class="prettyprint"> - <code> - final long duration = 10000; - - int i = 0; - - long start = System.currentTimeMillis(); - - while (System.currentTimeMillis() - start <= duration) - { - TextMessage message = (TextMessage)consumer.receive(2000); - - if (message == null) - { - return false; - } - - i++; - } - - long end = System.currentTimeMillis(); - - double rate = 1000 * (double)i / (end - start); - - System.out.println("We consumed " + i + " messages in " + (end - start) + " milliseconds"); - - System.out.println("Actual consume rate was " + rate + " messages per second"); - </code> - </pre> - - <li>This should produce output something like:</li> - - <pre class="prettyprint"> - <code> - [java] Sent messages - [java] Will now try and consume as many as we can in 10 seconds ... - [java] We consumed 100 messages in 10001 milliseconds - [java] Actual consume rate was 9.99900009999 messages per second - - </code> - </pre> - - <li>Be sure to close our resources!</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/dd820318/examples/jms/dead-letter/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/dead-letter/pom.xml b/examples/jms/dead-letter/pom.xml index 94f2c4c..5a39fd4 100644 --- a/examples/jms/dead-letter/pom.xml +++ b/examples/jms/dead-letter/pom.xml @@ -18,7 +18,8 @@ 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"> +<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> @@ -27,7 +28,7 @@ under the License. <version>1.0.1-SNAPSHOT</version> </parent> - <artifactId>artemis-jms-dead-letter-example</artifactId> + <artifactId>dead-letter</artifactId> <packaging>jar</packaging> <name>ActiveMQ Artemis JMS Dead Letter Example</name> @@ -37,71 +38,82 @@ under the License. <dependencies> <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-jms_2.0_spec</artifactId> + <groupId>org.apache.activemq</groupId> + <artifactId>artemis-jms-client</artifactId> + <version>${project.version}</version> </dependency> </dependencies> <profiles> <profile> - <id>example</id> - <build> - <plugins> - <plugin> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-maven-plugin</artifactId> - <executions> - <execution> - <id>create</id> - <goals> - <goal>create</goal> - </goals> - </execution> - <execution> - <id>start</id> - <goals> - <goal>cli</goal> - </goals> - <configuration> - <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.DeadLetterExample</clientClass> - </configuration> - </execution> - <execution> - <id>stop</id> - <goals> - <goal>cli</goal> - </goals> - <configuration> - <args> - <param>stop</param> - </args> - </configuration> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>org.apache.activemq.examples.jms</groupId> - <artifactId>artemis-jms-dead-letter-example</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - </plugin> - </plugins> - </build> + <!-- 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> + <configuration>${basedir}/target/classes/activemq/server0</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.DeadLetterExample</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>dead-letter</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> </project>
