http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/dead-letter/readme.html ---------------------------------------------------------------------- diff --git a/examples/jms/dead-letter/readme.html b/examples/jms/dead-letter/readme.html index 36985e2..deb836d 100644 --- a/examples/jms/dead-letter/readme.html +++ b/examples/jms/dead-letter/readme.html @@ -26,9 +26,10 @@ under the License. </head> <body onload="prettyPrint()"> <h1>Dead Letter Example</h1> + <pre>To run the example, simply type <b>mvn verify</b> from this directory, <br>or <b>mvn -PnoServer verify</b> if you want to start and create the server manually.</pre> <p>This example shows you how to define and deal with dead letter messages.</p> - <p>Messages can be delivered unsuccessfully (e.g. if the transacted session used to consume them is rolled back). + <p>Messages can be delivered unsuccessfully (e.g. if the transacted session used to consume them is rolled back). Such a message goes back to the JMS destination ready to be redelivered. However, this means it is possible for a message to be delivered again and again without any success and remain in the destination, clogging the system.</p> <p>To prevent this, messaging systems define dead letter messages: after a specified unsuccessful delivery attempts, the message is removed from the destination @@ -47,12 +48,12 @@ under the License. <max-delivery-attempts>3</max-delivery-attempts> </address-setting> </code> - </pre> + </pre> <p>This configuration will moved dead letter messages from <code>exampleQueue</code> to the <code>deadLetterQueue</code>.</p> <p>ActiveMQ Artemis allows to specify either a <code>Queue</code> by prefixing the <code>dead-letter-address</code> with <code>jms.queue.</code> or a <code>Topic</code> by prefixing with <code>jms.topic.</code>.<br /> In this example, we will use a <code>Queue</code> to hold the dead letter messages.</p> - <p>The maximum attempts of delivery is <code>3</code>. Once this figure is reached, a message is considered a dead letter message and is moved to + <p>The maximum attempts of delivery is <code>3</code>. Once this figure is reached, a message is considered a dead letter message and is moved to the <code>deadLetterQueue</code>. <p>Since we want to consume messages from this deadLetterQueue, we also need to add a JNDI binding to perform a lookup. This is configured in <a href="src/main/resources/activemq/server0/activemq-jms.xml">activemq-jms.xml</a></p> @@ -61,166 +62,5 @@ under the License. <entry name="/queue/deadLetterQueue"/> </queue></code> </pre> - </p> - <h2>Example step-by-step</h2> - <p><i>To run the example, simply type <code>mvn verify -Pexample</code> from this directory</i></p> - <ol> - <li>First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the <code>client-jndi.properties</code> file in the directory <code>../common/config</code></li> - <pre class="prettyprint"> - <code>InitialContext initialContext = getContext();</code> - </pre> - - <li>We look up the JMS queue object from JNDI</li> - <pre class="prettyprint"> - <code>Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");</code> - </pre> - - <li>We look up the JMS connection factory object from JNDI</li> - <pre class="prettyprint"> - <code>ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");</code> - </pre> - - <li>We create a JMS connection</li> - <pre class="prettyprint"> - <code>connection = cf.createConnection();</code> - </pre> - - <li>We create a JMS <em>transacted</em> session - <pre class="prettyprint"> - <code>Session session = connection.createSession(true, 0);</code> - </pre> - - <li>We create a JMS message producer on the session. This will be used to send the messages</li> - <pre class="prettyprint"> - <code>MessageProducer messageProducer = session.createProducer(topic);</code> - </pre> - - <li>We create a text messages</li> - <pre class="prettyprint"> - <code>TextMessage message = session.createTextMessage("this is a text message");</code> - </pre> - - <li>We send the message to the queue</li> - <pre class="prettyprint"> - <code>producer.send(message);</code> - </pre> - - <li>We commit the session to effectively send the message to the queue</li> - <pre class="prettyprint"> - <code>session.commit();</code> - </pre> - - <p>We will now consume the message from the queue 3 times and roll back the session every time</p> - - <li>We create a JMS message consumer on the queue</li> - <pre class="prettyprint"> - <code>MessageConsumer messageConsumer = session.createConsumer(queue);</code> - </pre> - - <li>We start the connection. In order for delivery to occur on any consumers or subscribers on a connection, the connection must be started</li> - <pre class="prettyprint"> - <code>connection.start();</code> - </pre> - - <li>We receive the message a 1<sup>st</sup> time</li> - <pre class="prettyprint"> - <code>TextMessage messageReceived = (TextMessage)messageConsumer.receive(5000); - System.out.println("1st delivery from " + queue.getQueueName() + ": " + messageReceived.getText());</code> - </pre> - - <li>We roll back the session. The message we received is undelivered and goes back to the queue</li> - <pre class="prettyprint"> - <code>session.rollback();</code> - </pre> - - <li>We receive a message and roll back the session a 2<sup>nd</sup> time - <pre class="prettyprint"> - <code>messageReceived = (TextMessage)messageConsumer.receive(5000); - System.out.println("2nd delivery from " + queue.getQueueName() + ": " + messageReceived.getText()); - session.rollback();</code> - </pre> - - <li>We do it againt a 3<sup>rd</sup> time - <pre class="prettyprint"> - <code>messageReceived = (TextMessage)messageConsumer.receive(5000); - System.out.println("3rd delivery from " + queue.getQueueName() + ": " + messageReceived.getText()); - session.rollback();</code> - </pre> - - <p>Since the queue was configured to move messages to the <code>deadLetterQueue</code> after <code>3</code> unsuccessful delivery attempts, - the message won't be in the <code>queue</code> anymore</p> - - <li>We try to receive a message from the queue for a 4<sup>th</sup>. Since there is none, the call will timeout after 5000ms and <code>messageReceived</code> will be <code>null</code> - <pre class="prettyprint"> - <code>messageReceived = (TextMessage)messageConsumer.receive(5000); - System.out.println("4th delivery from " + queue.getQueueName() + ": " + messageReceived);</code> - </pre> - - <p>We have configured ActiveMQ Artemis to send any dead letter messages to the <code>deadLetterQueue</code>. - We will now consume messages from this queue and receives the <em>dead letter messages</em>.</p> - - <li>We look up the JMS <em>dead letter queue</em> object from JNDI</li> - <pre class="prettyprint"> - <code>Queue deadLetterQueue = (Queue)initialContext.lookup("/queue/deadLetterQueue");</code> - </pre> - - <li>We create a JMS message consumer on the dead letter queue</li> - <pre class="prettyprint"> - <code>MessageConsumer deadLetterConsumer = session.createConsumer(expiryQueue);</code> - </pre> - - <li>We consume a message from the dead letter queue:</li> - <pre class="prettyprint"> - <code>messageReceived = (TextMessage)deadLetterConsumer.receive(5000);</code> - </pre> - - <li>The message consumed from the <em>dead letter queue</em> has the <em>same content</em> than the message which was sent to the <em>queue</em> - <pre class="prettyprint"> - <code>System.out.println("Received message from " + deadLetterQueue.getQueueName() + ": " + messageReceived.getText());</code> - </pre> - - <p>JMS does not specify the notion of dead letter destinations and messages. From JMS point of view, the message received from the dead letter queue - is a <strong>different</strong> message than the message removed from the queue after the unsuccessful delivery attempts: - the messages have the same content (properties and body) but their JMS headers differ.<br /> - ActiveMQ Artemis defines additional properties for messages received from a dead letter destination</p> - - <li>The message's destination is the dead letter queue</li> - <pre class="prettyprint"> - <code>System.out.println("Destination of the message: " + ((Queue)messageReceived.getJMSDestination()).getQueueName());</code> - </pre> - - <li>The <strong>origin destination</strong> is stored in the <code>_AMQ_ORIG_ADDRESS</code> property - <pre class="prettyprint"> - <code>System.out.println("*Origin destination* of the message: " + messageReceived.getStringProperty("_AMQ_ORIG_ADDRESS"));</code> - </pre> - - <li>We do not forget to commit the session to acknowledge that we have received the message from the dead letter queue</li> - <pre class="prettyprint"> - <code>session.commit();</code> - </pre> - - </p> - <li>And finally, <b>always</b> remember to close your JMS connections and resources after use, in a <code>finally</code> block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects</li> - - <pre class="prettyprint"> - <code>finally - { - if (initialContext != null) - { - initialContext.close(); - } - if (connection != null) - { - connection.close(); - } - }</code> - </pre> - </ol> - - <h2>More information</h2> - - <ul> - <li>User Manual's <a href="../../../docs/user-manual/en/html_single/index.html#undelivered-messages">Undelivered Messages chapter</a></li> - </ul> </body> </html>
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/delayed-redelivery/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/delayed-redelivery/pom.xml b/examples/jms/delayed-redelivery/pom.xml index 764efda..2fd5090 100644 --- a/examples/jms/delayed-redelivery/pom.xml +++ b/examples/jms/delayed-redelivery/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> @@ -27,7 +28,7 @@ under the License. <version>1.0.1-SNAPSHOT</version> </parent> - <artifactId>artemis-jms-delayed-redelivery-example</artifactId> + <artifactId>delayed-redelivery</artifactId> <packaging>jar</packaging> <name>ActiveMQ Artemis JMS Delayed Redelivery Example</name> @@ -37,71 +38,82 @@ under the License. <dependencies> <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-jms_2.0_spec</artifactId> + <groupId>org.apache.activemq</groupId> + <artifactId>artemis-jms-client</artifactId> + <version>${project.version}</version> </dependency> </dependencies> <profiles> <profile> - <id>example</id> - <build> - <plugins> - <plugin> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-maven-plugin</artifactId> - <executions> - <execution> - <id>create</id> - <goals> - <goal>create</goal> - </goals> - </execution> - <execution> - <id>start</id> - <goals> - <goal>cli</goal> - </goals> - <configuration> - <spawn>true</spawn> - <testURI>tcp://localhost:61616</testURI> - <args> - <param>run</param> - </args> - </configuration> - </execution> - <execution> - <id>runClient</id> - <goals> - <goal>runClient</goal> - </goals> - <configuration> - <clientClass>org.apache.activemq.artemis.jms.example.DelayedRedeliveryExample</clientClass> - </configuration> - </execution> - <execution> - <id>stop</id> - <goals> - <goal>cli</goal> - </goals> - <configuration> - <args> - <param>stop</param> - </args> - </configuration> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>org.apache.activemq.examples.jms</groupId> - <artifactId>artemis-jms-delayed-redelivery-example</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - </plugin> - </plugins> - </build> + <!-- specify -PnoServer if you don't want to start the server --> + <id>noServer</id> + <properties> + <noServer>true</noServer> + </properties> </profile> </profiles> + <build> + <plugins> + <plugin> + <groupId>org.apache.activemq</groupId> + <artifactId>artemis-maven-plugin</artifactId> + <executions> + <execution> + <id>create</id> + <goals> + <goal>create</goal> + </goals> + <configuration> + <configuration>${basedir}/target/classes/activemq/server0</configuration> + <ignore>${noServer}</ignore> + </configuration> + </execution> + <execution> + <id>start</id> + <goals> + <goal>cli</goal> + </goals> + <configuration> + <ignore>${noServer}</ignore> + <spawn>true</spawn> + <testURI>tcp://localhost:61616</testURI> + <args> + <param>run</param> + </args> + </configuration> + </execution> + <execution> + <id>runClient</id> + <goals> + <goal>runClient</goal> + </goals> + <configuration> + <clientClass>org.apache.activemq.artemis.jms.example.DelayedRedeliveryExample</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>delayed-redelivery</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> </project> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/delayed-redelivery/readme.html ---------------------------------------------------------------------- diff --git a/examples/jms/delayed-redelivery/readme.html b/examples/jms/delayed-redelivery/readme.html index 8613c02..09ecb38 100644 --- a/examples/jms/delayed-redelivery/readme.html +++ b/examples/jms/delayed-redelivery/readme.html @@ -26,7 +26,8 @@ under the License. </head> <body onload="prettyPrint()"> <h1>Delayed Redelivery Example</h1> - + <pre>To run the example, simply type <b>mvn verify</b> from this directory, <br>or <b>mvn -PnoServer verify</b> if you want to start and create the server manually.</pre> + <p>This example demonstrates how ActiveMQ Artemis can be configured to provide a delayed redelivery in the case where a message needs to be redelivered.</p> <p>Delaying redelivery can often be useful in the case that clients regularly fail or roll-back. Without a delayed @@ -46,142 +47,10 @@ under the License. <p>We then consume a message in a transacted session, and rollback, and note that the message is not redelivered until after 5 seconds.</p> <pre class="prettyprint"> - <code><address-setting match="jms.queue.exampleQueue"> + <code><address-setting match="jms.queue.exampleQueue"> <redelivery-delay>5000</redelivery-delay> </address-setting> </code> - </pre> - <p><i>To run the example, simply type <code>mvn verify -Pexample</code> from this directory</i></p> - <ol> - <li>Create an initial context to perform the JNDI lookup.</li> - <pre class="prettyprint"> - <code>initialContext = getContext(0);</code> - </pre> - - <li>Perform 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 transacted JMS Session - <pre class="prettyprint"> - <code>Session session = connection.createSession(true, 0);</code> - </pre> - - <li>Create a JMS Message Producer</li> - <pre class="prettyprint"> - <code>MessageProducer producer = session.createProducer(queue);</code> - </pre> - - <li>Create a Text Message</li> - <pre class="prettyprint"> - <code>TextMessage message = session.createTextMessage("this is a text message");</code> - </pre> - - <li>Send the Message</li> - <pre class="prettyprint"> - <code>producer.send(message);</code> - </pre> - - <li>We commit the session to effectively send the message to the queue</li> - <pre class="prettyprint"> - <code>session.commit();</code> - </pre> - - <li>We create a JMS message consumer on the queue</li> - <pre class="prettyprint"> - <code>MessageConsumer messageConsumer = session.createConsumer(queue);</code> - </pre> - - <li>We start the connection. In order for delivery to occur on any consumers or subscribers on a connection, the connection must be started</li> - <pre class="prettyprint"> - <code>connection.start();</code> - </pre> - - <li>We receive the message...</li> - <pre class="prettyprint"> - <code>TextMessage messageReceived = (TextMessage)messageConsumer.receive(5000); - System.out.println("1st delivery from " + queue.getQueueName() + ": " + messageReceived.getText());</code> - </pre> - - <li>...but we roll back the session. the message returns to the queue, but only after a - 5 second delay</li> - <pre class="prettyprint"> - <code>session.rollback();</code> - </pre> - - <li>We try to receive the message but it's being delayed</li> - <pre class="prettyprint"> - <code> - messageReceived = (TextMessage)messageConsumer.receive(3000); - - if (messageReceived != null) - { - return false; - } - - System.out.println("Redelivery has been delayed so received message is " + messageReceived); - - </code> - </pre> - - <li>We try and receive the message again, this time we should get it</li> - <pre class="prettyprint"> - <code> - messageReceived = (TextMessage)messageConsumer.receive(3000); - - System.out.println("2nd delivery from " + queue.getQueueName() + ": " + messageReceived.getText()); - </code> - </pre> - - <li>We rollback the session again to cause another redelivery, and we time how long this one takes</code> - <pre class="prettyprint"> - <code> - long start = System.currentTimeMillis(); - - session.rollback(); - - messageReceived = (TextMessage)messageConsumer.receive(8000); - - long end = System.currentTimeMillis(); - - System.out.println("3nd delivery from " + queue.getQueueName() + ": " + messageReceived.getText() + - " after " + (end - start) + " milliseconds."); - </code> - </pre> - - <li>And finally, <b>always</b> remember to close your JMS connections and resources after use, in a <code>finally</code> block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects</li> - - <pre class="prettyprint"> - <code>finally - { - if (initialContext != null) - { - initialContext.close(); - } - if (connection != null) - { - connection.close(); - } - }</code> - </pre> - </ol> - - <h2>More information</h2> - - <ul> - <li>User Manual's <a href="../../../docs/user-manual/en/html_single/index.html#undelivered-messages">Undelivered Messages chapter</a></li> - </ul> - + </pre> </body> </html> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/divert/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/divert/pom.xml b/examples/jms/divert/pom.xml index 46dfbc6..4c912b2 100644 --- a/examples/jms/divert/pom.xml +++ b/examples/jms/divert/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> @@ -26,8 +27,7 @@ under the License. <artifactId>jms-examples</artifactId> <version>1.0.1-SNAPSHOT</version> </parent> - - <artifactId>artemis-jms-divert-example</artifactId> + <artifactId>divert</artifactId> <packaging>jar</packaging> <name>ActiveMQ Artemis JMS Divert Example</name> @@ -42,114 +42,127 @@ under the License. <version>${project.version}</version> </dependency> <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-jms_2.0_spec</artifactId> + <groupId>org.apache.activemq</groupId> + <artifactId>artemis-jms-client</artifactId> + <version>${project.version}</version> </dependency> </dependencies> <profiles> <profile> - <id>example</id> - <build> - <plugins> - <plugin> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-maven-plugin</artifactId> - <executions> - <execution> - <id>create0</id> - <goals> - <goal>create</goal> - </goals> - <configuration> - <instance>${basedir}/target/server0</instance> - <configuration>${basedir}/target/classes/activemq/server0</configuration> - </configuration> - </execution> - <execution> - <id>create1</id> - <goals> - <goal>create</goal> - </goals> - <configuration> - <instance>${basedir}/target/server1</instance> - <configuration>${basedir}/target/classes/activemq/server1</configuration> - </configuration> - </execution> - <execution> - <id>start0</id> - <goals> - <goal>cli</goal> - </goals> - <configuration> - <spawn>true</spawn> - <testURI>tcp://localhost:61616</testURI> - <args> - <param>run</param> - </args> - <name>server0</name> - </configuration> - </execution> - <execution> - <id>start1</id> - <goals> - <goal>cli</goal> - </goals> - <configuration> - <spawn>true</spawn> - <location>${basedir}/target/server1</location> - <testURI>tcp://localhost:61617</testURI> - <args> - <param>run</param> - </args> - <name>server1</name> - </configuration> - </execution> - <execution> - <id>runClient</id> - <goals> - <goal>runClient</goal> - </goals> - <configuration> - <clientClass>org.apache.activemq.artemis.jms.example.DivertExample</clientClass> - </configuration> - </execution> - <execution> - <id>stop0</id> - <goals> - <goal>cli</goal> - </goals> - <configuration> - <location>${basedir}/target/server0</location> - <args> - <param>stop</param> - </args> - </configuration> - </execution> - <execution> - <id>stop1</id> - <goals> - <goal>cli</goal> - </goals> - <configuration> - <location>${basedir}/target/server1</location> - <args> - <param>stop</param> - </args> - </configuration> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>org.apache.activemq.examples.jms</groupId> - <artifactId>artemis-jms-divert-example</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - </plugin> - </plugins> - </build> + <!-- specify -PnoServer if you don't want to start the server --> + <id>noServer</id> + <properties> + <noServer>true</noServer> + </properties> </profile> </profiles> + <build> + <plugins> + <plugin> + <groupId>org.apache.activemq</groupId> + <artifactId>artemis-maven-plugin</artifactId> + <executions> + <execution> + <id>create0</id> + <goals> + <goal>create</goal> + </goals> + <configuration> + <ignore>${noServer}</ignore> + <libList><arg>org.apache.activemq.examples.jms:divert:${project.version}</arg></libList> + <instance>${basedir}/target/server0</instance> + <configuration>${basedir}/target/classes/activemq/server0</configuration> + </configuration> + </execution> + <execution> + <id>create1</id> + <goals> + <goal>create</goal> + </goals> + <configuration> + <ignore>${noServer}</ignore> + <libList><arg>org.apache.activemq.examples.jms:divert:${project.version}</arg></libList> + <instance>${basedir}/target/server1</instance> + <configuration>${basedir}/target/classes/activemq/server1</configuration> + </configuration> + </execution> + <execution> + <id>start0</id> + <goals> + <goal>cli</goal> + </goals> + <configuration> + <ignore>${noServer}</ignore> + <spawn>true</spawn> + <testURI>tcp://localhost:61616</testURI> + <args> + <param>run</param> + </args> + <name>server0</name> + </configuration> + </execution> + <execution> + <id>start1</id> + <goals> + <goal>cli</goal> + </goals> + <configuration> + <ignore>${noServer}</ignore> + <spawn>true</spawn> + <location>${basedir}/target/server1</location> + <testURI>tcp://localhost:61617</testURI> + <args> + <param>run</param> + </args> + <name>server1</name> + </configuration> + </execution> + <execution> + <id>runClient</id> + <goals> + <goal>runClient</goal> + </goals> + <configuration> + <clientClass>org.apache.activemq.artemis.jms.example.DivertExample</clientClass> + </configuration> + </execution> + <execution> + <id>stop0</id> + <goals> + <goal>cli</goal> + </goals> + <configuration> + <ignore>${noServer}</ignore> + <location>${basedir}/target/server0</location> + <args> + <param>stop</param> + </args> + </configuration> + </execution> + <execution> + <id>stop1</id> + <goals> + <goal>cli</goal> + </goals> + <configuration> + <ignore>${noServer}</ignore> + <location>${basedir}/target/server1</location> + <args> + <param>stop</param> + </args> + </configuration> + </execution> + </executions> + <dependencies> + <dependency> + <groupId>org.apache.activemq.examples.jms</groupId> + <artifactId>divert</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> </project> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/divert/readme.html ---------------------------------------------------------------------- diff --git a/examples/jms/divert/readme.html b/examples/jms/divert/readme.html index 6a5707f..62067d6 100644 --- a/examples/jms/divert/readme.html +++ b/examples/jms/divert/readme.html @@ -26,6 +26,7 @@ under the License. </head> <body onload="prettyPrint()"> <h1>Divert 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>ActiveMQ Artemis diverts allow messages to be transparently "diverted" from one address to another with just some simple configuration defined on the server side.</p> @@ -114,325 +115,5 @@ under the License. </bridges> </code> </pre> - - <p><i>To run the example, simply type <code>mvn verify -Pexample</code> from this directory</i></p> - - <ol> - <li>Create an initial context to perform the JNDI lookup on the London server</li> - <pre class="prettyprint"> - <code> - initialContext0 = getContext(0); - </code> - </pre> - - <li>Look-up the queue orderQueue on the London server - this is the queue any orders are sent to</li> - <pre class="prettyprint"> - <code> - Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue"); - </code> - </pre> - - <li>Look-up the topic priceUpdates on the London server- this is the topic that any price updates are sent to</li> - <pre class="prettyprint"> - <code> - Topic priceUpdates = (Topic)initialContextLondon.lookup("/topic/priceUpdates"); - </code> - </pre> - - <li>Look-up the spy topic on the London server- this is what we will use to snoop on any orders</li> - <pre class="prettyprint"> - <code> - Topic spyTopic = (Topic)initialContextLondon.lookup("/topic/spyTopic"); - </code> - </pre> - - <li>Create an initial context to perform the JNDI lookup on the New York server.</li> - <pre class="prettyprint"> - <code> - initialContextNewYork = getContext(1); - </code> - </pre> - - <li>Look-up the topic newYorkPriceUpdates on the New York server - any price updates sent to priceUpdates on the London server will - be diverted to the queue priceForward on the London server, and a bridge will consume from that queue and forward - them to the address newYorkPriceUpdates on the New York server where they will be distributed to the topic subscribers on - the New York server. - </li> - <pre class="prettyprint"> - <code> - Topic newYorkPriceUpdates = (Topic)initialContextNewYork.lookup("/topic/newYorkPriceUpdates"); - </code> - </pre> - - <li>Perform a lookup on the Connection Factory on the London server</li> - <pre class="prettyprint"> - <code> - ConnectionFactory cfLondon = (ConnectionFactory)initialContextLondon.lookup("/ConnectionFactory"); - </code> - </pre> - - <li>Perform a lookup on the Connection Factory on the New York server.</li> - <pre class="prettyprint"> - <code> - ConnectionFactory cfNewYork = (ConnectionFactory)initialContextNewYork.lookup("/ConnectionFactory"); - </code> - </pre> - - <li>Create a JMS Connection on the London server</li> - <pre class="prettyprint"> - <code> - connectionLondon = cfLondon.createConnection(); - </code> - </pre> - - <li>Create a JMS Connection on the New York server</li> - <pre class="prettyprint"> - <code> - connectionNewYork = cfNewYork.createConnection(); - </code> - </pre> - - <li>Create a JMS Session on the London server.</li> - <pre class="prettyprint"> - <code> - Session sessionLondon = connectionLondon.createSession(false, Session.AUTO_ACKNOWLEDGE); - </code> - </pre> - - <li>Create a JMS Session on the New York server.</li> - <pre class="prettyprint"> - <code> - Session sessionNewYork = connectionNewYork.createSession(false, Session.AUTO_ACKNOWLEDGE); - </code> - </pre> - - <li>Create a JMS MessageProducer orderProducer that sends to the queue orderQueue on the London server.</li> - <pre class="prettyprint"> - <code> - MessageProducer orderProducer = sessionLondon.createProducer(orderQueue); - /code> - </pre> - - <li>Create a JMS MessageProducer priceProducer that sends to the topic priceUpdates on the London server.</li> - <pre class="prettyprint"> - <code> - MessageProducer priceProducer = sessionLondon.createProducer(priceUpdates); - /code> - </pre> - - <li>Create a JMS subscriber which subscribes to the spyTopic on the London server</li> - <pre class="prettyprint"> - <code> - MessageConsumer spySubscriberA = sessionLondon.createConsumer(spyTopic); - </code> - </pre> - - <li>Create another JMS subscriber which also subscribes to the spyTopic on the London server</li> - <pre class="prettyprint"> - <code> - MessageConsumer spySubscriberB = sessionLondon.createConsumer(spyTopic); - </code> - </pre> - - <li>Create a JMS MessageConsumer which consumes orders from the order queue on the London server</li> - <pre class="prettyprint"> - <code> - MessageConsumer orderConsumer = sessionLondon.createConsumer(orderQueue); - </code> - </pre> - - <li>Create a JMS subscriber which subscribes to the priceUpdates topic on the London server</li> - <pre class="prettyprint"> - <code> - MessageConsumer priceUpdatesSubscriberLondon = sessionLondon.createConsumer(priceUpdates); - </code> - </pre> - - <li>Create a JMS subscriber which subscribes to the newYorkPriceUpdates topic on the New York server</li> - <pre class="prettyprint"> - <code> - MessageConsumer newYorkPriceUpdatesSubscriberA = sessionNewYork.createConsumer(newYorkPriceUpdates); - </code> - </pre> - - <li>Create another JMS subscriber which also subscribes to the newYorkPriceUpdates topic on the New York server</li> - <pre class="prettyprint"> - <code> - MessageConsumer newYorkPriceUpdatesSubscriberB = sessionNewYork.createConsumer(newYorkPriceUpdates); - </code> - </pre> - - <li>Start the connections</li> - <pre class="prettyprint"> - <code> - connectionLondon.start(); - - connectionNewYork.start(); - </code> - </pre> - - <li>Create an order message</li> - <pre class="prettyprint"> - <code> - TextMessage orderMessage = sessionLondon.createTextMessage("This is an order"); - </code> - </pre> - - <li>Send the order message to the order queue on the London server</li> - <pre class="prettyprint"> - <code> - orderProducer.send(orderMessage); - - System.out.println("Sent message: " + orderMessage.getText()); - </code> - </pre> - - <li>The order message is consumed by the orderConsumer on the London server</li> - <pre class="prettyprint"> - <code> - TextMessage receivedOrder = (TextMessage)orderConsumer.receive(5000); - - System.out.println("Received order: " + receivedOrder.getText()); - </code> - </pre> - - <li>A copy of the order is also received by the spyTopic subscribers on the London server</li> - <pre class="prettyprint"> - <code> - TextMessage spiedOrder1 = (TextMessage)spySubscriberA.receive(5000); - - System.out.println("Snooped on order: " + spiedOrder1.getText()); - - TextMessage spiedOrder2 = (TextMessage)spySubscriberB.receive(5000); - - System.out.println("Snooped on order: " + spiedOrder2.getText()); - </code> - </pre> - - <li>Create and send a price update message, destined for London</li> - <pre class="prettyprint"> - <code> - TextMessage priceUpdateMessageLondon = sessionLondon.createTextMessage("This is a price update for London"); - - priceUpdateMessageLondon.setStringProperty("office", "London"); - - priceProducer.send(priceUpdateMessageLondon); - </code> - </pre> - - <li>The price update *should* be received by the local subscriber since we only divert messages - where office = New York</li> - <pre class="prettyprint"> - <code> - TextMessage receivedUpdate = (TextMessage)priceUpdatesSubscriberLondon.receive(2000); - - System.out.println("Received price update locally: " + receivedUpdate.getText()); - </code> - </pre> - - <li>The price update *should not* be received in New York</li> - <pre class="prettyprint"> - <code> - TextMessage priceUpdate1 = (TextMessage)newYorkPriceUpdatesSubscriberA.receive(1000); - - if (priceUpdate1 != null) - { - return false; - } - - System.out.println("Did not received price update in New York, look it's: " + priceUpdate1); - - TextMessage priceUpdate2 = (TextMessage)newYorkPriceUpdatesSubscriberB.receive(1000); - - if (priceUpdate2 != null) - { - return false; - } - - System.out.println("Did not received price update in New York, look it's: " + priceUpdate2); - </code> - </pre> - - <li>Create a price update message, destined for New York</li> - <pre class="prettyprint"> - <code> - TextMessage priceUpdateMessageNewYork = sessionLondon.createTextMessage("This is a price update for New York"); - - priceUpdateMessageNewYork.setStringProperty("office", "New York"); - </code> - </pre> - - <li>Send the price update message to the priceUpdates topic on the London server</li> - <pre class="prettyprint"> - <code> - priceProducer.send(priceUpdateMessageNewYork); - </code> - </pre> - - <li>The price update *should not* be received by the local subscriber to the priceUpdates topic - since it has been *exclusively* diverted to the priceForward queue, because it has a header saying - it is destined for the New York office</li> - <pre class="prettyprint"> - <code> - Message message = priceUpdatesSubscriberLondon.receive(1000); - - if (message != null) - { - return false; - } - - System.out.println("Didn't receive local price update, look, it's: " + message); - </code> - </pre> - - <li>The remote subscribers on server 1 *should* receive a copy of the price update since - it has been diverted to a local priceForward queue which has a bridge consuming from it and which - forwards it to the same address on server 1. - We notice how the forwarded messages have had a special header added by our custom transformer that - we told the divert to use</li> - <pre class="prettyprint"> - <code> - priceUpdate1 = (TextMessage)newYorkPriceUpdatesSubscriberA.receive(5000); - - System.out.println("Received forwarded price update on server 1: " + priceUpdate1.getText()); - System.out.println("Time of forward: " + priceUpdate1.getLongProperty("time_of_forward")); - - priceUpdate2 = (TextMessage)newYorkPriceUpdatesSubscriberB.receive(5000); - - System.out.println("Received forwarded price update on server 2: " + priceUpdate2.getText()); - System.out.println("Time of forward: " + priceUpdate2.getLongProperty("time_of_forward")); - </code> - </pre> - - - <li>And finally, <b>always</b> remember to close your resources after use, in a <code>finally</code> block.</li> - - <pre class="prettyprint"> - <code> - finally - { - if (initialContextLondon != null) - { - initialContextLondon.close(); - } - if (initialContextNewYork != null) - { - initialContextNewYork.close(); - } - if (connectionLondon != null) - { - connectionLondon.close(); - } - if (connectionNewYork != null) - { - connectionNewYork.close(); - } - } - </code> - </pre> - - - - </ol> </body> </html> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/divert/src/main/java/org/apache/activemq/artemis/jms/example/DivertExample.java ---------------------------------------------------------------------- diff --git a/examples/jms/divert/src/main/java/org/apache/activemq/artemis/jms/example/DivertExample.java b/examples/jms/divert/src/main/java/org/apache/activemq/artemis/jms/example/DivertExample.java index 9cbaaa6..3d74c55 100644 --- a/examples/jms/divert/src/main/java/org/apache/activemq/artemis/jms/example/DivertExample.java +++ b/examples/jms/divert/src/main/java/org/apache/activemq/artemis/jms/example/DivertExample.java @@ -25,8 +25,9 @@ import javax.jms.Queue; import javax.jms.Session; import javax.jms.TextMessage; import javax.jms.Topic; -import javax.naming.InitialContext; -import java.util.Hashtable; + +import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; /** * This examples demonstrates the use of ActiveMQ Artemis "Diverts" to transparently divert or copy messages @@ -41,37 +42,17 @@ public class DivertExample Connection connectionLondon = null; Connection connectionNewYork = null; - - InitialContext initialContextLondon = null; - - InitialContext initialContextNewYork = null; try { - // Step 1. Create an initial context to perform the JNDI lookup on the London server - Hashtable<String, Object> properties = new Hashtable<String, Object>(); - properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); - properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61616"); - properties.put("queue.queue/orders", "orders"); - properties.put("topic.topic/priceUpdates", "priceUpdates"); - properties.put("topic.topic/spyTopic", "spyTopic"); - initialContextLondon = new InitialContext(properties); - // Step 2. Look-up the queue orderQueue on the London server - this is the queue any orders are sent to - Queue orderQueue = (Queue)initialContextLondon.lookup("queue/orders"); + Queue orderQueue = ActiveMQJMSClient.createQueue("orders"); // Step 3. Look-up the topic priceUpdates on the London server- this is the topic that any price updates are // sent to - Topic priceUpdates = (Topic)initialContextLondon.lookup("topic/priceUpdates"); + Topic priceUpdates = ActiveMQJMSClient.createTopic("priceUpdates"); // Step 4. Look-up the spy topic on the London server- this is what we will use to snoop on any orders - Topic spyTopic = (Topic)initialContextLondon.lookup("topic/spyTopic"); - - // Step 6. Create an initial context to perform the JNDI lookup on the New York server - properties = new Hashtable<String, Object>(); - properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); - properties.put("connectionFactory.ConnectionFactory2", "tcp://localhost:61617"); - properties.put("topic.topic/newYorkPriceUpdates", "newYorkPriceUpdates"); - initialContextNewYork = new InitialContext(properties); + Topic spyTopic = ActiveMQJMSClient.createTopic("spyTopic"); // Step 7. Look-up the topic newYorkPriceUpdates on the New York server - any price updates sent to // priceUpdates on the London server will @@ -80,13 +61,13 @@ public class DivertExample // them to the address newYorkPriceUpdates on the New York server where they will be distributed to the topic // subscribers on // the New York server - Topic newYorkPriceUpdates = (Topic)initialContextNewYork.lookup("topic/newYorkPriceUpdates"); + Topic newYorkPriceUpdates = ActiveMQJMSClient.createTopic("newYorkPriceUpdates"); // Step 8. Perform a lookup on the Connection Factory on the London server - ConnectionFactory cfLondon = (ConnectionFactory)initialContextLondon.lookup("ConnectionFactory"); + ConnectionFactory cfLondon = new ActiveMQConnectionFactory("tcp://localhost:61616"); // Step 9. Perform a lookup on the Connection Factory on the New York server - ConnectionFactory cfNewYork = (ConnectionFactory)initialContextNewYork.lookup("ConnectionFactory2"); + ConnectionFactory cfNewYork = new ActiveMQConnectionFactory("tcp://localhost:61617"); // Step 10. Create a JMS Connection on the London server connectionLondon = cfLondon.createConnection(); @@ -226,15 +207,6 @@ public class DivertExample } finally { - // Step 12. Be sure to close our resources! - if (initialContextLondon != null) - { - initialContextLondon.close(); - } - if (initialContextNewYork != null) - { - initialContextNewYork.close(); - } if (connectionLondon != null) { connectionLondon.close(); http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/durable-subscription/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/durable-subscription/pom.xml b/examples/jms/durable-subscription/pom.xml index 9571cd8..a87bf28 100644 --- a/examples/jms/durable-subscription/pom.xml +++ b/examples/jms/durable-subscription/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> @@ -27,7 +28,7 @@ under the License. <version>1.0.1-SNAPSHOT</version> </parent> - <artifactId>artemis-jms-durable-subscription-example</artifactId> + <artifactId>durable-subscription</artifactId> <packaging>jar</packaging> <name>ActiveMQ Artemis JMS Durable Subscription Example</name> @@ -37,71 +38,82 @@ under the License. <dependencies> <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-jms_2.0_spec</artifactId> + <groupId>org.apache.activemq</groupId> + <artifactId>artemis-jms-client</artifactId> + <version>${project.version}</version> </dependency> </dependencies> <profiles> <profile> - <id>example</id> - <build> - <plugins> - <plugin> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-maven-plugin</artifactId> - <executions> - <execution> - <id>create</id> - <goals> - <goal>create</goal> - </goals> - </execution> - <execution> - <id>start</id> - <goals> - <goal>cli</goal> - </goals> - <configuration> - <spawn>true</spawn> - <testURI>tcp://localhost:61616</testURI> - <args> - <param>run</param> - </args> - </configuration> - </execution> - <execution> - <id>runClient</id> - <goals> - <goal>runClient</goal> - </goals> - <configuration> - <clientClass>org.apache.activemq.artemis.jms.example.DurableSubscriptionExample</clientClass> - </configuration> - </execution> - <execution> - <id>stop</id> - <goals> - <goal>cli</goal> - </goals> - <configuration> - <args> - <param>stop</param> - </args> - </configuration> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>org.apache.activemq.examples.jms</groupId> - <artifactId>artemis-jms-durable-subscription-example</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - </plugin> - </plugins> - </build> + <!-- specify -PnoServer if you don't want to start the server --> + <id>noServer</id> + <properties> + <noServer>true</noServer> + </properties> </profile> </profiles> + <build> + <plugins> + <plugin> + <groupId>org.apache.activemq</groupId> + <artifactId>artemis-maven-plugin</artifactId> + <executions> + <execution> + <id>create</id> + <goals> + <goal>create</goal> + </goals> + <configuration> + <ignore>${noServer}</ignore> + <configuration>${basedir}/target/classes/activemq/server0</configuration> + </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.DurableSubscriptionExample</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>durable-subscription</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> </project> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/durable-subscription/readme.html ---------------------------------------------------------------------- diff --git a/examples/jms/durable-subscription/readme.html b/examples/jms/durable-subscription/readme.html index 4379baa..def30b7 100644 --- a/examples/jms/durable-subscription/readme.html +++ b/examples/jms/durable-subscription/readme.html @@ -27,133 +27,13 @@ under the License. <body onload="prettyPrint()"> <h1>JMS Durable Subscription Example</h1> + <pre>To run the example, simply type <b>mvn verify</b> from this directory, <br>or <b>mvn -PnoServer verify</b> if you want to start and create the server manually.</pre> <p>This example demonstrates how to use a durable subscription with ActiveMQ Artemis.</p> <p>Durable subscriptions are a standard part of JMS, please consult the JMS 1.1 specification for full details.</p> <p>Unlike non durable subscriptions, the key function of durable subscriptions is that the messages contained in them persist longer than the lifetime of the subscriber - i.e. they will accumulate messages sent to the topic even - if the subscriber is not currently connected. They will also survive server restarts. Note that for the messages to + if the subscriber is not currently connected. They will also survive server restarts. Note that for the messages to be persisted, the messages sent to them must be marked as persistent messages.</p> - <h2>Example step-by-step</h2> - <p><i>To run the example, simply type <code>mvn verify -Pexample</code> from this directory</i></p> - - <ol> - <li>First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the <code>client-jndi.properties</code> file in the directory <code>../common/config</code></li> - <pre class="prettyprint"> - <code>initialContext = getContext();</code> - </pre> - - <li>We look-up the JMS topic object from JNDI</li> - <pre class="prettyprint"> - <code>Topic topic = (Topic) initialContext.lookup("/topic/exampleTopic");</code> - </pre> - - <li>We look-up the JMS connection factory object from JNDI</li> - <pre class="prettyprint"> - <code>ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");</code> - </pre> - - <li>We create a JMS connection</li> - <pre class="prettyprint"> - <code>connection = cf.createConnection();</code> - </pre> - - <li>We set the client-id on the connection. This must be the <b>first operation</b> performed on the connection object. - The combination of client-id and durable subscription name uniquely identifies the durable subscription. Maybe different durable subscritions can have the same name if they belong to different client-id values</li> - <pre class="prettyprint"> - <code>connection.setClientID("durable-client");</code> - </pre> - - <li>We start the connection. In order for delivery to occur on any consumers or subscribers on a connection, the connection must be started</li> - <pre class="prettyprint"> - <code>connection.start();</code> - </pre> - - <li>We create a JMS session. The session is created as non transacted and will auto acknowledge messages.</li> - <pre class="prettyprint"> - <code>Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);</code> - </pre> - - <li>We create a JMS message producer on the session. This will be used to send the messages.</li> - <pre class="prettyprint"> - <code>MessageProducer messageProducer = session.createProducer(topic);</code> - </pre> - - <li>We create the durable subscriber on the topic, specifying it's name. Since this is the first time the subscriber is created and a subscription with that name and for this client-id does not already exist, then the underlying durable subscription will be created, and a subscriber will be created and returned for that subscription.</li> - <pre class="prettyprint"> - <code>TopicSubscriber subscriber = session.createDurableSubscriber(topic, "subscriber-1");</code> - </pre> - - <li>We create a JMS text message, message 1, that we are going to send. Note that it must be a persistent message in order to survive server restart.</li> - <pre class="prettyprint"> - <code>TextMessage message1 = session.createTextMessage("This is a text message 1");</code> - </pre> - - <li>We send message 1 to the topic</li> - <pre class="prettyprint"> - <code>messageProducer.send(message1);</code> - </pre> - - <li>The message arrives in the subscription, and we consume the message from the subscription.</li> - <pre class="prettyprint"> - <code>TextMessage messageReceived = (TextMessage)subscriber.receive();</code> - </pre> - - <li>We create and send another text message, message 2, to the same topic</li> - <pre class="prettyprint"> - <code>TextMessage message2 = session.createTextMessage("This is a text message 2"); - - messageProducer.send(message2);</code> - </pre> - - <li>Now we close the subscriber. Since the subscription is durable it will continue to survive even though there is no subscriber attached to it. At this point you could even stop and restart the server and the subscription would survive!</li> - - <pre class="prettyprint"> - <code>subscriber.close();</code> - </pre> - - <li>We now create another durable subscriber, with the same name and same client-id on the same topic. Since the durable subscrition already exists, it will simply return a new subscriber consuming from the <i>same</i> durable subscription instance as before</li> - - <pre class="prettyprint"> - <code>subscriber = session.createDurableSubscriber(topic, "subscriber-1");</code> - </pre> - - <li>We consume message 2 which was sent before the first subscriber was closed.</li> - - <pre class="prettyprint"> - <code>messageReceived = (TextMessage)subscriber.receive();</code> - </pre> - - <li>We close the second subscriber.</li> - - <pre class="prettyprint"> - <code>subscriber.close();</code> - </pre> - - <li>Now we <i>delete</i> the underlying durable subscription. This will delete any remaining unacknowledged messages in the subscription and a new subscriber will not be able to access them</li> - - <pre class="prettyprint"> - <code>session.unsubscribe("subscriber-1");</code> - </pre> - - <li>And finally, <b>always</b> remember to close your JMS connections and resources after use, in a <code>finally</code> block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects</li> - - <pre class="prettyprint"> - <code>finally - { - if (initialContext != null) - { - initialContext.close(); - } - if (connection != null) - { - connection.close(); - } - }</code> - </pre> - - - - </ol> </body> </html> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/embedded-simple/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/embedded-simple/pom.xml b/examples/jms/embedded-simple/pom.xml index a1dae09..8b19033 100644 --- a/examples/jms/embedded-simple/pom.xml +++ b/examples/jms/embedded-simple/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> @@ -27,7 +28,7 @@ under the License. <version>1.0.1-SNAPSHOT</version> </parent> - <artifactId>artemis-jms-embedded-simple-example</artifactId> + <artifactId>embedded-simple</artifactId> <packaging>jar</packaging> <name>ActiveMQ Artemis JMS Simple Embedded Example</name> @@ -47,41 +48,37 @@ under the License. <version>${project.version}</version> </dependency> <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-jms_2.0_spec</artifactId> + <groupId>org.apache.activemq</groupId> + <artifactId>artemis-jms-client</artifactId> + <version>${project.version}</version> </dependency> </dependencies> - <profiles> - <profile> - <id>example</id> - <build> - <plugins> - <plugin> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-maven-plugin</artifactId> - <executions> - <execution> - <id>runClient</id> - <goals> - <goal>runClient</goal> - </goals> - <configuration> - <clientClass>org.apache.activemq.artemis.jms.example.EmbeddedExample</clientClass> - </configuration> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>org.apache.activemq.examples.jms</groupId> - <artifactId>artemis-jms-embedded-simple-example</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - </plugin> - </plugins> - </build> - </profile> - </profiles> + <build> + <plugins> + <plugin> + <groupId>org.apache.activemq</groupId> + <artifactId>artemis-maven-plugin</artifactId> + <executions> + <execution> + <id>runClient</id> + <goals> + <goal>runClient</goal> + </goals> + <configuration> + <clientClass>org.apache.activemq.artemis.jms.example.EmbeddedExample</clientClass> + </configuration> + </execution> + </executions> + <dependencies> + <dependency> + <groupId>org.apache.activemq.examples.jms</groupId> + <artifactId>embedded-simple</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> </project> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/embedded/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/embedded/pom.xml b/examples/jms/embedded/pom.xml index 8d81f45..75d876c 100644 --- a/examples/jms/embedded/pom.xml +++ b/examples/jms/embedded/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> @@ -27,7 +28,7 @@ under the License. <version>1.0.1-SNAPSHOT</version> </parent> - <artifactId>artemis-jms-embedded-example</artifactId> + <artifactId>embedded</artifactId> <packaging>jar</packaging> <name>ActiveMQ Artemis JMS Embedded Example</name> @@ -47,41 +48,37 @@ under the License. <version>${project.version}</version> </dependency> <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-jms_2.0_spec</artifactId> + <groupId>org.apache.activemq</groupId> + <artifactId>artemis-jms-client</artifactId> + <version>${project.version}</version> </dependency> </dependencies> - <profiles> - <profile> - <id>example</id> - <build> - <plugins> - <plugin> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-maven-plugin</artifactId> - <executions> - <execution> - <id>runClient</id> - <goals> - <goal>runClient</goal> - </goals> - <configuration> - <clientClass>org.apache.activemq.artemis.jms.example.EmbeddedExample</clientClass> - </configuration> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>org.apache.activemq.examples.jms</groupId> - <artifactId>artemis-jms-embedded-example</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - </plugin> - </plugins> - </build> - </profile> - </profiles> + <build> + <plugins> + <plugin> + <groupId>org.apache.activemq</groupId> + <artifactId>artemis-maven-plugin</artifactId> + <executions> + <execution> + <id>runClient</id> + <goals> + <goal>runClient</goal> + </goals> + <configuration> + <clientClass>org.apache.activemq.artemis.jms.example.EmbeddedExample</clientClass> + </configuration> + </execution> + </executions> + <dependencies> + <dependency> + <groupId>org.apache.activemq.examples.jms</groupId> + <artifactId>embedded</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> </project> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/embedded/readme.html ---------------------------------------------------------------------- diff --git a/examples/jms/embedded/readme.html b/examples/jms/embedded/readme.html index b64ea4c..b1bdd0f 100644 --- a/examples/jms/embedded/readme.html +++ b/examples/jms/embedded/readme.html @@ -26,78 +26,13 @@ under the License. </head> <body onload="prettyPrint()"> <h1>Embedded JMS Server Example</h1> - + <pre>To run the example, simply type <b>mvn verify</b> from this directory</pre> + <p>This examples shows how to setup and run an embedded JMS server using ActiveMQ Artemis.</p> <p>ActiveMQ Artemis was designed using POJOs (Plain Old Java Objects) which means embedding ActiveMQ Artemis in your own application is as simple as instantiating a few objects.</p> - <p>This example does not use any configuration files. The server is configured using POJOs and can be easily ported to any dependency injection framework.<br /> + <p>This example does not use any configuration files. The server is configured using POJOs and can be easily ported to any dependency injection framework.<br /> We will setup and run a full-fledged JMS server which binds its JMS resources to JNDI and can be accessed by remote clients.</p> - - <h2>Example step-by-step</h2> - <p><i>To run the example, simply type <code>mvn verify -Pexample</code> from this directory</i></p> - - <ol> - <li>Create ActiveMQ Artemis core configuration, and set the properties accordingly</li> - <pre class="prettyprint"> - <code>Configuration configuration = new ConfigurationImpl(); - configuration.setPersistenceEnabled(false); - configuration.setSecurityEnabled(false); - configuration.getAcceptorConfigurations().add(new TransportConfiguration(NettyAcceptorFactory.class.getName()));</code> - Configuration configuration = new ConfigurationImpl();</pre> - - <li>Create the ActiveMQ Artemis core server</li> - <pre class="prettyprint"> - <code>ActiveMQServer activemqServer = ActiveMQ Artemis.newActiveMQServer(configuration);</code> - </pre> - - <li>Create the JMS configuration</li> - <pre class="prettyprint"> - <code>JMSConfiguration jmsConfig = new JMSConfigurationImpl();</code> - </pre> - - <li>Configure the JMS ConnectionFactory</li> - <pre class="prettyprint"> - <code>TransportConfiguration connectorConfig = new TransportConfiguration(NettyConnectorFactory.class.getName()); - ConnectionFactoryConfiguration cfConfig = new ConnectionFactoryConfigurationImpl("cf", connectorConfig, "/cf"); - jmsConfig.getConnectionFactoryConfigurations().add(cfConfig);</code> - </pre> - - <li>Configure the JMS Queue</li> - <pre class="prettyprint"> - <code>QueueConfiguration queueConfig = new QueueConfigurationImpl("queue1", null, false, "/queue/queue1"); - jmsConfig.getQueueConfigurations().add(queueConfig);</code> - </pre> - - <li>Start the JMS Server using the ActiveMQ Artemis core server and the JMS configuration</li> - <pre class="prettyprint"> - <code>JMSServerManager jmsServer = new JMSServerManagerImpl(activemqServer, jmsConfig); - jmsServer.start();</code> - </pre> - <p>At this point the JMS server is started and any JMS clients can look up JMS resources from JNDI to send/receive - messages from the server. To keep the example simple, we will send and receive a JMS message from the same JVM - used to run the JMS server.</p> - - <li>Lookup JMS resources defined in the configuration </li> - <pre class="prettyprint"> - <code>ConnectionFactory cf = (ConnectionFactory)context.lookup("/cf"); - Queue queue = (Queue)context.lookup("/queue/queue1");</code> - </pre> - - <li>Send and receive a message using JMS API</li> - <p>See the <a href="../../queue/readme.html">Queue Example</a> for detailed steps to send and receive a JMS message</p> - - <p>Finally, we stop the JMS server and its associated resources.</p> - - <li>Stop the JMS server</li> - <pre class="prettyprint"> - <code>jmsServer.stop();</code> - </pre> - - <li>Stop the JNDI server</li> - <pre class="prettyprint"> - <code>naming.stop();</code> - </pre> - </ol> </body> </html> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/expiry/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/expiry/pom.xml b/examples/jms/expiry/pom.xml index 9c53999..44c48e4 100644 --- a/examples/jms/expiry/pom.xml +++ b/examples/jms/expiry/pom.xml @@ -18,7 +18,8 @@ specific language governing permissions and limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> @@ -27,7 +28,7 @@ under the License. <version>1.0.1-SNAPSHOT</version> </parent> - <artifactId>artemis-jms-expiry-example</artifactId> + <artifactId>expiry</artifactId> <packaging>jar</packaging> <name>ActiveMQ Artemis JMS Expiry Example</name> @@ -37,71 +38,82 @@ under the License. <dependencies> <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-jms_2.0_spec</artifactId> + <groupId>org.apache.activemq</groupId> + <artifactId>artemis-jms-client</artifactId> + <version>${project.version}</version> </dependency> </dependencies> <profiles> <profile> - <id>example</id> - <build> - <plugins> - <plugin> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-maven-plugin</artifactId> - <executions> - <execution> - <id>create</id> - <goals> - <goal>create</goal> - </goals> - </execution> - <execution> - <id>start</id> - <goals> - <goal>cli</goal> - </goals> - <configuration> - <spawn>true</spawn> - <testURI>tcp://localhost:61616</testURI> - <args> - <param>run</param> - </args> - </configuration> - </execution> - <execution> - <id>runClient</id> - <goals> - <goal>runClient</goal> - </goals> - <configuration> - <clientClass>org.apache.activemq.artemis.jms.example.ExpiryExample</clientClass> - </configuration> - </execution> - <execution> - <id>stop</id> - <goals> - <goal>cli</goal> - </goals> - <configuration> - <args> - <param>stop</param> - </args> - </configuration> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>org.apache.activemq.examples.jms</groupId> - <artifactId>artemis-jms-expiry-example</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - </plugin> - </plugins> - </build> + <!-- specify -PnoServer if you don't want to start the server --> + <id>noServer</id> + <properties> + <noServer>true</noServer> + </properties> </profile> </profiles> + <build> + <plugins> + <plugin> + <groupId>org.apache.activemq</groupId> + <artifactId>artemis-maven-plugin</artifactId> + <executions> + <execution> + <id>create</id> + <goals> + <goal>create</goal> + </goals> + <configuration> + <ignore>${noServer}</ignore> + <configuration>${basedir}/target/classes/activemq/server0</configuration> + </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.ExpiryExample</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>expiry</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> </project>
