http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6b17d966/examples/broker-features/standard/last-value-queue/readme.html ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/last-value-queue/readme.html b/examples/broker-features/standard/last-value-queue/readme.html deleted file mode 100644 index 1fb58ee..0000000 --- a/examples/broker-features/standard/last-value-queue/readme.html +++ /dev/null @@ -1,162 +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 Last-Value Queue 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>Last-Value Queue Example</h1> - - <pre>To run the example, simply type <b>mvn verify</b> from this directory, <br>or <b>mvn -PnoServer verify</b> if you want to start and create the server manually.</pre> - - <p>This example shows you how to configure and use last-value queues.</p> - <p>Last-Value queues are special queues which discard any messages when a newer message with the same value for a well-defined <em>Last-Value</em> property is put in the queue. - In other words, a Last-Value queue only retains the last value.</p> - <p>A typical example for Last-Value queue is for stock prices, where you are only interested by the latest value for a particular stock.</p> - - <p>The example will send 3 messages with the same <em>Last-Value</em> property to a to a Last-Value queue.<br /> - We will browse the queue and see that only the last message is in the queue, the first two messages have been discarded. <br /> - We will then consume from the queue the <em>last</em> message.</p> - - <h2>Example setup</h2> - <p>Last-Value queues are defined in the configuration file <a href="server0/broker.xml">broker.xml</a>:</p> - <pre class="prettyprint"> - <code><address-setting match="jms.queue.lastValueQueue"> - <last-value-queue>true</last-value-queue> - </address-setting></code> - </pre> - - <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 <a href="server0/client-jndi.properties">client-jndi.properties</a></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/lastValueQueue");</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, a session and a producer for the queue</li> - <pre class="prettyprint"> - <code> connection = cf.createConnection(); - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - MessageProducer producer = session.createProducer(queue);</code> - </pre> - - <li>We will create and send a text message with the Last-Value property set to <code>STOCK_NAME</code></li> - <pre class="prettyprint"> - <code>TextMessage message = session.createTextMessage("1st message with Last-Value property set"); - message.setStringProperty("_AMQ_LVQ_NAME", "STOCK_NAME"); - producer.send(message); - System.out.format("Sent message: %s\n", message.getText());</code> - </pre> - - <p><em>The <em>Last-Value</em> key is defined in ActiveMQ's MessageImpl class. Its value is <code>"_AMQ_LVQ_NAME"</code></em></p> - - <li>We will create and send a <em>second</em> text message with the Last-Value property set to <code>STOCK_NAME</code></li> - <pre class="prettyprint"> - <code>message = session.createTextMessage("2nd message with Last-Value property set"); - message.setStringProperty("_AMQ_LVQ_NAME", "STOCK_NAME"); - producer.send(message); - System.out.format("Sent message: %s\n", message.getText());</code> - </pre> - - <li>We will create and send a <em>third</em> text message with the Last-Value property set to <code>STOCK_NAME</code></li> - <pre class="prettyprint"> - <code>message = session.createTextMessage("3rd message with Last-Value property set"); - message.setStringProperty("_AMQ_LVQ_NAME", "STOCK_NAME"); - producer.send(message); - System.out.format("Sent message: %s\n", message.getText());</code> - </pre> - - <p><em>When the 2<sup>nd</sup> message was sent to the queue, the 1<sup>st</sup> message was discarded.<br /> - Similarly, when the 3<sup>rd</sup> message was sent to the queue, the 2<sup>nd</sup> message was discarded.<br /> - Only the 3<sup>rd</sup> message remains in the queue.</em></p> - - <li>We will browse the queue. There will be a single message displayed: the 3<sup>rd</sup> message</li> - <pre class="prettyprint"> - <code>QueueBrowser browser = session.createBrowser(queue); - Enumeration enumeration = browser.getEnumeration(); - while (enumeration.hasMoreElements()) - { - TextMessage messageInTheQueue = (TextMessage)enumeration.nextElement(); - System.out.format("Message in the queue: %s\n", messageInTheQueue.getText()); - } - browser.close(); - </code> - </pre> - - <p><em>We will now consume the message on the queue</em></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 try to receive a message from the queue. It will be the 3<sup>rd</sup> message</li> - <pre class="prettyprint"> - <code> TextMessage messageReceived = (TextMessage)messageConsumer.receive(5000); - System.out.format("Received message: %s\n", messageReceived.getText());</code> - </pre> - - <li>We will try to receive another message but there is no other on the queue. The <code>receive</code> method will timeout after 5 seconds</li> - <pre class="prettyprint"> - <code> messageReceived = (TextMessage)messageConsumer.receive(5000); - System.out.format("Received message: %s\n", messageReceived);</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#last-value-queues">Last-Value Queues chapter</a></li> - </ul> - </body> -</html>
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6b17d966/examples/broker-features/standard/last-value-queue/src/main/java/org/apache/activemq/artemis/jms/example/LastValueQueueExample.java ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/last-value-queue/src/main/java/org/apache/activemq/artemis/jms/example/LastValueQueueExample.java b/examples/broker-features/standard/last-value-queue/src/main/java/org/apache/activemq/artemis/jms/example/LastValueQueueExample.java deleted file mode 100644 index 469f839..0000000 --- a/examples/broker-features/standard/last-value-queue/src/main/java/org/apache/activemq/artemis/jms/example/LastValueQueueExample.java +++ /dev/null @@ -1,104 +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.MessageConsumer; -import javax.jms.MessageProducer; -import javax.jms.Queue; -import javax.jms.QueueBrowser; -import javax.jms.Session; -import javax.jms.TextMessage; -import java.util.Enumeration; - -import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; -import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; - -/** - * This example shows how to configure and use a <em>Last-Value</em> queues. - * Only the last message with a well-defined property is hold by the queue. - */ -public class LastValueQueueExample { - - public static void main(final String[] args) throws Exception { - Connection connection = null; - try { - // Step 2. new Queue - Queue queue = ActiveMQJMSClient.createQueue("exampleQueue"); - - // Step 3. new Connection Factory - ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(); - - // Step 4.Create a JMS Connection, session and producer on the queue - connection = cf.createConnection(); - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - MessageProducer producer = session.createProducer(queue); - - // Step 5. Create and send a text message with the Last-Value header set - TextMessage message = session.createTextMessage("1st message with Last-Value property set"); - message.setStringProperty("_AMQ_LVQ_NAME", "STOCK_NAME"); - producer.send(message); - System.out.format("Sent message: %s%n", message.getText()); - - // Step 6. Create and send a second text message with the Last-Value header set - message = session.createTextMessage("2nd message with Last-Value property set"); - message.setStringProperty("_AMQ_LVQ_NAME", "STOCK_NAME"); - producer.send(message); - System.out.format("Sent message: %s%n", message.getText()); - - // Step 7. Create and send a third text message with the Last-Value header set - message = session.createTextMessage("3rd message with Last-Value property set"); - message.setStringProperty("_AMQ_LVQ_NAME", "STOCK_NAME"); - producer.send(message); - System.out.format("Sent message: %s%n", message.getText()); - - // Step 8. Browse the queue. There is only 1 message in it, the last sent - QueueBrowser browser = session.createBrowser(queue); - Enumeration enumeration = browser.getEnumeration(); - while (enumeration.hasMoreElements()) { - TextMessage messageInTheQueue = (TextMessage) enumeration.nextElement(); - System.out.format("Message in the queue: %s%n", messageInTheQueue.getText()); - } - browser.close(); - - // Step 9. Create a JMS Message Consumer for the queue - MessageConsumer messageConsumer = session.createConsumer(queue); - - // Step 10. Start the Connection - connection.start(); - - // Step 11. Trying to receive a message. Since the queue is configured to keep only the - // last message with the Last-Value header set, the message received is the last sent - TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000); - System.out.format("Received message: %s%n", messageReceived.getText()); - - // Step 12. Trying to receive another message but there will be none. - // The 1st message was discarded when the 2nd was sent to the queue. - // The 2nd message was in turn discarded when the 3trd was sent to the queue - messageReceived = (TextMessage) messageConsumer.receive(5000); - System.out.format("Received message: %s%n", messageReceived); - - cf.close(); - } - finally { - // Step 13. Be sure to close our JMS resources! - if (connection != null) { - connection.close(); - } - } - } -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6b17d966/examples/broker-features/standard/last-value-queue/src/main/resources/activemq/server0/artemis-roles.properties ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/last-value-queue/src/main/resources/activemq/server0/artemis-roles.properties b/examples/broker-features/standard/last-value-queue/src/main/resources/activemq/server0/artemis-roles.properties deleted file mode 100644 index 4e2d44c..0000000 --- a/examples/broker-features/standard/last-value-queue/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/last-value-queue/src/main/resources/activemq/server0/artemis-users.properties ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/last-value-queue/src/main/resources/activemq/server0/artemis-users.properties b/examples/broker-features/standard/last-value-queue/src/main/resources/activemq/server0/artemis-users.properties deleted file mode 100644 index 4e2d44c..0000000 --- a/examples/broker-features/standard/last-value-queue/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/last-value-queue/src/main/resources/activemq/server0/broker.xml ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/last-value-queue/src/main/resources/activemq/server0/broker.xml b/examples/broker-features/standard/last-value-queue/src/main/resources/activemq/server0/broker.xml deleted file mode 100644 index 470de98..0000000 --- a/examples/broker-features/standard/last-value-queue/src/main/resources/activemq/server0/broker.xml +++ /dev/null @@ -1,67 +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 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-settings> - - <address-settings> - <!--override the expiry address for the example--> - <address-setting match="jms.queue.lastValueQueue"> - <last-value-queue>true</last-value-queue> - </address-setting> - </address-settings> - - </core> -</configuration> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6b17d966/examples/broker-features/standard/last-value-queue/src/main/resources/jndi.properties ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/last-value-queue/src/main/resources/jndi.properties b/examples/broker-features/standard/last-value-queue/src/main/resources/jndi.properties deleted file mode 100644 index 93537c4..0000000 --- a/examples/broker-features/standard/last-value-queue/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/management-notifications/pom.xml ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/management-notifications/pom.xml b/examples/broker-features/standard/management-notifications/pom.xml deleted file mode 100644 index bade921..0000000 --- a/examples/broker-features/standard/management-notifications/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>management-notifications</artifactId> - <packaging>jar</packaging> - <name>ActiveMQ Artemis JMS Management Notifications 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.ManagementNotificationExample</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>management-notifications</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/management-notifications/readme.html ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/management-notifications/readme.html b/examples/broker-features/standard/management-notifications/readme.html deleted file mode 100644 index 6ac1efa..0000000 --- a/examples/broker-features/standard/management-notifications/readme.html +++ /dev/null @@ -1,215 +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 Management Notification 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>Management Notification 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 to receive management notifications from ActiveMQ Artemis using JMS Messages.</p> - <p>ActiveMQ Artemis servers emit management notifications when events of interest occur (consumers are created or closed, - destinations are created or deleted, security authentication fails, etc.).<br /> - These notifications can be received either by using JMX (see <a href="../jmx/readme.html">JMX example</a>) or by receiving JMS Messages - from a well-known destination.</p> - <p>This example will setup a JMS MessageListener to receive management notifications. We will also perform normal JMS operations to see the kind - of notifications they trigger.</p> - - <h2>Example configuration</h2> - - <p>ActiveMQ Artemis can configured to send JMS messages when management notifications are emitted on the server.</p> - <p>By default, the management name is called <code>activemq.notifications</code> but this can be configured in <a href="server0/broker.xml">broker.xml</a>. - For this example, we will set it to <code>jms.topic.notificationsTopic</code> to be able to receive notifications from a JMS Topic.</p> - <pre class="prettyprint"> - <code><management-notification-address>jms.topic.notificationsTopic</management-notification-address></code> - </pre> - - <p>Since we want to lookup the notifications topic using JNDI, we also declare it in <a href="server0/activemq-jms.xml">activemq-jms.xml</a> - <pre class="prettyprint"> - <code><topic name="notificationsTopic"> - <entry name="/topic/notificationsTopic"/> - </topic></code> - </pre> - <p>The notification queue requires permission to create/delete temporary queues and consume messages. - This is also configured in <a href="server0/broker.xml">broker.xml</a></p> - <pre class="prettyprint"> - <code><!--security for notification topic--> - <security-setting match="jms.topic.notificationsTopic"> - <permission type="consume" roles="guest"/> - <permission type="createNonDurableQueue" roles="guest"/> - <permission type="deleteNonDurableQueue" roles="guest"/> - </security-setting></code> - </pre> - - <h2>Example step-by-step</h2> -x <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 its properties from <a href="server0/client-jndi.properties">client-jndi.properties</a></li> - <pre class="prettyprint"> - <code>InitialContext initialContext = getContext(0);</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, a session and a message producer for the example queue</li> - <pre class="prettyprint"> - <code>connection = cf.createConnection(); - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - MessageProducer producer = session.createProducer(queue);</code> - </pre> - - <li>We look up the JMS Topic used to receive the notifications from JNDI</li> - <pre class="prettyprint"> - <code>Topic notificationsTopic = (Topic) initialContext.lookup("/topic/notificationsTopic");</code> - </pre> - - <li>We create a MessageConsumer for the notification queue and set its MessageListener. When a notification is received, we will simply display all the message properties</li> - <pre class="prettyprint"> - <code>MessageConsumer notificationConsumer = session.createConsumer(notificationsTopic); - notificationConsumer.setMessageListener(new MessageListener() - { - public void onMessage(Message notif) - { - System.out.println("------------------------"); - System.out.println("Received notification:"); - try - { - Enumeration propertyNames = notif.getPropertyNames(); - while (propertyNames.hasMoreElements()) - { - String propertyName = (String)propertyNames.nextElement(); - System.out.format(" %s: %s\n", propertyName, notif.getObjectProperty(propertyName)); - } - } - catch (JMSException e) - { - } - System.out.println("------------------------"); - } - });</code> - </pre> - - <li>We start the connection to receive messages</li> - <pre class="prettyprint"> - <code>connection.start();</code> - </pre> - - <p><em>Now that a message listener is setup to receive management notifications, we will perform regular JMS operations to - see what kind of notifications are triggered</em></p> - - <li>We create a JMS message consumer on the example queue</li> - <pre class="prettyprint"> - <code>MessageConsumer consumer = session.createConsumer(queue);</code> - </pre> - - <p>This will generate a <code>CONSUMER_CREATED</code> notification: - <pre class="prettyprint"> - <code>------------------------ - Received notification: - _AMQ_RoutingName: jms.queue.exampleQueue - _AMQ_Address: jms.queue.exampleQueue - ... - _AMQ_ConsumerCount: 1 - ... - _AMQ_NotifType: CONSUMER_CREATED - ------------------------</code> - </pre> - <p>The notification tells us that a consumer was created for the JMS queue <code>exampleQueue</code>. When the notification - was emitted, this consumer was the only one for the queue</p> - - <li>We close this consumer</li> - <pre class="prettyprint"> - <code>consumer.close();</code> - </pre> - - <p>This will generate a <code>CONSUMER_CLOSED</code> notification: - <pre class="prettyprint"> - <code>------------------------ - Received notification: - _AMQ_RoutingName: jms.queue.exampleQueue - _AMQ_Address: jms.queue.exampleQueue - ... - _AMQ_ConsumerCount: 0 - ... - _AMQ_NotifType: CONSUMER_CLOSED - ------------------------</code> - </pre> - <p>The notification tells us that a consumer was closed for the JMS queue <code>exampleQueue</code>. When the notification - was emitted, there were no other consumers on the queue</p> - - <li>As a last example, we will create a connection with invalid user credentials</li> - <pre class="prettyprint"> - <code>try - { - cf.createConnection("not.a.valid.user", "not.a.valid.password"); - } catch (JMSException e) - { - }</code> - </pre> - - <p>This will generate a <code>SECURITY_AUTHENTICATION_VIOLATION</code> notification: - <pre class="prettyprint"> - <code>------------------------ - Received notification: - _AMQ_User: not.a.valid.user - ... - _AMQ_NotifType: SECURITY_AUTHENTICATION_VIOLATION - ------------------------ - </code> - </pre> - <p>The notification tells us that a user named <code>not.a.valid.user</code> failed to authenticate when creating a connection to ActiveMQ Artemis.</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#management.notifications">Management Notifications chapter</a></li> - </ul> - - </body> -</html> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6b17d966/examples/broker-features/standard/management-notifications/src/main/java/org/apache/activemq/artemis/jms/example/ManagementNotificationExample.java ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/management-notifications/src/main/java/org/apache/activemq/artemis/jms/example/ManagementNotificationExample.java b/examples/broker-features/standard/management-notifications/src/main/java/org/apache/activemq/artemis/jms/example/ManagementNotificationExample.java deleted file mode 100644 index 5fc00cf..0000000 --- a/examples/broker-features/standard/management-notifications/src/main/java/org/apache/activemq/artemis/jms/example/ManagementNotificationExample.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.activemq.artemis.jms.example; - -import java.util.Enumeration; - -import javax.jms.Connection; -import javax.jms.ConnectionFactory; -import javax.jms.JMSException; -import javax.jms.Message; -import javax.jms.MessageConsumer; -import javax.jms.MessageListener; -import javax.jms.MessageProducer; -import javax.jms.Queue; -import javax.jms.Session; -import javax.jms.Topic; -import javax.naming.InitialContext; - -/** - * An example that shows how to receive management notifications using JMS messages. - */ -public class ManagementNotificationExample { - - 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 queue - Queue queue = (Queue) initialContext.lookup("queue/exampleQueue"); - - // Step 3. Perform a lookup on the Connection Factory - ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("ConnectionFactory"); - - // Step 4.Create a JMS connection, a session and a producer for the queue - connection = cf.createConnection(); - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - MessageProducer producer = session.createProducer(queue); - - // Step 5. Perform a lookup on the notifications topic - Topic notificationsTopic = (Topic) initialContext.lookup("topic/notificationsTopic"); - - // Step 6. Create a JMS message consumer for the notification queue and set its message listener - // It will display all the properties of the JMS Message - MessageConsumer notificationConsumer = session.createConsumer(notificationsTopic); - notificationConsumer.setMessageListener(new MessageListener() { - public void onMessage(final Message notif) { - System.out.println("------------------------"); - System.out.println("Received notification:"); - try { - Enumeration propertyNames = notif.getPropertyNames(); - while (propertyNames.hasMoreElements()) { - String propertyName = (String) propertyNames.nextElement(); - System.out.format(" %s: %s%n", propertyName, notif.getObjectProperty(propertyName)); - } - } - catch (JMSException e) { - } - System.out.println("------------------------"); - } - }); - - // Step 7. Start the Connection to allow the consumers to receive messages - connection.start(); - - // Step 8. Create a JMS Message Consumer on the queue - MessageConsumer consumer = session.createConsumer(queue); - - // Step 9. Close the consumer - consumer.close(); - - // Step 10. Try to create a connection with unknown user - try { - cf.createConnection("not.a.valid.user", "not.a.valid.password"); - } - catch (JMSException e) { - } - - // sleep a little bit to be sure to receive the notification for the security - // authentication violation before leaving the example - Thread.sleep(2000); - } - finally { - // Step 11. Be sure to close the resources! - 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/management-notifications/src/main/resources/activemq/server0/artemis-roles.properties ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/management-notifications/src/main/resources/activemq/server0/artemis-roles.properties b/examples/broker-features/standard/management-notifications/src/main/resources/activemq/server0/artemis-roles.properties deleted file mode 100644 index 4e2d44c..0000000 --- a/examples/broker-features/standard/management-notifications/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/management-notifications/src/main/resources/activemq/server0/artemis-users.properties ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/management-notifications/src/main/resources/activemq/server0/artemis-users.properties b/examples/broker-features/standard/management-notifications/src/main/resources/activemq/server0/artemis-users.properties deleted file mode 100644 index 4e2d44c..0000000 --- a/examples/broker-features/standard/management-notifications/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/management-notifications/src/main/resources/activemq/server0/broker.xml ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/management-notifications/src/main/resources/activemq/server0/broker.xml b/examples/broker-features/standard/management-notifications/src/main/resources/activemq/server0/broker.xml deleted file mode 100644 index 2c97901..0000000 --- a/examples/broker-features/standard/management-notifications/src/main/resources/activemq/server0/broker.xml +++ /dev/null @@ -1,81 +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 ../../../../src/schema/artemis-server.xsd"> - - <jms xmlns="urn:activemq:jms"> - <!--the queue used by the example--> - <queue name="exampleQueue"/> - - <!--the notifications topic used by the example--> - <topic name="notificationsTopic"/> - </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> - - - <management-notification-address>jms.topic.notificationsTopic</management-notification-address> - - <!-- Netty standard TCP acceptor --> - <acceptors> - <acceptor name="netty">tcp://localhost:61616</acceptor> - </acceptors> - - <!-- Other configs --> - - <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 for notification queue--> - <security-setting match="jms.topic.notificationsTopic"> - <permission type="consume" roles="guest"/> - <permission type="createNonDurableQueue" roles="guest"/> - <permission type="deleteNonDurableQueue" roles="guest"/> - </security-setting> - - <!-- security settings for JMS temporary queue --> - <security-setting match="queuetempjms.*"> - <permission type="createNonDurableQueue" roles="guest"/> - <permission type="deleteNonDurableQueue" roles="guest"/> - <permission type="consume" roles="guest"/> - <permission type="send" roles="guest"/> - </security-setting> - </security-settings> - - </core> -</configuration> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6b17d966/examples/broker-features/standard/management-notifications/src/main/resources/jndi.properties ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/management-notifications/src/main/resources/jndi.properties b/examples/broker-features/standard/management-notifications/src/main/resources/jndi.properties deleted file mode 100644 index 2582245..0000000 --- a/examples/broker-features/standard/management-notifications/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 -topic.topic/notificationsTopic=notificationsTopic http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6b17d966/examples/broker-features/standard/management/pom.xml ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/management/pom.xml b/examples/broker-features/standard/management/pom.xml deleted file mode 100644 index cd006e5..0000000 --- a/examples/broker-features/standard/management/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>management</artifactId> - <packaging>jar</packaging> - <name>ActiveMQ Artemis JMS Management 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.ManagementExample</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>management</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/management/readme.html ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/management/readme.html b/examples/broker-features/standard/management/readme.html deleted file mode 100644 index 30057ba..0000000 --- a/examples/broker-features/standard/management/readme.html +++ /dev/null @@ -1,208 +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 Management 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>Management Example</h1> - <p>This example shows how to manage ActiveMQ Artemis using JMS Messages to invoke management operations on the server.</a></p> - <p>To manage ActiveMQ Artemis using JMX, see the <a href="../jmx/readme.html">JMX</a> example.</p> - - <h2>Example configuration</h2> - - <p>ActiveMQ Artemis can be managed by sending JMS messages with specific properties to its <em>management</em> queue.</p> - </p>By default, the management name is called <code>activemq.management</code> but this can be configured in <a href="server0/broker.xml">broker.xml</a> - <pre class="prettyprint"> - <code><management-address>activemq.management</management-address></code> - </pre> - - <p>The management queue requires a "special" user permission <code>manage</code> to be able to receive management messages. - This is also configured in <a href="server0/broker.xml">broker.xml</a></p> - <pre class="prettyprint"> - <code><security-setting match="activemq.management"> - <permission type="manage" roles="guest" /> - </security-setting></code> - </pre> - - <h2>Example step-by-step</h2> - <p><em>To run the example, simply type <code>mvn verify -Pexample</code> from this directory</em></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 its properties from <a href="server0/client-jndi.properties">client-jndi.properties</a></li> - <pre class="prettyprint"> - <code>InitialContext initialContext = getContext(0);</code> - </pre> - - <li>We look up the JMS queue object from JNDI</li> - <pre class="prettyprint"> - <code>Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");</code> - </pre> - - <li>We look up the JMS connection factory object from JNDI</li> - <pre class="prettyprint"> - <code>ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");</code> - </pre> - - <li>We create a JMS connection</li> - <pre class="prettyprint"> - <code>connection = cf.createConnection();</code> - </pre> - - <li>We create a JMS session. The session is created as non transacted and will auto acknowledge messages.</li> - <pre class="prettyprint"> - <code>Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);</code> - </pre> - - <li>We create a JMS message producer on the session. This will be used to send the messages.</li> - <pre class="prettyprint"> - <code>MessageProducer messageProducer = session.createProducer(topic);</code> - </pre> - - <li>We create a JMS text message that we are going to send.</li> - <pre class="prettyprint"> - <code>TextMessage message = session.createTextMessage("This is a text message");</code> - </pre> - - <li>We send message to the queue</li> - <pre class="prettyprint"> - <code>messageProducer.send(message);</code> - </pre> - - <p><em>Now that we have a message in the queue, we will manage the queue by retrieving the number of messages in the queue - (i.e. 1) and by removing the message which has been sent in step 8.</em></p> - - <li>We create the JMS management queue. This is a <em>special</em> queue which is not looked up from JNDI but instantiated directly</li> - <pre class="prettyprint"> - <code>Queue managementQueue = new ActiveMQQueue("activemq.management", "activemq.management");</code> - </pre> - - <li>We create a <code>QueueRequestor</code> to send messages to the management queue and receive replies (see <a href="../queue-requestor/readme.html">queue-requestor example</a>)</li> - <pre class="prettyprint"> - <code>QueueRequestor requestor = new QueueRequestor(session, managementQueue);</code> - </pre> - - <li>We start the connection to receive replies on the requestor</li> - <pre class="prettyprint"> - <code>connection.start()</code> - </pre> - - <li>We create a JMS message which will be used as a <em>management</em> message</li> - <pre class="prettyprint"> - <code>Message m = session.createMessage();</code> - </pre> - - <li>a <em>management</em> message has well-defined properties that ActiveMQ Artemis server needs to know to perform management operations.<br /> - We use a helper class <code>JMSManagementHelper</code> to fill these properties: - <ul> - <li>The name of the resource to manage <code>jms.queue.exampleQueue</code> - (i.e. <code>jms.queue</code> followed by the name of the queue as defined in <a href="server0/activemq-jms.xml">activemq-jms.xml</a>)</li> - <li>In our case, the name of the attribute to retrieve <code>MessageCount</code></li> - </ul> - </li> - <pre class="prettyprint"> - <code>JMSManagementHelper.putAttribute(m, "jms.queue.exampleQueue", "MessageCount");</code> - </pre> - - <li>We send the <em>management</em> message using the requestor and wait for a reply</li> - <pre class="prettyprint"> - <code>Message reply = requestor.request(m);</code> - </pre> - - <li>We use a helper class <code>JMSManagementHelper</code> to retrieve the result from the reply message: - <pre class="prettyprint"> - <code>int messageCount = (Integer)JMSManagementHelper.getResult(reply); - System.out.println(queue.getQueueName() + " contains " + messageCount + " messages");</code> - </pre> - - <li>We create another JMS message to use as a management message</li> - <pre class="prettyprint"> - <code>m = session.createMessage();</code> - </pre> - - <li>This time, we fill the <em>management</em> message with properties to <em>invoke</em> a management operation on the queue - <ul> - <li>the name of the resource <code>jms.queue.exampleQueue</code></li> - <li>the name of the management operation <code>removeMessage</code></li> - <li>any parameters required to invoke the management operations (in our case, the JMS Message ID of the message sent in step 8)</li> - </ul> - </li> - <pre class="prettyprint"> - <code>JMSManagementHelper.putOperationInvocation(m, "jms.queue.exampleQueue", "removeMessage", message.getJMSMessageID());</code> - </pre> - - <li>Again, we use the requestor to send the management message and wait for a reply</li> - <pre class="prettyprint"> - <code>reply = requestor.request(m);</code> - </pre> - - <li>We use the helper class to check that the operation was successfully invoked on the server</li> - <pre class="prettyprint"> - <code>boolean success = JMSManagementHelper.hasOperationSucceeded(reply); - System.out.println("operation invocation has succeeded: " + success);</code> - </pre> - - <li>We use a helper class <code>JMSManagementHelper</code> to retrieve the result from the reply message: - (in our case, the <code>removeMessage</code> method returns a boolean)</li> - <pre class="prettyprint"> - <code>boolean messageRemoved = (Boolean)JMSManagementHelper.getResult(reply); - System.out.println("message has been removed: " + messageRemoved);</code> - </pre> - - <p><em>We will now consume the message from the queue but there will be none: the message sent at step 8 was removed by the management operation</em></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 try to receive a message from the queue. Since there is none, the call will timeout after 5000ms and messageReceived will be null - </li> - <pre class="prettyprint"> - <code>TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000); - System.out.println("Received message: " + messageReceived);</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#management.jms">Using Management Via JMS chapter</a></li> - </ul> - </body> -</html> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6b17d966/examples/broker-features/standard/management/src/main/java/org/apache/activemq/artemis/jms/example/ManagementExample.java ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/management/src/main/java/org/apache/activemq/artemis/jms/example/ManagementExample.java b/examples/broker-features/standard/management/src/main/java/org/apache/activemq/artemis/jms/example/ManagementExample.java deleted file mode 100644 index 8c780c3..0000000 --- a/examples/broker-features/standard/management/src/main/java/org/apache/activemq/artemis/jms/example/ManagementExample.java +++ /dev/null @@ -1,133 +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.Message; -import javax.jms.MessageConsumer; -import javax.jms.MessageProducer; -import javax.jms.Queue; -import javax.jms.QueueConnection; -import javax.jms.QueueConnectionFactory; -import javax.jms.QueueRequestor; -import javax.jms.QueueSession; -import javax.jms.Session; -import javax.jms.TextMessage; -import javax.naming.InitialContext; - -import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; -import org.apache.activemq.artemis.api.jms.management.JMSManagementHelper; - -/** - * An example that shows how to manage ActiveMQ Artemis using JMS messages. - */ -public class ManagementExample { - - public static void main(final String[] args) throws Exception { - QueueConnection connection = null; - InitialContext initialContext = null; - try { - // Step 1. Create an initial context to perform the JNDI lookup. - initialContext = new InitialContext(); - - // Step 2. Perfom a lookup on the queue - Queue queue = (Queue) initialContext.lookup("queue/exampleQueue"); - - // Step 3. Perform a lookup on the Connection Factory - QueueConnectionFactory cf = (QueueConnectionFactory) initialContext.lookup("ConnectionFactory"); - - // Step 4.Create a JMS Connection - connection = cf.createQueueConnection(); - - // Step 5. Create a JMS Session - QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); - - // Step 6. Create a JMS Message Producer - MessageProducer producer = session.createProducer(queue); - - // Step 7. Create a Text Message - TextMessage message = session.createTextMessage("This is a text message"); - System.out.println("Sent message: " + message.getText()); - - // Step 8. Send the Message - producer.send(message); - - // Step 9. create the JMS management queue. - // It is a "special" queue and it is not looked up from JNDI but constructed directly - Queue managementQueue = ActiveMQJMSClient.createQueue("activemq.management"); - - // Step 10. Create a QueueRequestor for the management queue (see queue-requestor example) - QueueRequestor requestor = new QueueRequestor(session, managementQueue); - - // Step 11. Start the Connection to allow the queue requestor to receive replies - connection.start(); - - // Step 12. Create a JMS message which is used to send a management message - Message m = session.createMessage(); - - // Step 13. Use a helper class to fill the JMS message with management information: - // * the name of the resource to manage - // * in this case, we want to retrieve the value of the messageCount of the queue - JMSManagementHelper.putAttribute(m, "jms.queue.exampleQueue", "messageCount"); - - // Step 14. Use the requestor to send the request and wait for the reply - Message reply = requestor.request(m); - - // Step 15. Use a helper class to retrieve the operation result - int messageCount = (Integer) JMSManagementHelper.getResult(reply); - System.out.println(queue.getQueueName() + " contains " + messageCount + " messages"); - - // Step 16. Create another JMS message to use as a management message - m = session.createMessage(); - - // Step 17. Use a helper class to fill the JMS message with management information: - // * the object name of the resource to manage (i.e. the queue) - // * in this case, we want to call the "removeMessage" operation with the JMS MessageID - // of the message sent to the queue in step 8. - JMSManagementHelper.putOperationInvocation(m, "jms.queue.exampleQueue", "removeMessage", message.getJMSMessageID()); - - // Step 18 Use the requestor to send the request and wait for the reply - reply = requestor.request(m); - - // Step 19. Use a helper class to check that the operation has succeeded - boolean success = JMSManagementHelper.hasOperationSucceeded(reply); - System.out.println("operation invocation has succeeded: " + success); - - // Step 20. Use a helper class to retrieve the operation result - // in that case, a boolean which is true if the message was removed, false else - boolean messageRemoved = (Boolean) JMSManagementHelper.getResult(reply); - System.out.println("message has been removed: " + messageRemoved); - - // Step 21. Create a JMS Message Consumer on the queue - MessageConsumer messageConsumer = session.createConsumer(queue); - - // Step 22. Trying to receive a message. Since the only message in the queue was removed by a management - // operation, - // there is none to consume. The call will timeout after 5000ms and messageReceived will be null - TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000); - System.out.println("Received message: " + messageReceived); - } - finally { - // Step 23. Be sure to close the resources! - 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/management/src/main/resources/activemq/server0/artemis-roles.properties ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/management/src/main/resources/activemq/server0/artemis-roles.properties b/examples/broker-features/standard/management/src/main/resources/activemq/server0/artemis-roles.properties deleted file mode 100644 index 4e2d44c..0000000 --- a/examples/broker-features/standard/management/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/management/src/main/resources/activemq/server0/artemis-users.properties ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/management/src/main/resources/activemq/server0/artemis-users.properties b/examples/broker-features/standard/management/src/main/resources/activemq/server0/artemis-users.properties deleted file mode 100644 index 4e2d44c..0000000 --- a/examples/broker-features/standard/management/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/management/src/main/resources/activemq/server0/broker.xml ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/management/src/main/resources/activemq/server0/broker.xml b/examples/broker-features/standard/management/src/main/resources/activemq/server0/broker.xml deleted file mode 100644 index 36eec30..0000000 --- a/examples/broker-features/standard/management/src/main/resources/activemq/server0/broker.xml +++ /dev/null @@ -1,76 +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> - - - <management-address>jms.queue.activemq.management</management-address> - - <!-- Netty standard TCP acceptor --> - <acceptors> - <acceptor name="netty">tcp://localhost:61616</acceptor> - </acceptors> - - <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 for management queue--> - <security-setting match="jms.queue.activemq.management"> - <permission type="manage" roles="guest"/> - </security-setting> - - <!-- security settings for JMS temporary queue --> - <security-setting match="jms.tempqueue.#"> - <permission type="createNonDurableQueue" roles="guest"/> - <permission type="deleteNonDurableQueue" roles="guest"/> - <permission type="consume" roles="guest"/> - <permission type="send" roles="guest"/> - </security-setting> - - </security-settings> - - </core> -</configuration> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6b17d966/examples/broker-features/standard/management/src/main/resources/jndi.properties ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/management/src/main/resources/jndi.properties b/examples/broker-features/standard/management/src/main/resources/jndi.properties deleted file mode 100644 index 93537c4..0000000 --- a/examples/broker-features/standard/management/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/message-counters/pom.xml ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/message-counters/pom.xml b/examples/broker-features/standard/message-counters/pom.xml deleted file mode 100644 index e2db0ac..0000000 --- a/examples/broker-features/standard/message-counters/pom.xml +++ /dev/null @@ -1,116 +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>message-counters</artifactId> - <packaging>jar</packaging> - <name>ActiveMQ Artemis JMS Message Counter Example</name> - - <properties> - <activemq.basedir>${project.basedir}/../../../..</activemq.basedir> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-server</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-jms-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> - <javaOptions>-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=3001 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false - </javaOptions> - </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.MessageCounterExample</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>message-counters</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - </plugin> - </plugins> - </build> - -</project>