http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/no-consumer-buffering/readme.html ---------------------------------------------------------------------- diff --git a/examples/jms/no-consumer-buffering/readme.html b/examples/jms/no-consumer-buffering/readme.html deleted file mode 100644 index 7f5e427..0000000 --- a/examples/jms/no-consumer-buffering/readme.html +++ /dev/null @@ -1,205 +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 No Consumer Buffering 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>No Consumer Buffering 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>By default, ActiveMQ Artemis consumers buffer messages from the server in a client side buffer - before actual delivery actually occurs.</p> - <p>This improves performance since otherwise every time you called receive() or had processed the last - message in a MessageListener onMessage() method, the ActiveMQ Artemis client would have to go the - server to request the next message involving a network round trip for every message reducing performance.</p> - <p>Therefore, by default, ActiveMQ Artemis pre-fetches messages into a buffer on each consumer. The total maximum size of - messages in bytes that will be buffered on each consumer is determined by the <code>consumer-window-size</code> - parameter on the connection factory.</p> - <p>In some cases it is not desirable to buffer any messages on the client side consumer.</p> - <p>An example would be an order queue which had multiple consumers that processed orders from the queue. - Each order takes a significant time to process, but each one should be processed in a timely fashion.</p> - <p>If orders were buffered in each consumer, and a new consumer was added that consumer would not be able - to process orders which were already in the client side buffer of another consumer.</p> - <p>To turn off client side buffering of messages, set <code>consumer-window-size</code> to zero.</p> - - <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 deploying the connection factory. See <code>activemq-jms.xml</code></p> - <h2>Example step-by-step</h2> - <p>In this example we specify a <code>consumer-window-size</code> of <code>0</code> bytes in the <code>activemq-jms.xml</code> - file when deploying the connection factory:</p> - <pre class="prettyprint"> - <code> - <connection-factory name="ConnectionFactory"> - <connector-ref connector-name="netty-connector"/> - <entries> - <entry name="ConnectionFactory"/> - </entries> - - <!-- We set the consumer window size to 0, which means messages are not buffered at all - on the client side --> - <consumer-window-size>0</consumer-window-size> - - </connection-factory> - </code> - </pre> - <p>We create a consumer on a queue and send 10 messages to it. We then create another consumer on - the same queue.</p> - <p>We then consume messages from each consumer in a semi-random order. We note that the messages - are consumed in the order they were sent.</p> - <p>If the messages had been buffered in each consumer they would not be available to be consumed - in an order determined afer delivery.</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 consumer1 = session.createConsumer(queue);</code> - </pre> - - <li>Start the connection</li> - - <pre class="prettyprint"> - <code> - connection.start(); - </code> - </pre> - - - <li>Send 10 messages to the queue</li> - <pre class="prettyprint"> - <code> - final int numMessages = 10; - - for (int i = 0; i < numMessages; i++) - { - TextMessage message = session.createTextMessage("This is text message: " + i); - - producer.send(message); - } - </code> - </pre> - - <li>Create another JMS MessageConsumer on the same queue.</li> - <pre class="prettyprint"> - <code>MessageConsumer consumer2 = session.createConsumer(queue);</code> - </pre> - - <li>Consume three messages from consumer2</li> - - <pre class="prettyprint"> - <code> - for (int i = 0; i < 3; i++) - { - TextMessage message = (TextMessage)consumer2.receive(2000); - - System.out.println("Consumed message from consumer2: " + message.getText()); - } - </code> - </pre> - - <li>Consume five messages from consumer1</li> - - <pre class="prettyprint"> - <code> - for (int i = 0; i < 5; i++) - { - TextMessage message = (TextMessage)consumer1.receive(2000); - - System.out.println("Consumed message from consumer1: " + message.getText()); - } - </code> - </pre> - - <li>Consume two more messages from consumer2</li> - - <pre class="prettyprint"> - <code> - for (int i = 0; i < 2; i++) - { - TextMessage message = (TextMessage)consumer1.receive(2000); - - System.out.println("Consumed message from consumer2: " + message.getText()); - } - </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> - - <h2>More information</h2> - - <ul> - <li>User Manual's <a href="../../../docs/user-manual/en/html_single/index.html#flow-control.consumer.window">Consumer Window-Based Flow Control chapter</a></li> - </ul> - - </body> -</html>
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/no-consumer-buffering/src/main/java/org/apache/activemq/artemis/jms/example/NoConsumerBufferingExample.java ---------------------------------------------------------------------- diff --git a/examples/jms/no-consumer-buffering/src/main/java/org/apache/activemq/artemis/jms/example/NoConsumerBufferingExample.java b/examples/jms/no-consumer-buffering/src/main/java/org/apache/activemq/artemis/jms/example/NoConsumerBufferingExample.java deleted file mode 100644 index 6f321b0..0000000 --- a/examples/jms/no-consumer-buffering/src/main/java/org/apache/activemq/artemis/jms/example/NoConsumerBufferingExample.java +++ /dev/null @@ -1,110 +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.ConnectionFactory; -import javax.jms.MessageConsumer; -import javax.jms.MessageProducer; -import javax.jms.Queue; -import javax.jms.Session; -import javax.jms.TextMessage; - -import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; -import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; - -/** - * This example demonstrates how ActiveMQ Artemis consumers can be configured to not buffer any messages from - * the server. - */ -public class NoConsumerBufferingExample { - - public static void main(final String[] args) throws Exception { - Connection connection = null; - try { - // Step 2. Perfom a lookup on the queue - Queue queue = ActiveMQJMSClient.createQueue("exampleQueue"); - - // Step 3. new Connection factory with consumerWindowsize=0 - ConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616?consumerWindowSize=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 a JMS Message Producer - MessageProducer producer = session.createProducer(queue); - - // Step 7. Create a JMS MessageConsumer - - MessageConsumer consumer1 = session.createConsumer(queue); - - // Step 8. Start the connection - - connection.start(); - - // Step 9. Send 10 messages to the queue - - final int numMessages = 10; - - for (int i = 0; i < numMessages; i++) { - TextMessage message = session.createTextMessage("This is text message: " + i); - - producer.send(message); - } - - System.out.println("Sent messages"); - - // Step 10. Create another consumer on the same queue - - MessageConsumer consumer2 = session.createConsumer(queue); - - // Step 11. Consume three messages from consumer2 - - for (int i = 0; i < 3; i++) { - TextMessage message = (TextMessage) consumer2.receive(2000); - - System.out.println("Consumed message from consumer2: " + message.getText()); - } - - // Step 12. Consume five messages from consumer1 - - for (int i = 0; i < 5; i++) { - TextMessage message = (TextMessage) consumer1.receive(2000); - - System.out.println("Consumed message from consumer1: " + message.getText()); - } - - // Step 13. Consume another two messages from consumer2 - - for (int i = 0; i < 2; i++) { - TextMessage message = (TextMessage) consumer2.receive(2000); - - System.out.println("Consumed message from consumer1: " + message.getText()); - } - } - finally { - // Step 9. Be sure to close our resources! - - if (connection != null) { - connection.close(); - } - } - } -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/no-consumer-buffering/src/main/resources/jndi.properties ---------------------------------------------------------------------- diff --git a/examples/jms/no-consumer-buffering/src/main/resources/jndi.properties b/examples/jms/no-consumer-buffering/src/main/resources/jndi.properties deleted file mode 100644 index d9b77a6..0000000 --- a/examples/jms/no-consumer-buffering/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?consumerWindowSize=0 -queue.queue/exampleQueue=exampleQueue http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/non-transaction-failover/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/non-transaction-failover/pom.xml b/examples/jms/non-transaction-failover/pom.xml deleted file mode 100644 index 6dec19e..0000000 --- a/examples/jms/non-transaction-failover/pom.xml +++ /dev/null @@ -1,109 +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>non-transaction-failover</artifactId> - <packaging>jar</packaging> - <name>ActiveMQ Artemis JMS Non Transaction 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.activemq</groupId> - <artifactId>artemis-jms-client</artifactId> - <version>${project.version}</version> - </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>runClient</id> - <goals> - <goal>runClient</goal> - </goals> - <configuration> - <clientClass>org.apache.activemq.artemis.jms.example.NonTransactionFailoverExample</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>non-transaction-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/non-transaction-failover/readme.html ---------------------------------------------------------------------- diff --git a/examples/jms/non-transaction-failover/readme.html b/examples/jms/non-transaction-failover/readme.html deleted file mode 100644 index 3667284..0000000 --- a/examples/jms/non-transaction-failover/readme.html +++ /dev/null @@ -1,157 +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 Failover Without Transactions 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 Failover Without Transactions Example</h1> - - <pre>To run the example, simply type <b>mvn verify</b> from this directory.</pre> - - - <p>This example demonstrates two servers coupled as a live-backup pair for high availability (HA), and a client - connection failing over from live to backup when the live server is crashed.</p> - <p>Failover behavior differs whether the JMS session is transacted or not.</p> - <p>When a <em>non-transacted</em> JMS session is used, once and only once delivery is not guaranteed - and it is possible some messages will be lost or delivered twice, depending when the failover to the backup server occurs.</p> - <p>It is up to the client to deal with such cases. To ensure once and only once delivery, the client must - use transacted JMS sessions (as shown in the example for <a href="../transaction-failover/readme.html">failover with transactions</a>).</p> - <p>For more information on ActiveMQ Artemis failover and HA, and clustering in general, please see the clustering - section of the user manual.</p> - - <h2>Example step-by-step</h2> - <p>In this example, the live server is server 1, and the backup server is server 0</p> - <p>The connection will initially be created to server1, server 1 will crash, and the client will carry on - seamlessly on server 0, the backup server.</p> - <ol> - <li>Get an initial context for looking up JNDI from server #1.</li> - <pre class="prettyprint"> - initialContext = getContext(1); - </pre> - - <li>Look up the JMS resources from JNDI on server #1.</li> - <pre class="prettyprint"> - Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue"); - ConnectionFactory connectionFactory = (ConnectionFactory)initialContext.lookup("/ConnectionFactory"); - </pre> - - <li>Create a JMS Connection</li> - <pre class="prettyprint"> - connection = connectionFactory.createConnection(); - </pre> - - <li>Create a JMS <em>non-transacted</em> Session with client acknowledgement</li> - <pre class="prettyprint"> - Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); - </pre> - - <li>Start the connection to ensure delivery occurs</li> - <pre class="prettyprint"> - connection.start(); - </pre> - - <li>Create a JMS MessageProducer and MessageConsumer</li> - <pre class="prettyprint"> - MessageProducer producer = session.createProducer(queue); - MessageConsumer consumer = session.createConsumer(queue); - </pre> - - <li>Send some messages to server #1</li> - <pre class="prettyprint"> - 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()); - } - </pre> - - <li>Receive and acknowledge half of the sent messages</li> - <pre class="prettyprint"> - 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(); - </pre> - - <li>Receive the second half of the sent messages but <em>do not acknowledge them yet</em></li> - <pre class="prettyprint"> - for (int i = numMessages / 2; i < numMessages; i++) - { - message0 = (TextMessage)consumer.receive(5000); - System.out.println("Got message: " + message0.getText()); - } - </pre> - - <li>Crash server #1, the live server, and wait a little while to make sure it has really crashed.</li> - <pre class="prettyprint"> - killServer(1); - Thread.sleep(2000); - </pre> - - <li>Acknowledging the second half of the sent messages will fail as failover to the backup server has occurred</li> - <pre class="prettyprint"> - try - { - message0.acknowledge(); - } - catch (JMSException e) - { - System.err.println("Got exception while acknowledging message: " + e.getMessage()); - } - </pre> - - <li>Consume again the second half of the messages againg. Note that they are not considered as redelivered</li> - <pre class="prettyprint"> - for (int i = numMessages / 2; i < numMessages; i++) - { - message0 = (TextMessage)consumer.receive(5000); - System.out.printf("Got message: %s (redelivered?: %s)\n", message0.getText(), message0.getJMSRedelivered()); - } - message0.acknowledge(); - </pre> - - <li>And finally, <strong>always</strong> remember to close your 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"> - finally - { - if (connection != null) - { - connection.close(); - } - - if (initialContext != null) - { - initialContext.close(); - } - } - </pre> - - </ol> - </body> -</html> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/non-transaction-failover/src/main/java/org/apache/activemq/artemis/jms/example/NonTransactionFailoverExample.java ---------------------------------------------------------------------- diff --git a/examples/jms/non-transaction-failover/src/main/java/org/apache/activemq/artemis/jms/example/NonTransactionFailoverExample.java b/examples/jms/non-transaction-failover/src/main/java/org/apache/activemq/artemis/jms/example/NonTransactionFailoverExample.java deleted file mode 100644 index 9352ac5..0000000 --- a/examples/jms/non-transaction-failover/src/main/java/org/apache/activemq/artemis/jms/example/NonTransactionFailoverExample.java +++ /dev/null @@ -1,128 +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; - -/** - * A simple example that demonstrates failover of the JMS connection from one node to another - * when the live server crashes using a JMS <em>non-transacted</em> session. - */ -public class NonTransactionFailoverExample { - - public static void main(final String[] args) throws Exception { - final int numMessages = 10; - - Connection connection = null; - - InitialContext initialContext = null; - - Process[] servers = new Process[2]; - - try { - for (int i = 0; i < args.length; i++) { - servers[i] = ServerUtil.startServer(args[i], NonTransactionFailoverExample.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 half of the sent messages - 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(); - - // Step 9. Receive the 2nd half of the sent messages but *do not* acknowledge them yet - for (int i = numMessages / 2; 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 - // pending Acks are on the server's side - 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 half of the messages again. Note that they are not considered as redelivered. - for (int i = numMessages / 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/non-transaction-failover/src/main/resources/jndi.properties ---------------------------------------------------------------------- diff --git a/examples/jms/non-transaction-failover/src/main/resources/jndi.properties b/examples/jms/non-transaction-failover/src/main/resources/jndi.properties deleted file mode 100644 index 7f7a19f..0000000 --- a/examples/jms/non-transaction-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/paging/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/paging/pom.xml b/examples/jms/paging/pom.xml deleted file mode 100644 index 22c0c60..0000000 --- a/examples/jms/paging/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>paging</artifactId> - <packaging>jar</packaging> - <name>ActiveMQ Artemis JMS Paging 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.PagingExample</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>paging</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/paging/readme.html ---------------------------------------------------------------------- diff --git a/examples/jms/paging/readme.html b/examples/jms/paging/readme.html deleted file mode 100644 index 1f9afd3..0000000 --- a/examples/jms/paging/readme.html +++ /dev/null @@ -1,187 +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 Paging 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>Paging 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 ActiveMQ Artemis would avoid running out of memory resources by paging messages.</p> - <p>A maxSize can be specified per Destination via the destinations settings configuration file (broker.xml).</p> - <p>When messages routed to an address exceed the specified maxSize the server will begin to write messages to the file - system, this is called paging. This will continue to occur until messages have been delivered to consumers and subsequently - acknowledged freeing up memory. Messages will then be read from the file system , i.e. depaged, and routed as normal. </p> - <p>Acknowledgement plays an important factor on paging as messages will stay on the file system until the memory is released - so it is important to make sure that the client acknowledges its messages.</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 connection factory object from JNDI</li> - <pre class="prettyprint"> - <code>ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");</code> - </pre> - - <li>We look-up the JMS queue object from JNDI. pagingQueue is configured to hold a very limited number of bytes in memory</li> - <pre class="prettyprint"> - <code>Queue pageQueue = (Queue) initialContext.lookup("/queue/pagingQueue");</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 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. We will use client acknowledgement on this example.</li> - <pre class="prettyprint"> - <code>Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);</code> - </pre> - - - <li>Create a JMS Message Producer for pageQueueAddress</li> - <pre class="prettyprint"><code> - MessageProducer pageMessageProducer = session.createProducer(pageQueue); - </pre></code> - - <li>We don't need persistent messages in order to use paging. (This step is optional)</li> - <pre class="prettyprint"><code> - pageMessageProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); - </pre></code> - - <li>Create a Binary Bytes Message with 10K arbitrary bytes</li> - <pre class="prettyprint"><code> - BytesMessage message = session.createBytesMessage(); - message.writeBytes(new byte[10 * 1024]); - </pre></code> - - - <li>Send only 20 messages to the Queue. This will be already enough for pagingQueue. Look at ./paging/config/activemq-queues.xml for the config.</li> - <pre class="prettyprint"><code> - for (int i = 0; i < 20; i++) - { - pageMessageProducer.send(message); - } - </pre></code> - - <li>Create a JMS Message Producer</li> - <pre class="prettyprint"><code> - MessageProducer messageProducer = session.createProducer(queue); - </pre></code> - - <li>We don't need persistent messages in order to use paging. (This step is optional)</li> - <pre class="prettyprint"><code> - messageProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); - </pre></code> - - <li>Send the message for about 30K, which should be over the memory limit imposed by the server</li> - <pre class="prettyprint"><code> - for (int i = 0; i < 30000; i++) - { - messageProducer.send(message); - } - </pre></code> - - <li>if you pause the example here, you will several files under ./build/data/paging</li> - - <pre class="prettyprint"><code> - // Thread.sleep(30000); // if you want to just our of curiosity, you can sleep here and inspect the created files just for - </pre></code> - - - <li>Create a JMS Message Consumer</li> - <pre class="prettyprint"><code> - MessageConsumer messageConsumer = session.createConsumer(queue); - </pre></code> - - - <li>Start the JMS Connection. This step will activate the subscribers to receive messages.</li> - <pre class="prettyprint"><code> - connection.start(); - </pre></code> - - - <li>Receive the messages. It's important to ACK for messages as ActiveMQ Artemis will not read messages from paging until messages are ACKed</li> - - <pre class="prettyprint"><code> - for (int i = 0; i < 30000; i++) - { - message = (BytesMessage)messageConsumer.receive(1000); - - if (i % 1000 == 0) - { - System.out.println("Received " + i + " messages"); - - message.acknowledge(); - } - } - </pre></code> - - <li>Receive the messages from the Queue names pageQueue. Create the proper consumer for that.</li> - <pre class="prettyprint"><code> - messageConsumer.close(); - messageConsumer = session.createConsumer(pageQueue); - - for (int i = 0; i < 20; i++) - { - message = (BytesMessage)messageConsumer.receive(1000); - - System.out.println("Received message " + i + " from pageQueue"); - - message.acknowledge(); - } - </pre></code> - - <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/paging/src/main/java/org/apache/activemq/artemis/jms/example/PagingExample.java ---------------------------------------------------------------------- diff --git a/examples/jms/paging/src/main/java/org/apache/activemq/artemis/jms/example/PagingExample.java b/examples/jms/paging/src/main/java/org/apache/activemq/artemis/jms/example/PagingExample.java deleted file mode 100644 index 19d8a17..0000000 --- a/examples/jms/paging/src/main/java/org/apache/activemq/artemis/jms/example/PagingExample.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 javax.jms.BytesMessage; -import javax.jms.Connection; -import javax.jms.ConnectionFactory; -import javax.jms.DeliveryMode; -import javax.jms.MessageConsumer; -import javax.jms.MessageProducer; -import javax.jms.Queue; -import javax.jms.Session; -import javax.naming.InitialContext; - -/** - * A simple JMS Queue example that creates a producer and consumer on a queue and sends then receives a message. - */ -public class PagingExample { - - public static void main(final String[] args) throws Exception { - Connection connection = null; - - InitialContext initialContext = null; - try { - // Step 1. Create an initial context to perform the JNDI lookup. - initialContext = new InitialContext(); - - // Step 2. Perform a lookup on the Connection Factory - ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("ConnectionFactory"); - - // Step 3. We look-up the JMS queue object from JNDI. pagingQueue is configured to hold a very limited number - // of bytes in memory - Queue pageQueue = (Queue) initialContext.lookup("queue/pagingQueue"); - - // Step 4. Lookup for a JMS Queue - Queue queue = (Queue) initialContext.lookup("queue/exampleQueue"); - - // Step 5. Create a JMS Connection - connection = cf.createConnection(); - - // Step 6. Create a JMS Session - Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); - - // Step 7. Create a JMS Message Producer for pageQueueAddress - MessageProducer pageMessageProducer = session.createProducer(pageQueue); - - // Step 8. We don't need persistent messages in order to use paging. (This step is optional) - pageMessageProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); - - // Step 9. Create a Binary Bytes Message with 10K arbitrary bytes - BytesMessage message = session.createBytesMessage(); - message.writeBytes(new byte[10 * 1024]); - - // Step 10. Send only 20 messages to the Queue. This will be already enough for pagingQueue. Look at - // ./paging/config/activemq-queues.xml for the config. - for (int i = 0; i < 20; i++) { - pageMessageProducer.send(message); - } - - // Step 11. Create a JMS Message Producer - MessageProducer messageProducer = session.createProducer(queue); - - // Step 12. We don't need persistent messages in order to use paging. (This step is optional) - messageProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); - - // Step 13. Send the message for about 1K, which should be over the memory limit imposed by the server - for (int i = 0; i < 1000; i++) { - messageProducer.send(message); - } - - // Step 14. if you pause this example here, you will see several files under ./build/data/paging - // Thread.sleep(30000); // if you want to just our of curiosity, you can sleep here and inspect the created - // files just for - - // Step 15. Create a JMS Message Consumer - MessageConsumer messageConsumer = session.createConsumer(queue); - - // Step 16. Start the JMS Connection. This step will activate the subscribers to receive messages. - connection.start(); - - // Step 17. Receive the messages. It's important to ACK for messages as ActiveMQ Artemis will not read messages from - // paging - // until messages are ACKed - - for (int i = 0; i < 1000; i++) { - message = (BytesMessage) messageConsumer.receive(3000); - - if (i % 100 == 0) { - System.out.println("Received " + i + " messages"); - message.acknowledge(); - } - } - - message.acknowledge(); - - // Step 18. Receive the messages from the Queue names pageQueue. Create the proper consumer for that - messageConsumer.close(); - messageConsumer = session.createConsumer(pageQueue); - - for (int i = 0; i < 20; i++) { - message = (BytesMessage) messageConsumer.receive(1000); - - System.out.println("Received message " + i + " from pageQueue"); - - message.acknowledge(); - } - } - finally { - // And finally, always remember to close your JMS connections after use, in a finally block. Closing a JMS - // connection will automatically close all of its sessions, consumers, producer and browser objects - - if (initialContext != null) { - initialContext.close(); - } - - if (connection != null) { - connection.close(); - } - } - } -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/paging/src/main/resources/activemq/server0/artemis-roles.properties ---------------------------------------------------------------------- diff --git a/examples/jms/paging/src/main/resources/activemq/server0/artemis-roles.properties b/examples/jms/paging/src/main/resources/activemq/server0/artemis-roles.properties deleted file mode 100644 index 4e2d44c..0000000 --- a/examples/jms/paging/src/main/resources/activemq/server0/artemis-roles.properties +++ /dev/null @@ -1,17 +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. -## --------------------------------------------------------------------------- -guest=guest \ No newline at end of file http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/paging/src/main/resources/activemq/server0/artemis-users.properties ---------------------------------------------------------------------- diff --git a/examples/jms/paging/src/main/resources/activemq/server0/artemis-users.properties b/examples/jms/paging/src/main/resources/activemq/server0/artemis-users.properties deleted file mode 100644 index 4e2d44c..0000000 --- a/examples/jms/paging/src/main/resources/activemq/server0/artemis-users.properties +++ /dev/null @@ -1,17 +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. -## --------------------------------------------------------------------------- -guest=guest \ No newline at end of file http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/paging/src/main/resources/activemq/server0/broker.xml ---------------------------------------------------------------------- diff --git a/examples/jms/paging/src/main/resources/activemq/server0/broker.xml b/examples/jms/paging/src/main/resources/activemq/server0/broker.xml deleted file mode 100644 index a7a1969..0000000 --- a/examples/jms/paging/src/main/resources/activemq/server0/broker.xml +++ /dev/null @@ -1,93 +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. ---> - -<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns="urn:activemq" - xsi:schemaLocation="urn:activemq /schema/artemis-server.xsd"> - - <jms xmlns="urn:activemq:jms"> - <!--the topic used by the example--> - <queue name="exampleQueue"/> - - <queue name="pagingQueue"/> - </jms> - - <core xmlns="urn:activemq:core"> - - <bindings-directory>${data.dir}/server0/data/messaging/bindings</bindings-directory> - - <journal-directory>${data.dir}/server0/data/messaging/journal</journal-directory> - - <large-messages-directory>${data.dir}/server0/data/messaging/largemessages</large-messages-directory> - - <paging-directory>${data.dir}/server0/data/messaging/paging</paging-directory> - - - <!-- Connectors --> - <connectors> - <connector name="netty-connector">tcp://localhost:61616</connector> - </connectors> - - <!-- Acceptors --> - <acceptors> - <acceptor name="netty-acceptor">tcp://localhost:61616</acceptor> - </acceptors> - - <!-- Other config --> - - <security-settings> - <!--security for example queue--> - <security-setting match="jms.queue.exampleQueue"> - <permission type="createDurableQueue" roles="guest"/> - <permission type="deleteDurableQueue" roles="guest"/> - <permission type="createNonDurableQueue" roles="guest"/> - <permission type="deleteNonDurableQueue" roles="guest"/> - <permission type="consume" roles="guest"/> - <permission type="send" roles="guest"/> - </security-setting> - - <security-setting match="jms.queue.pagingQueue"> - <permission type="createDurableQueue" roles="guest"/> - <permission type="deleteDurableQueue" roles="guest"/> - <permission type="createNonDurableQueue" roles="guest"/> - <permission type="deleteNonDurableQueue" roles="guest"/> - <permission type="consume" roles="guest"/> - <permission type="send" roles="guest"/> - </security-setting> - </security-settings> - - <address-settings> - <address-setting match="jms.queue.pagingQueue"> - <max-size-bytes>100000</max-size-bytes> - <page-size-bytes>20000</page-size-bytes> - </address-setting> - - <address-setting match="jms.queue.exampleQueue"> - <max-size-bytes>10485760</max-size-bytes> - <page-size-bytes>1048576</page-size-bytes> - </address-setting> - <address-setting match="#"> - <max-size-bytes>10485760</max-size-bytes> - <page-size-bytes>1048576</page-size-bytes> - </address-setting> - </address-settings> - - </core> -</configuration> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/paging/src/main/resources/jndi.properties ---------------------------------------------------------------------- diff --git a/examples/jms/paging/src/main/resources/jndi.properties b/examples/jms/paging/src/main/resources/jndi.properties deleted file mode 100644 index 6f70010..0000000 --- a/examples/jms/paging/src/main/resources/jndi.properties +++ /dev/null @@ -1,21 +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 -queue.queue/pagingQueue=pagingQueue http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/perf/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/perf/pom.xml b/examples/jms/perf/pom.xml deleted file mode 100644 index a1eb6ef..0000000 --- a/examples/jms/perf/pom.xml +++ /dev/null @@ -1,160 +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>perf</artifactId> - <packaging>jar</packaging> - <name>ActiveMQ Artemis JMS PerfExample Example</name> - - <properties> - <activemq.basedir>${project.basedir}/../../..</activemq.basedir> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-server</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-jms-server</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-core-client</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-commons</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>io.netty</groupId> - <artifactId>netty-all</artifactId> - <version>${netty.version}</version> - </dependency> - <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-jms_2.0_spec</artifactId> - </dependency> - </dependencies> - - <profiles> - <profile> - <id>server</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>runClient</id> - <goals> - <goal>runClient</goal> - </goals> - <configuration> - <clientClass>org.apache.activemq.artemis.jms.example.Server</clientClass> - </configuration> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>org.apache.activemq.examples.jms</groupId> - <artifactId>perf</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-core-client</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - </plugin> - </plugins> - </build> - </profile> - <profile> - <id>listener</id> - <build> - <plugins> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>exec-maven-plugin</artifactId> - <version>1.1</version> - <executions> - <execution> - <phase>package</phase> - <goals> - <goal>java</goal> - </goals> - </execution> - </executions> - <configuration> - <mainClass>org.apache.activemq.artemis.jms.example.PerfListener</mainClass> - </configuration> - </plugin> - </plugins> - </build> - </profile> - <profile> - <id>sender</id> - <build> - <plugins> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>exec-maven-plugin</artifactId> - <version>1.1</version> - <executions> - <execution> - <phase>package</phase> - <goals> - <goal>java</goal> - </goals> - </execution> - </executions> - <configuration> - <mainClass>org.apache.activemq.artemis.jms.example.PerfSender</mainClass> - </configuration> - </plugin> - </plugins> - </build> - </profile> - </profiles> - - -</project> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/perf/readme.html ---------------------------------------------------------------------- diff --git a/examples/jms/perf/readme.html b/examples/jms/perf/readme.html deleted file mode 100644 index c3d44c2..0000000 --- a/examples/jms/perf/readme.html +++ /dev/null @@ -1,39 +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 Queue Selector 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 Simple Performance</h1> - - <p>To start the server run <code>mvn verify -Pexample</code></p> - - <p>To start the listener run <code>mvn -Plistener package</code></p> - - <p>To start the sender run <code>mvn -Psender package</code></p> - - <p>To configure the clients simply edit the <code>perf.properties</code> or <code>client.jndi.properties</code> in the - <code>src/main/resources</code> directory</p> - </body> -</html> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/perf/src/main/java/org/apache/activemq/artemis/jms/example/PerfBase.java ---------------------------------------------------------------------- diff --git a/examples/jms/perf/src/main/java/org/apache/activemq/artemis/jms/example/PerfBase.java b/examples/jms/perf/src/main/java/org/apache/activemq/artemis/jms/example/PerfBase.java deleted file mode 100644 index 869ee09..0000000 --- a/examples/jms/perf/src/main/java/org/apache/activemq/artemis/jms/example/PerfBase.java +++ /dev/null @@ -1,400 +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.io.FileInputStream; -import java.io.InputStream; -import java.util.Properties; -import java.util.Random; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.atomic.AtomicLong; -import java.util.logging.Logger; - -import javax.jms.*; -import javax.naming.InitialContext; - -import org.apache.activemq.artemis.utils.TokenBucketLimiter; -import org.apache.activemq.artemis.utils.TokenBucketLimiterImpl; - -public abstract class PerfBase { - - private static final Logger log = Logger.getLogger(PerfSender.class.getName()); - - private static final String DEFAULT_PERF_PROPERTIES_FILE_NAME = "target/classes/perf.properties"; - - private static byte[] randomByteArray(final int length) { - byte[] bytes = new byte[length]; - - Random random = new Random(); - - for (int i = 0; i < length; i++) { - bytes[i] = Integer.valueOf(random.nextInt()).byteValue(); - } - - return bytes; - } - - protected static String getPerfFileName(final String[] args) { - String fileName; - - if (args.length > 0) { - fileName = args[0]; - } - else { - fileName = PerfBase.DEFAULT_PERF_PROPERTIES_FILE_NAME; - } - - return fileName; - } - - protected static PerfParams getParams(final String fileName) throws Exception { - Properties props = null; - - InputStream is = null; - - try { - is = new FileInputStream(fileName); - - props = new Properties(); - - props.load(is); - } - finally { - if (is != null) { - is.close(); - } - } - - int noOfMessages = Integer.valueOf(props.getProperty("num-messages")); - int noOfWarmupMessages = Integer.valueOf(props.getProperty("num-warmup-messages")); - int messageSize = Integer.valueOf(props.getProperty("message-size")); - boolean durable = Boolean.valueOf(props.getProperty("durable")); - boolean transacted = Boolean.valueOf(props.getProperty("transacted")); - int batchSize = Integer.valueOf(props.getProperty("batch-size")); - boolean drainQueue = Boolean.valueOf(props.getProperty("drain-queue")); - String destinationLookup = props.getProperty("destination-lookup"); - String connectionFactoryLookup = props.getProperty("connection-factory-lookup"); - int throttleRate = Integer.valueOf(props.getProperty("throttle-rate")); - boolean dupsOK = Boolean.valueOf(props.getProperty("dups-ok-acknowlege")); - boolean disableMessageID = Boolean.valueOf(props.getProperty("disable-message-id")); - boolean disableTimestamp = Boolean.valueOf(props.getProperty("disable-message-timestamp")); - - PerfBase.log.info("num-messages: " + noOfMessages); - PerfBase.log.info("num-warmup-messages: " + noOfWarmupMessages); - PerfBase.log.info("message-size: " + messageSize); - PerfBase.log.info("durable: " + durable); - PerfBase.log.info("transacted: " + transacted); - PerfBase.log.info("batch-size: " + batchSize); - PerfBase.log.info("drain-queue: " + drainQueue); - PerfBase.log.info("throttle-rate: " + throttleRate); - PerfBase.log.info("connection-factory-lookup: " + connectionFactoryLookup); - PerfBase.log.info("destination-lookup: " + destinationLookup); - PerfBase.log.info("disable-message-id: " + disableMessageID); - PerfBase.log.info("disable-message-timestamp: " + disableTimestamp); - PerfBase.log.info("dups-ok-acknowledge: " + dupsOK); - - PerfParams perfParams = new PerfParams(); - perfParams.setNoOfMessagesToSend(noOfMessages); - perfParams.setNoOfWarmupMessages(noOfWarmupMessages); - perfParams.setMessageSize(messageSize); - perfParams.setDurable(durable); - perfParams.setSessionTransacted(transacted); - perfParams.setBatchSize(batchSize); - perfParams.setDrainQueue(drainQueue); - perfParams.setConnectionFactoryLookup(connectionFactoryLookup); - perfParams.setDestinationLookup(destinationLookup); - perfParams.setThrottleRate(throttleRate); - perfParams.setDisableMessageID(disableMessageID); - perfParams.setDisableTimestamp(disableTimestamp); - perfParams.setDupsOK(dupsOK); - - return perfParams; - } - - private final PerfParams perfParams; - - protected PerfBase(final PerfParams perfParams) { - this.perfParams = perfParams; - } - - private ConnectionFactory factory; - - private Connection connection; - - private Session session; - - private Destination destination; - - private long start; - - private void init() throws Exception { - InitialContext ic = new InitialContext(); - System.out.println("ic = " + ic); - factory = (ConnectionFactory) ic.lookup(perfParams.getConnectionFactoryLookup()); - - destination = (Destination) ic.lookup(perfParams.getDestinationLookup()); - - connection = factory.createConnection(); - - session = connection.createSession(perfParams.isSessionTransacted(), perfParams.isDupsOK() ? Session.DUPS_OK_ACKNOWLEDGE : Session.AUTO_ACKNOWLEDGE); - - ic.close(); - } - - private void displayAverage(final long numberOfMessages, final long start, final long end) { - double duration = (1.0 * end - start) / 1000; // in seconds - double average = 1.0 * numberOfMessages / duration; - PerfBase.log.info(String.format("average: %.2f msg/s (%d messages in %2.2fs)", average, numberOfMessages, duration)); - } - - protected void runSender() { - try { - init(); - - if (perfParams.isDrainQueue()) { - drainQueue(); - } - - start = System.currentTimeMillis(); - PerfBase.log.info("warming up by sending " + perfParams.getNoOfWarmupMessages() + " messages"); - sendMessages(perfParams.getNoOfWarmupMessages(), perfParams.getBatchSize(), perfParams.isDurable(), perfParams.isSessionTransacted(), false, perfParams.getThrottleRate(), perfParams.getMessageSize()); - PerfBase.log.info("warmed up"); - start = System.currentTimeMillis(); - sendMessages(perfParams.getNoOfMessagesToSend(), perfParams.getBatchSize(), perfParams.isDurable(), perfParams.isSessionTransacted(), true, perfParams.getThrottleRate(), perfParams.getMessageSize()); - long end = System.currentTimeMillis(); - displayAverage(perfParams.getNoOfMessagesToSend(), start, end); - } - catch (Exception e) { - e.printStackTrace(); - } - finally { - if (session != null) { - try { - session.close(); - } - catch (Exception e) { - e.printStackTrace(); - } - } - if (connection != null) { - try { - connection.close(); - } - catch (JMSException e) { - e.printStackTrace(); - } - } - } - } - - protected void runListener() { - try { - init(); - - if (perfParams.isDrainQueue()) { - drainQueue(); - } - - MessageConsumer consumer = session.createConsumer(destination); - - connection.start(); - - PerfBase.log.info("READY!!!"); - - CountDownLatch countDownLatch = new CountDownLatch(1); - consumer.setMessageListener(new PerfListener(countDownLatch, perfParams)); - countDownLatch.await(); - long end = System.currentTimeMillis(); - // start was set on the first received message - displayAverage(perfParams.getNoOfMessagesToSend(), start, end); - } - catch (Exception e) { - e.printStackTrace(); - } - finally { - if (session != null) { - try { - session.close(); - } - catch (Exception e) { - e.printStackTrace(); - } - } - if (connection != null) { - try { - connection.close(); - } - catch (JMSException e) { - e.printStackTrace(); - } - } - } - } - - private void drainQueue() throws Exception { - PerfBase.log.info("Draining queue"); - - Session drainSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - - MessageConsumer consumer = drainSession.createConsumer(destination); - - connection.start(); - - Message message = null; - - int count = 0; - do { - message = consumer.receive(3000); - - if (message != null) { - message.acknowledge(); - - count++; - } - } while (message != null); - - drainSession.close(); - - PerfBase.log.info("Drained " + count + " messages"); - } - - private void sendMessages(final int numberOfMessages, - final int txBatchSize, - final boolean durable, - final boolean transacted, - final boolean display, - final int throttleRate, - final int messageSize) throws Exception { - MessageProducer producer = session.createProducer(destination); - - producer.setDeliveryMode(perfParams.isDurable() ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT); - - producer.setDisableMessageID(perfParams.isDisableMessageID()); - - producer.setDisableMessageTimestamp(perfParams.isDisableTimestamp()); - - BytesMessage message = session.createBytesMessage(); - - byte[] payload = PerfBase.randomByteArray(messageSize); - - message.writeBytes(payload); - - final int modulo = 2000; - - TokenBucketLimiter tbl = throttleRate != -1 ? new TokenBucketLimiterImpl(throttleRate, false) : null; - - boolean committed = false; - for (int i = 1; i <= numberOfMessages; i++) { - producer.send(message); - - if (transacted) { - if (i % txBatchSize == 0) { - session.commit(); - committed = true; - } - else { - committed = false; - } - } - - if (display && i % modulo == 0) { - double duration = (1.0 * System.currentTimeMillis() - start) / 1000; - PerfBase.log.info(String.format("sent %6d messages in %2.2fs", i, duration)); - } - - if (tbl != null) { - tbl.limit(); - } - } - if (transacted && !committed) { - session.commit(); - } - } - - private class PerfListener implements MessageListener { - - private final CountDownLatch countDownLatch; - - private final PerfParams perfParams; - - private boolean warmingUp = true; - - private boolean started = false; - - private final int modulo; - - private final AtomicLong count = new AtomicLong(0); - - public PerfListener(final CountDownLatch countDownLatch, final PerfParams perfParams) { - this.countDownLatch = countDownLatch; - this.perfParams = perfParams; - warmingUp = perfParams.getNoOfWarmupMessages() > 0; - modulo = 2000; - } - - public void onMessage(final Message message) { - try { - if (warmingUp) { - boolean committed = checkCommit(); - if (count.incrementAndGet() == perfParams.getNoOfWarmupMessages()) { - PerfBase.log.info("warmed up after receiving " + count.longValue() + " msgs"); - if (!committed) { - checkCommit(); - } - warmingUp = false; - } - return; - } - - if (!started) { - started = true; - // reset count to take stats - count.set(0); - start = System.currentTimeMillis(); - } - - long currentCount = count.incrementAndGet(); - boolean committed = checkCommit(); - if (currentCount == perfParams.getNoOfMessagesToSend()) { - if (!committed) { - checkCommit(); - } - countDownLatch.countDown(); - } - if (currentCount % modulo == 0) { - double duration = (1.0 * System.currentTimeMillis() - start) / 1000; - PerfBase.log.info(String.format("received %6d messages in %2.2fs", currentCount, duration)); - } - } - catch (Exception e) { - e.printStackTrace(); - } - } - - private boolean checkCommit() throws Exception { - if (perfParams.isSessionTransacted()) { - if (count.longValue() % perfParams.getBatchSize() == 0) { - session.commit(); - - return true; - } - } - return false; - } - } - -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/perf/src/main/java/org/apache/activemq/artemis/jms/example/PerfListener.java ---------------------------------------------------------------------- diff --git a/examples/jms/perf/src/main/java/org/apache/activemq/artemis/jms/example/PerfListener.java b/examples/jms/perf/src/main/java/org/apache/activemq/artemis/jms/example/PerfListener.java deleted file mode 100644 index 3f2c478..0000000 --- a/examples/jms/perf/src/main/java/org/apache/activemq/artemis/jms/example/PerfListener.java +++ /dev/null @@ -1,46 +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.logging.Logger; - -public class PerfListener extends PerfBase { - - private static final Logger log = Logger.getLogger(PerfListener.class.getName()); - - public static void main(final String[] args) { - try { - String fileName = PerfBase.getPerfFileName(args); - - PerfParams params = PerfBase.getParams(fileName); - - new PerfListener(params).run(); - } - catch (Exception e) { - e.printStackTrace(); - } - } - - private PerfListener(final PerfParams perfParams) { - super(perfParams); - } - - public void run() throws Exception { - runListener(); - } - -}
