http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6b17d966/examples/broker-features/standard/no-consumer-buffering/readme.html ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/no-consumer-buffering/readme.html b/examples/broker-features/standard/no-consumer-buffering/readme.html deleted file mode 100644 index 596562d..0000000 --- a/examples/broker-features/standard/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/6b17d966/examples/broker-features/standard/no-consumer-buffering/src/main/java/org/apache/activemq/artemis/jms/example/NoConsumerBufferingExample.java ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/no-consumer-buffering/src/main/java/org/apache/activemq/artemis/jms/example/NoConsumerBufferingExample.java b/examples/broker-features/standard/no-consumer-buffering/src/main/java/org/apache/activemq/artemis/jms/example/NoConsumerBufferingExample.java deleted file mode 100644 index 6f321b0..0000000 --- a/examples/broker-features/standard/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/6b17d966/examples/broker-features/standard/no-consumer-buffering/src/main/resources/jndi.properties ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/no-consumer-buffering/src/main/resources/jndi.properties b/examples/broker-features/standard/no-consumer-buffering/src/main/resources/jndi.properties deleted file mode 100644 index d9b77a6..0000000 --- a/examples/broker-features/standard/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/6b17d966/examples/broker-features/standard/paging/pom.xml ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/paging/pom.xml b/examples/broker-features/standard/paging/pom.xml deleted file mode 100644 index d78efc9..0000000 --- a/examples/broker-features/standard/paging/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.broker</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> - - <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.broker</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/6b17d966/examples/broker-features/standard/paging/readme.html ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/paging/readme.html b/examples/broker-features/standard/paging/readme.html deleted file mode 100644 index 7c74320..0000000 --- a/examples/broker-features/standard/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/6b17d966/examples/broker-features/standard/paging/src/main/java/org/apache/activemq/artemis/jms/example/PagingExample.java ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/paging/src/main/java/org/apache/activemq/artemis/jms/example/PagingExample.java b/examples/broker-features/standard/paging/src/main/java/org/apache/activemq/artemis/jms/example/PagingExample.java deleted file mode 100644 index 19d8a17..0000000 --- a/examples/broker-features/standard/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/6b17d966/examples/broker-features/standard/paging/src/main/resources/activemq/server0/artemis-roles.properties ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/paging/src/main/resources/activemq/server0/artemis-roles.properties b/examples/broker-features/standard/paging/src/main/resources/activemq/server0/artemis-roles.properties deleted file mode 100644 index 4e2d44c..0000000 --- a/examples/broker-features/standard/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/6b17d966/examples/broker-features/standard/paging/src/main/resources/activemq/server0/artemis-users.properties ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/paging/src/main/resources/activemq/server0/artemis-users.properties b/examples/broker-features/standard/paging/src/main/resources/activemq/server0/artemis-users.properties deleted file mode 100644 index 4e2d44c..0000000 --- a/examples/broker-features/standard/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/6b17d966/examples/broker-features/standard/paging/src/main/resources/activemq/server0/broker.xml ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/paging/src/main/resources/activemq/server0/broker.xml b/examples/broker-features/standard/paging/src/main/resources/activemq/server0/broker.xml deleted file mode 100644 index a7a1969..0000000 --- a/examples/broker-features/standard/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/6b17d966/examples/broker-features/standard/paging/src/main/resources/jndi.properties ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/paging/src/main/resources/jndi.properties b/examples/broker-features/standard/paging/src/main/resources/jndi.properties deleted file mode 100644 index 6f70010..0000000 --- a/examples/broker-features/standard/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/6b17d966/examples/broker-features/standard/pom.xml ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/pom.xml b/examples/broker-features/standard/pom.xml deleted file mode 100644 index 106462b..0000000 --- a/examples/broker-features/standard/pom.xml +++ /dev/null @@ -1,171 +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.clustered</groupId> - <artifactId>broker-features</artifactId> - <version>1.0.1-SNAPSHOT</version> - </parent> - - <groupId>org.apache.activemq.examples.broker</groupId> - <artifactId>jms-examples</artifactId> - <packaging>pom</packaging> - <name>ActiveMQ Artemis Standard Examples</name> - - <properties> - <udp-address>231.7.7.7</udp-address> - <activemq.basedir>${project.basedir}/../../..</activemq.basedir> - </properties> - - <profiles> - <profile> - <id>release</id> - <modules> - <module>bridge</module> - <module>browser</module> - <module>client-kickoff</module> - <module>consumer-rate-limit</module> - <module>dead-letter</module> - <module>delayed-redelivery</module> - <module>divert</module> - <module>durable-subscription</module> - <module>embedded</module> - <module>embedded-simple</module> - <module>expiry</module> - <module>http-transport</module> - <module>interceptor</module> - <module>instantiate-connection-factory</module> - <module>jms-auto-closeable</module> - <module>jms-bridge</module> - <module>jms-completion-listener</module> - <module>jms-context</module> - <module>jms-shared-consumer</module> - <module>jmx</module> - <module>large-message</module> - <module>last-value-queue</module> - <module>management</module> - <module>management-notifications</module> - <module>message-counters</module> - <module>message-group</module> - <module>message-group2</module> - <module>message-priority</module> - <module>no-consumer-buffering</module> - <module>paging</module> - <module>pre-acknowledge</module> - <module>producer-rate-limit</module> - <module>queue</module> - <module>queue-requestor</module> - <module>queue-selector</module> - <module>reattach-node</module> - <module>rest</module> - <module>request-reply</module> - <module>scheduled-message</module> - <module>security</module> - <module>send-acknowledgements</module> - <module>spring-integration</module> - <module>ssl-enabled</module> - <module>static-selector</module> - <module>temp-queue</module> - <module>topic</module> - <module>topic-hierarchies</module> - <module>topic-selector-example1</module> - <module>topic-selector-example2</module> - <module>transactional</module> - <module>xa-heuristic</module> - <module>xa-receive</module> - <module>xa-send</module> - </modules> - </profile> - <profile> - <id>examples</id> - <modules> - <module>bridge</module> - <module>browser</module> - <module>client-kickoff</module> - <module>consumer-rate-limit</module> - <module>dead-letter</module> - <module>delayed-redelivery</module> - <module>divert</module> - <module>durable-subscription</module> - <module>embedded</module> - <module>embedded-simple</module> - <module>expiry</module> - <module>http-transport</module> - <module>interceptor</module> - <module>jms-auto-closeable</module> - <module>instantiate-connection-factory</module> - <module>jms-bridge</module> - <module>jms-completion-listener</module> - <module>jms-context</module> - <module>jms-shared-consumer</module> - <module>jmx</module> - <module>large-message</module> - <module>last-value-queue</module> - <module>management</module> - <module>management-notifications</module> - <module>message-counters</module> - <module>message-group</module> - <module>message-group2</module> - <module>message-priority</module> - <module>no-consumer-buffering</module> - <module>paging</module> - <module>pre-acknowledge</module> - <module>producer-rate-limit</module> - <module>queue</module> - <module>queue-requestor</module> - <module>queue-selector</module> - <module>reattach-node</module> - - <module>request-reply</module> - <module>rest</module> - <module>scheduled-message</module> - <module>security</module> - <module>send-acknowledgements</module> - <module>spring-integration</module> - - <!-- ARTEMIS-197 FIX ME - this one could be the case of leaving it out for good - as it may require to be run manually - <module>ssl-enabled</module> --> - - <module>static-selector</module> - - <!--this needs to be run standalone as it needs manual intervention--> - <!--<module>stop-server-failover</module>--> - - <module>temp-queue</module> - <module>topic</module> - <module>topic-hierarchies</module> - <module>topic-selector-example1</module> - <module>topic-selector-example2</module> - <module>transactional</module> - <module>xa-heuristic</module> - <module>xa-receive</module> - <module>xa-send</module> - </modules> - </profile> - - </profiles> - - -</project> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6b17d966/examples/broker-features/standard/pre-acknowledge/pom.xml ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/pre-acknowledge/pom.xml b/examples/broker-features/standard/pre-acknowledge/pom.xml deleted file mode 100644 index c5da1a5..0000000 --- a/examples/broker-features/standard/pre-acknowledge/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.broker</groupId> - <artifactId>jms-examples</artifactId> - <version>1.0.1-SNAPSHOT</version> - </parent> - - <artifactId>pre-acknowledge</artifactId> - <packaging>jar</packaging> - <name>ActiveMQ Artemis JMS Pre Acknowledge 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> - - <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.PreacknowledgeExample</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.broker</groupId> - <artifactId>pre-acknowledge</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - </plugin> - </plugins> - </build> - -</project> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6b17d966/examples/broker-features/standard/pre-acknowledge/readme.html ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/pre-acknowledge/readme.html b/examples/broker-features/standard/pre-acknowledge/readme.html deleted file mode 100644 index 235c278..0000000 --- a/examples/broker-features/standard/pre-acknowledge/readme.html +++ /dev/null @@ -1,154 +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 Pre-Acknowledge 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 Pre-Acknowledge 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>Standard JMS supports three acknowledgement modes: AUTO_ACKNOWLEDGE, CLIENT_ACKNOWLEDGE, and - DUPS_OK_ACKNOWLEDGE. For a full description on these modes please consult the JMS specification, or any - JMS tutorial.</p> - <p>All of these standard modes involve sending acknowledgements from the client to the server. However - in some cases, you really don't mind losing messages in event of failure, so it would make sense - to acknowledge the message on the server <b>before</b> delivering it to the client.</p> - <p>By acknowledging the message before sending to the client, you can avoid extra network traffic and CPU - work done in sending acknowledgements from client to server.</p> - <p>The down-side of acknowledging on the server before delivery, is that if the system crashes after acknowledging - the message, but before the message has been received by the client, then, on recovery, that message - will be lost. This makes pre-acknowledgement not appropriate for all use cases, but it is very useful for some - use-cases when you can cope with such loss of messages<p> - <p>An example of a use-case where it might be a good idea to use pre-acknowledge, is for stock price update - messages. With these messages it might be ok to lose a message in event of crash, since the next price - update message will arrive soon, overriding the previous price.</p> - <p>In order to use pre-acknowledge functionality with ActiveMQ Artemis the session has to be created with - a special, ActiveMQ Artemis specific acknowledgement mode, given by the value of - <code>ActiveMQJMSConstants.PRE_ACKNOWLEDGE</code>. - <h2>Example step-by-step</h2> - - <ol> - <li>Create an initial context to perform the JNDI lookup.</li> - <pre class="prettyprint"> - <code> - initialContext = getContext(0); - </code> - </pre> - - <li>Perform the look-ups</li> - <pre class="prettyprint"> - <code> - Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue"); - - ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory"); - </code> - </pre> - - <li>Create a the JMS objects.</li> - <pre class="prettyprint"> - <code> - connection = cf.createConnection(); - - Session session = connection.createSession(false, ActiveMQSession.PRE_ACKNOWLEDGE); - - MessageProducer producer = session.createProducer(queue); - - MessageConsumer messageConsumer = session.createConsumer(queue); - </code> - </pre> - - <li>Create and send a message.</li> - <pre class="prettyprint"> - <code> - TextMessage message1 = session.createTextMessage("This is a text message 1"); - - producer.send(message1); - - System.out.println("Sent message: " + message1.getText()); - </code> - </pre> - - <li>Print out the message count of the queue. The queue contains one message as expected - delivery has not yet started on the queue.</li> - <pre class="prettyprint"> - <code> - int count = getMessageCount(connection); - - System.out.println("Queue message count is " + count); - </code> - </pre> - - <li>Start the Connection, delivery will now start. Give a little time for delivery to occur.</li> - <pre class="prettyprint"> - <code> - connection.start(); - - Thread.sleep(1000); - </code> - </pre> - - <li>Print out the message count of the queue. It should now be zero, since the message has - already been acknowledged even before the consumer has received it.</li> - <pre class="prettyprint"> - <code> - count = getMessageCount(connection); - - System.out.println("Queue message count is now " + count); - </code> - </pre> - - <li>Finally, receive the message.</li> - <pre class="prettyprint"> - <code> - TextMessage messageReceived = (TextMessage)messageConsumer.receive(5000); - - System.out.println("Received message: " + messageReceived.getText()); - </code> - </pre> - - <li>Be sure to close our resources!</li> - <pre class="prettyprint"> - <code> - 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#pre-acknowledge">Pre-acknowledgement Mode chapter</a></li> - </ul> - - </body> -</html> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6b17d966/examples/broker-features/standard/pre-acknowledge/src/main/java/org/apache/activemq/artemis/jms/example/PreacknowledgeExample.java ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/pre-acknowledge/src/main/java/org/apache/activemq/artemis/jms/example/PreacknowledgeExample.java b/examples/broker-features/standard/pre-acknowledge/src/main/java/org/apache/activemq/artemis/jms/example/PreacknowledgeExample.java deleted file mode 100644 index 834b54a..0000000 --- a/examples/broker-features/standard/pre-acknowledge/src/main/java/org/apache/activemq/artemis/jms/example/PreacknowledgeExample.java +++ /dev/null @@ -1,126 +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.Message; -import javax.jms.MessageConsumer; -import javax.jms.MessageProducer; -import javax.jms.Queue; -import javax.jms.QueueConnection; -import javax.jms.QueueRequestor; -import javax.jms.QueueSession; -import javax.jms.Session; -import javax.jms.TextMessage; - -import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; -import org.apache.activemq.artemis.api.jms.ActiveMQJMSConstants; -import org.apache.activemq.artemis.api.jms.management.JMSManagementHelper; -import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; - -/** - * This example demonstrates the use of ActiveMQ Artemis "pre-acknowledge" functionality where - * messages are acknowledged before they are delivered to the consumer. - * - * Please see the readme.html for more details. - */ -public class PreacknowledgeExample { - - public static void main(final String[] args) throws Exception { - Connection connection = null; - try { - - // Step 2. instantiate the queue object - Queue queue = ActiveMQJMSClient.createQueue("exampleQueue"); - - // new connection factory - ConnectionFactory cf = new ActiveMQConnectionFactory(); - - // Step 3. Create a the JMS objects - connection = cf.createConnection(); - - Session session = connection.createSession(false, ActiveMQJMSConstants.PRE_ACKNOWLEDGE); - - MessageProducer producer = session.createProducer(queue); - - MessageConsumer messageConsumer = session.createConsumer(queue); - - // Step 4. Create and send a message - TextMessage message1 = session.createTextMessage("This is a text message 1"); - - producer.send(message1); - - System.out.println("Sent message: " + message1.getText()); - - // Step 5. Print out the message count of the queue. The queue contains one message as expected - // delivery has not yet started on the queue - int count = getMessageCount(connection); - - System.out.println("Queue message count is " + count); - - // Step 6. Start the Connection, delivery will now start. Give a little time for delivery to occur. - connection.start(); - - Thread.sleep(1000); - - // Step 7. Print out the message countof the queue. It should now be zero, since the message has - // already been acknowledged even before the consumer has received it. - count = getMessageCount(connection); - - System.out.println("Queue message count is now " + count); - - if (count != 0) { - throw new IllegalStateException("Queue message count is not 0."); - } - - // Step 8. Finally, receive the message - TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000); - - System.out.println("Received message: " + messageReceived.getText()); - } - finally { - // Step 9. Be sure to close our resources! - if (connection != null) { - connection.close(); - } - } - } - - // To do this we send a management message to get the message count. - // In real life you wouldn't create a new session every time you send a management message - private static int getMessageCount(final Connection connection) throws Exception { - QueueSession session = ((QueueConnection) connection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE); - - Queue managementQueue = ActiveMQJMSClient.createQueue("activemq.management"); - - QueueRequestor requestor = new QueueRequestor(session, managementQueue); - - connection.start(); - - Message m = session.createMessage(); - - JMSManagementHelper.putAttribute(m, "jms.queue.exampleQueue", "messageCount"); - - Message response = requestor.request(m); - - int messageCount = (Integer) JMSManagementHelper.getResult(response); - - return messageCount; - } - -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6b17d966/examples/broker-features/standard/pre-acknowledge/src/main/resources/activemq/server0/artemis-roles.properties ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/pre-acknowledge/src/main/resources/activemq/server0/artemis-roles.properties b/examples/broker-features/standard/pre-acknowledge/src/main/resources/activemq/server0/artemis-roles.properties deleted file mode 100644 index 4e2d44c..0000000 --- a/examples/broker-features/standard/pre-acknowledge/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/6b17d966/examples/broker-features/standard/pre-acknowledge/src/main/resources/activemq/server0/artemis-users.properties ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/pre-acknowledge/src/main/resources/activemq/server0/artemis-users.properties b/examples/broker-features/standard/pre-acknowledge/src/main/resources/activemq/server0/artemis-users.properties deleted file mode 100644 index 4e2d44c..0000000 --- a/examples/broker-features/standard/pre-acknowledge/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/6b17d966/examples/broker-features/standard/pre-acknowledge/src/main/resources/activemq/server0/broker.xml ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/pre-acknowledge/src/main/resources/activemq/server0/broker.xml b/examples/broker-features/standard/pre-acknowledge/src/main/resources/activemq/server0/broker.xml deleted file mode 100644 index f29acbc..0000000 --- a/examples/broker-features/standard/pre-acknowledge/src/main/resources/activemq/server0/broker.xml +++ /dev/null @@ -1,63 +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 queue used by the example--> - <queue name="exampleQueue"/> - </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> - - <!-- Acceptors --> - <acceptors> - <acceptor name="netty-acceptor">tcp://localhost:61616</acceptor> - </acceptors> - - <!-- Other config --> - - <security-settings> - <security-setting match="jms.#"> - <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.activemq.management"> - <permission type="manage" roles="guest"/> - </security-setting> - </security-settings> - - </core> -</configuration> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6b17d966/examples/broker-features/standard/pre-acknowledge/src/main/resources/jndi.properties ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/pre-acknowledge/src/main/resources/jndi.properties b/examples/broker-features/standard/pre-acknowledge/src/main/resources/jndi.properties deleted file mode 100644 index 93537c4..0000000 --- a/examples/broker-features/standard/pre-acknowledge/src/main/resources/jndi.properties +++ /dev/null @@ -1,20 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -java.naming.factory.initial=org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory -connectionFactory.ConnectionFactory=tcp://localhost:61616 -queue.queue/exampleQueue=exampleQueue http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6b17d966/examples/broker-features/standard/producer-rate-limit/pom.xml ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/producer-rate-limit/pom.xml b/examples/broker-features/standard/producer-rate-limit/pom.xml deleted file mode 100644 index 91b7603..0000000 --- a/examples/broker-features/standard/producer-rate-limit/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.broker</groupId> - <artifactId>jms-examples</artifactId> - <version>1.0.1-SNAPSHOT</version> - </parent> - - <artifactId>producer-rate-limit</artifactId> - <packaging>jar</packaging> - <name>ActiveMQ Artemis JMS Producer Rate Limit 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> - - <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.ProducerRateLimitExample</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.broker</groupId> - <artifactId>producer-rate-limit</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - </plugin> - </plugins> - </build> - -</project> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6b17d966/examples/broker-features/standard/producer-rate-limit/readme.html ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/producer-rate-limit/readme.html b/examples/broker-features/standard/producer-rate-limit/readme.html deleted file mode 100644 index 7e10ca3..0000000 --- a/examples/broker-features/standard/producer-rate-limit/readme.html +++ /dev/null @@ -1,176 +0,0 @@ -<!-- -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. ---> - -<html> - <head> - <title>ActiveMQ Artemis JMS Message Producer Rate Limiting</title> - <link rel="stylesheet" type="text/css" href="../../../common/common.css" /> - <link rel="stylesheet" type="text/css" href="../../../common/prettify.css" /> - <script type="text/javascript" src="../../../common/prettify.js"></script> - </head> - <body onload="prettyPrint()"> - <h1>JMS Message Producer 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 send rate at which a JMS MessageProducer will send messages. - This can be specified when creating or deploying the connection factory. See <code>activemq-jms.xml</code></p> - <p>If this value is specified then ActiveMQ Artemis will ensure that messages are never produced at a rate higher than - specified. This is a form of producer <i>throttling</i>.</p> - <h2>Example step-by-step</h2> - <p>In this example we specify a <code>producer-max-rate</code> of <code>50</code> messages per second 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 limit producers created on this connection factory to produce messages at a maximum rate - of 50 messages per sec --> - <producer-max-rate>50</producer-max-rate> - - </connection-factory> - </code> - </pre> - <p>We then simply send as many messages as we can in 10 seconds and note how many messages are actually sent.</p> - <p>We note that the number of messages sent per second never exceeds the specified value of <code>50</code> messages per second.</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 Message Producer</li> - <pre class="prettyprint"> - <code>MessageProducer producer = session.createProducer(queue);</code> - </pre> - - <li>Send 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 = session.createTextMessage("This is text message: " + i++); - - producer.send(message); - } - - long end = System.currentTimeMillis(); - - double rate = 1000 * (double)i / (end - start); - - System.out.println("We sent " + i + " messages in " + (end - start) + " milliseconds"); - - System.out.println("Actual send rate was " + rate + " messages per second"); - </code> - </pre> - - <li>We note that the sending rate doesn't exceed 50 messages per second. Here's some example output from a real - run</li> - - <pre class="prettyprint"> - <code> - [java] Will now send as many messages as we can in 10 seconds... - [java] We sent 500 messages in 10072 milliseconds - [java] Actual send rate was 49.64257347100874 messages per second - </code> - </pre> - - - <li>For good measure we consumer the messages we produced.</li> - <pre class="prettyprint"> - <code> - MessageConsumer messageConsumer = session.createConsumer(queue); - - connection.start(); - - System.out.println("Now consuming the messages..."); - - i = 0; - while (true) - { - TextMessage messageReceived = (TextMessage)messageConsumer.receive(5000); - - if (messageReceived == null) - { - break; - } - - i++; - } - - System.out.println("Received " + i + " messages"); - - </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>