http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/bridge/readme.html ---------------------------------------------------------------------- diff --git a/examples/jms/bridge/readme.html b/examples/jms/bridge/readme.html deleted file mode 100644 index a9440c7..0000000 --- a/examples/jms/bridge/readme.html +++ /dev/null @@ -1,74 +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 Core Bridge 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>Core Bridge Example</h1> - <pre>To run the example, simply type <b>mvn verify</b> from this directory, <br>or <b>mvn -PnoServer verify</b> if you want to start and create the server manually.</pre> - - <p>This example demonstrates a core bridge deployed on one server, which consumes messages from a - local queue and forwards them to an address on a second server.</p> - - <p>Core bridges are used to create message flows between any two ActiveMQ Artemis servers which are remotely separated. - Core bridges are resilient and will cope with temporary connection failure allowing them to be an ideal - choice for forwarding over unreliable connections, e.g. a WAN.</p> - <p>They can also be configured with an optional filter expression, and will only forward messages that - match that filter.</p> - <p>Furthermore they can be configured to use an optional Transformer class. A user-defined Transformer class - can be specified which is called at forwarding time. This gives the user the opportunity to transform - the message in some ways, e.g. changing its properties or body</p> - <p>ActiveMQ Artemis also includes a <b>JMS Bridge</b>. This is similar to a core bridge, but uses the JMS API - and can be used to bridge between any two JMS 1.1 compliant messaging systems. The core bridge is limited to bridging - between ActiveMQ Artemis instances, but may provide better performance than the JMS bridge. The JMS bridge is covered in - a separate example.</p> - <p>For more information on bridges, please see the ActiveMQ Artemis user manual.</p> - - <p>In this example we will demonstrate a simple sausage factory for aardvarks.</p> - <p>We have a JMS queue on server 0 named <code>sausage-factory</code>, and we have a - JMS queue on server 1 named <code>mincing-machine</code></p> - <p>We want to forward any messages that are sent to the <code>sausage-factory</code> queue on server 0, to the <code>mincing-machine</code> - on server 1.</p> - <p>We only want to make aardvark sausages, so we only forward messages where the property "name" is set - to "aardvark". It is known that other things, such are Sasquatches are also sent to the <code>sausage-factory</code> and we - want to reject those.</p> - <p>Moreover it is known that Aardvarks normally wear blue hats, and it's important that we only make sausages using - Aardvarks with green hats, so on the way we are going transform the property "hat" from "green" to "blue".</p> - <p>Here's a snippet from <code>broker.xml</code> showing the bridge configuration</p> - <pre class="prettyprint"> - <code> - <bridge name="my-bridge"> - <queue-name>jms.queue.sausage-factory</queue-name> - <forwarding-address>jms.queue.mincing-machine</forwarding-address> - <filter string="name='aardvark'"/> - <transformer-class-name>org.apache.activemq.artemis.jms.example.HatColourChangeTransformer</transformer-class-name> - <reconnect-attempts>-1</reconnect-attempts> - <static-connectors> - <connector-ref>remote-connector</connector-ref> - </static-connectors> - </bridge> - </code> - </pre> - </body> -</html>
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/bridge/src/main/java/org/apache/activemq/artemis/jms/example/BridgeExample.java ---------------------------------------------------------------------- diff --git a/examples/jms/bridge/src/main/java/org/apache/activemq/artemis/jms/example/BridgeExample.java b/examples/jms/bridge/src/main/java/org/apache/activemq/artemis/jms/example/BridgeExample.java deleted file mode 100644 index 0fa17c2..0000000 --- a/examples/jms/bridge/src/main/java/org/apache/activemq/artemis/jms/example/BridgeExample.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.activemq.artemis.jms.example; - -import javax.jms.Connection; -import javax.jms.ConnectionFactory; -import javax.jms.Message; -import javax.jms.MessageConsumer; -import javax.jms.MessageProducer; -import javax.jms.Queue; -import javax.jms.Session; -import javax.naming.InitialContext; -import java.util.Hashtable; - -/** - * This example demonstrates a core bridge set-up between two nodes, consuming messages from a queue - * on one node and forwarding them to an address on the second node. - */ -public class BridgeExample { - - public static void main(final String[] args) throws Exception { - Connection connection0 = null; - - Connection connection1 = null; - - InitialContext ic0 = null; - - InitialContext ic1 = null; - - try { - // Step 1 - we create an initial context for looking up JNDI on node 0 - - Hashtable<String, Object> properties = new Hashtable<String, Object>(); - properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); - properties.put("connectionFactory.ConnectionFactory", "tcp://127.0.0.1:61616"); - properties.put("queue.queue/sausage-factory", "sausage-factory"); - ic0 = new InitialContext(properties); - - // Step 2 - we look up the sausage-factory queue from node 0 - - Queue sausageFactory = (Queue) ic0.lookup("queue/sausage-factory"); - - // Step 3 - we look up a JMS ConnectionFactory object from node 0 - - ConnectionFactory cf0 = (ConnectionFactory) ic0.lookup("ConnectionFactory"); - - // Step 4 - we create an initial context for looking up JNDI on node 1 - - properties = new Hashtable<String, Object>(); - properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); - properties.put("connectionFactory.ConnectionFactory", "tcp://127.0.0.1:61617"); - properties.put("queue.queue/mincing-machine", "mincing-machine"); - ic1 = new InitialContext(properties); - - // Step 5 - we look up the mincing-machine queue on node 1 - - Queue mincingMachine = (Queue) ic1.lookup("queue/mincing-machine"); - - // Step 6 - we look up a JMS ConnectionFactory object from node 1 - - ConnectionFactory cf1 = (ConnectionFactory) ic1.lookup("ConnectionFactory"); - - // Step 7. We create a JMS Connection connection0 which is a connection to server 0 - - connection0 = cf0.createConnection(); - - // Step 8. We create a JMS Connection connection1 which is a connection to server 1 - connection1 = cf1.createConnection(); - - // Step 9. We create a JMS Session on server 0 - - Session session0 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE); - - // Step 10. We create a JMS Session on server 1 - - Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE); - - // Step 10. We start the connection to ensure delivery occurs on them - - connection1.start(); - - // Step 11. We create JMS MessageConsumer object - MessageConsumer consumer = session1.createConsumer(mincingMachine); - - // Step 12. We create a JMS MessageProducer object on server 0 - MessageProducer producer = session0.createProducer(sausageFactory); - - // Step 13. We create and send a message representing an aardvark with a green hat to the sausage-factory - // on node 0 - Message message = session0.createMessage(); - - message.setStringProperty("name", "aardvark"); - - message.setStringProperty("hat", "green"); - - producer.send(message); - - System.out.println("Sent " + message.getStringProperty("name") + - " message with " + - message.getStringProperty("hat") + - " hat to sausage-factory on node 0"); - - // Step 14 - we successfully receive the aardvark message from the mincing-machine one node 1. The aardvark's - // hat is now blue since it has been transformed! - - Message receivedMessage = consumer.receive(5000); - - System.out.println("Received " + receivedMessage.getStringProperty("name") + - " message with " + - receivedMessage.getStringProperty("hat") + - " hat from mincing-machine on node 1"); - - // Step 13. We create and send another message, this time representing a sasquatch with a mauve hat to the - // sausage-factory on node 0. This won't be bridged to the mincing-machine since we only want aardvarks, not - // sasquatches - - message = session0.createMessage(); - - message.setStringProperty("name", "sasquatch"); - - message.setStringProperty("hat", "mauve"); - - producer.send(message); - - System.out.println("Sent " + message.getStringProperty("name") + - " message with " + - message.getStringProperty("hat") + - " hat to sausage-factory on node 0"); - - // Step 14. We don't receive the message since it has not been bridged. - - receivedMessage = consumer.receive(1000); - - if (receivedMessage == null) { - System.out.println("Didn't receive that message from mincing-machine on node 1"); - } - else { - throw new IllegalStateException(); - } - } - finally { - // Step 15. Be sure to close our resources! - - if (connection0 != null) { - connection0.close(); - } - - if (connection1 != null) { - connection1.close(); - } - - if (ic0 != null) { - ic0.close(); - } - - if (ic1 != null) { - ic1.close(); - } - } - } -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/bridge/src/main/java/org/apache/activemq/artemis/jms/example/HatColourChangeTransformer.java ---------------------------------------------------------------------- diff --git a/examples/jms/bridge/src/main/java/org/apache/activemq/artemis/jms/example/HatColourChangeTransformer.java b/examples/jms/bridge/src/main/java/org/apache/activemq/artemis/jms/example/HatColourChangeTransformer.java deleted file mode 100644 index ae8cf39..0000000 --- a/examples/jms/bridge/src/main/java/org/apache/activemq/artemis/jms/example/HatColourChangeTransformer.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.activemq.artemis.jms.example; - -import org.apache.activemq.artemis.api.core.SimpleString; -import org.apache.activemq.artemis.core.server.ServerMessage; -import org.apache.activemq.artemis.core.server.cluster.Transformer; - -public class HatColourChangeTransformer implements Transformer { - - public ServerMessage transform(final ServerMessage message) { - SimpleString propName = new SimpleString("hat"); - - SimpleString oldProp = message.getSimpleStringProperty(propName); - - // System.out.println("Old hat colour is " + oldProp); - - // Change the colour - message.putStringProperty(propName, new SimpleString("blue")); - - return message; - } - -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/bridge/src/main/resources/activemq/server0/broker.xml ---------------------------------------------------------------------- diff --git a/examples/jms/bridge/src/main/resources/activemq/server0/broker.xml b/examples/jms/bridge/src/main/resources/activemq/server0/broker.xml deleted file mode 100644 index 250a851..0000000 --- a/examples/jms/bridge/src/main/resources/activemq/server0/broker.xml +++ /dev/null @@ -1,88 +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="sausage-factory"/> - </jms> - - <core xmlns="urn:activemq:core"> - - <bindings-directory>${data.dir}/server0/data/messaging/bindings</bindings-directory> - - <journal-directory>${data.dir}/server0/data/messaging/journal</journal-directory> - - <large-messages-directory>${data.dir}/server0/data/messaging/largemessages</large-messages-directory> - - <paging-directory>${data.dir}/server0/data/messaging/paging</paging-directory> - - <!-- Connectors --> - <connectors> - <!-- Connector to the other node --> - <connector name="remote-connector">tcp://localhost:61617</connector> - </connectors> - - <!-- Acceptors --> - <acceptors> - <acceptor name="netty-acceptor">tcp://localhost:61616</acceptor> - </acceptors> - - <!-- We need to create a core queue for the JMS queue explicitly because the bridge will be deployed - before the JMS queue is deployed, so the first time, it otherwise won't find the queue --> - <queues> - <queue name="jms.queue.sausage-factory"> - <address>jms.queue.sausage-factory</address> - </queue> - </queues> - - <!-- We set-up a bridge that forwards from a queue on this node to an address on another node. - We specify a filter with the bridge, and a transformer too. The filter and transformer are optional --> - <bridges> - <bridge name="my-bridge"> - <queue-name>jms.queue.sausage-factory</queue-name> - <forwarding-address>jms.queue.mincing-machine</forwarding-address> - <filter string="name='aardvark'"/> - <transformer-class-name>org.apache.activemq.artemis.jms.example.HatColourChangeTransformer</transformer-class-name> - <reconnect-attempts>-1</reconnect-attempts> - <static-connectors> - <connector-ref>remote-connector</connector-ref> - </static-connectors> - </bridge> - </bridges> - - <!-- Other config --> - - <security-settings> - <!--security for example queue--> - <security-setting match="jms.queue.#"> - <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> - </core> - -</configuration> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/bridge/src/main/resources/activemq/server1/broker.xml ---------------------------------------------------------------------- diff --git a/examples/jms/bridge/src/main/resources/activemq/server1/broker.xml b/examples/jms/bridge/src/main/resources/activemq/server1/broker.xml deleted file mode 100644 index 516f179..0000000 --- a/examples/jms/bridge/src/main/resources/activemq/server1/broker.xml +++ /dev/null @@ -1,59 +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="mincing-machine"/> - </jms> - <core xmlns="urn:activemq:core"> - - <bindings-directory>${data.dir}/server1/data/messaging/bindings</bindings-directory> - - <journal-directory>${data.dir}/server1/data/messaging/journal</journal-directory> - - <large-messages-directory>${data.dir}/server1/data/messaging/largemessages</large-messages-directory> - - <paging-directory>${data.dir}/server1/data/messaging/paging</paging-directory> - - <!-- Acceptors --> - <acceptors> - <acceptor name="netty-acceptor">tcp://localhost:61617</acceptor> - </acceptors> - - <!-- Other config --> - - <security-settings> - <!--security for example queue--> - <security-setting match="jms.queue.#"> - <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> - </core> - -</configuration> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/browser/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/browser/pom.xml b/examples/jms/browser/pom.xml deleted file mode 100644 index 8cbd2d7..0000000 --- a/examples/jms/browser/pom.xml +++ /dev/null @@ -1,119 +0,0 @@ -<?xml version='1.0'?> -<!-- -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. ---> - -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.apache.activemq.examples.jms</groupId> - <artifactId>jms-examples</artifactId> - <version>1.0.1-SNAPSHOT</version> - </parent> - - <artifactId>browser</artifactId> - <packaging>jar</packaging> - <name>ActiveMQ Artemis JMS Browser Example</name> - - <properties> - <activemq.basedir>${project.basedir}/../../..</activemq.basedir> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-jms-client</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - - <profiles> - <profile> - <!-- specify -PnoServer if you don't want to start the server --> - <id>noServer</id> - <properties> - <noServer>true</noServer> - </properties> - </profile> - </profiles> - <build> - <plugins> - <plugin> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-maven-plugin</artifactId> - <executions> - <execution> - <id>create</id> - <phase>verify</phase> - <configuration> - <ignore>${noServer}</ignore> - </configuration> - <goals> - <goal>create</goal> - </goals> - </execution> - <execution> - <id>start</id> - <goals> - <goal>cli</goal> - </goals> - <configuration> - <spawn>true</spawn> - <ignore>${noServer}</ignore> - <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.QueueBrowserExample</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>browser</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - </plugin> - </plugins> - </build> - -</project> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/browser/readme.html ---------------------------------------------------------------------- diff --git a/examples/jms/browser/readme.html b/examples/jms/browser/readme.html deleted file mode 100644 index 76f349f..0000000 --- a/examples/jms/browser/readme.html +++ /dev/null @@ -1,40 +0,0 @@ -<!-- -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. ---> - -<html> - <head> - <title>ActiveMQ Artemis JMS QueueBrowser Example</title> - <link rel="stylesheet" type="text/css" href="../common/common.css" /> - <link rel="stylesheet" type="text/css" href="../common/prettify.css" /> - <script type="text/javascript" src="../common/prettify.js"></script> - </head> - <body onload="prettyPrint()"> - <h1>JMS QueueBrowser 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 use a JMS <a href="http://java.sun.com/javaee/5/docs/api/javax/jms/QueueBrowser.html">QueueBrowser</a> with ActiveMQ Artemis.<br /> - Queues are a standard part of JMS, please consult the JMS 1.1 specification for full details.<br /> - A QueueBrowser is used to look at messages on the queue without removing them. - It can scan the entire content of a queue or only messages matching a message selector.</p> - <p> - The example will send 2 messages on a queue, use a QueueBrowser to browse - the queue (looking at the message without removing them) and finally consume the 2 messages - </p> - </body> -</html> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/browser/src/main/java/org/apache/activemq/artemis/jms/example/QueueBrowserExample.java ---------------------------------------------------------------------- diff --git a/examples/jms/browser/src/main/java/org/apache/activemq/artemis/jms/example/QueueBrowserExample.java b/examples/jms/browser/src/main/java/org/apache/activemq/artemis/jms/example/QueueBrowserExample.java deleted file mode 100644 index 1c9db3b..0000000 --- a/examples/jms/browser/src/main/java/org/apache/activemq/artemis/jms/example/QueueBrowserExample.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.activemq.artemis.jms.example; - -import javax.jms.Connection; -import javax.jms.ConnectionFactory; -import javax.jms.MessageConsumer; -import javax.jms.MessageProducer; -import javax.jms.Queue; -import javax.jms.QueueBrowser; -import javax.jms.Session; -import javax.jms.TextMessage; -import javax.naming.InitialContext; -import java.util.Enumeration; - -/** - * A simple example which shows how to use a QueueBrowser to look at messages of a queue without removing them from the queue - */ -public class QueueBrowserExample { - - 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. Perfom a lookup on the queue - Queue queue = (Queue) initialContext.lookup("queue/exampleQueue"); - - // Step 3. Perform a lookup on the Connection Factory - // you could alternatively instantiate the connection directly - // ConnectionFactory cf = new ActiveMQConnectionFactory(); // this would accept the broker URI as well - ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("ConnectionFactory"); - - // Step 4. Create a JMS Connection - connection = cf.createConnection(); - - // Step 5. Create a JMS Session - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - - // Step 6. Create a JMS Message Producer - MessageProducer producer = session.createProducer(queue); - - // Step 7. Create 2 Text Messages - TextMessage message_1 = session.createTextMessage("this is the 1st message"); - TextMessage message_2 = session.createTextMessage("this is the 2nd message"); - - // Step 8. Send the Message - producer.send(message_1); - producer.send(message_2); - - // Step 9. Create the JMS QueueBrowser - QueueBrowser browser = session.createBrowser(queue); - - // Step 10. Browse the messages on the queue - // Browsing a queue does not remove the messages from the queue - Enumeration messageEnum = browser.getEnumeration(); - while (messageEnum.hasMoreElements()) { - TextMessage message = (TextMessage) messageEnum.nextElement(); - System.out.println("Browsing: " + message.getText()); - } - - // Step 11. Close the browser - browser.close(); - - // Step 12. Create a JMS Message Consumer - MessageConsumer messageConsumer = session.createConsumer(queue); - - // Step 13. Start the Connection - connection.start(); - - // Step 14. Receive the 2 messages - TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000); - System.out.println("Received message: " + messageReceived.getText()); - messageReceived = (TextMessage) messageConsumer.receive(5000); - System.out.println("Received message: " + messageReceived.getText()); - } - finally { - // Step 15. Be sure to close our JMS resources! - if (initialContext != null) { - initialContext.close(); - } - if (connection != null) { - connection.close(); - } - } - } -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/browser/src/main/resources/jndi.properties ---------------------------------------------------------------------- diff --git a/examples/jms/browser/src/main/resources/jndi.properties b/examples/jms/browser/src/main/resources/jndi.properties deleted file mode 100644 index 93537c4..0000000 --- a/examples/jms/browser/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/21bf4406/examples/jms/client-kickoff/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/client-kickoff/pom.xml b/examples/jms/client-kickoff/pom.xml deleted file mode 100644 index a07eb35..0000000 --- a/examples/jms/client-kickoff/pom.xml +++ /dev/null @@ -1,122 +0,0 @@ -<?xml version='1.0'?> -<!-- -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. ---> - -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.apache.activemq.examples.jms</groupId> - <artifactId>jms-examples</artifactId> - <version>1.0.1-SNAPSHOT</version> - </parent> - - <artifactId>client-kickoff</artifactId> - <packaging>jar</packaging> - <name>ActiveMQ Artemis JMS Kick Off Example</name> - - <properties> - <activemq.basedir>${project.basedir}/../../..</activemq.basedir> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-jms-client</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - - <profiles> - <profile> - <!-- specify -PnoServer if you don't want to start the server --> - <id>noServer</id> - <properties> - <noServer>true</noServer> - </properties> - </profile> - </profiles> - <build> - <plugins> - <plugin> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-maven-plugin</artifactId> - <executions> - <execution> - <id>create</id> - <goals> - <goal>create</goal> - </goals> - <configuration> - <ignore>${noServer}</ignore> - <!-- options used for JMX on the example --> - <javaOptions>-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=3000 - -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.ClientKickoffExample</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>client-kickoff</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - </plugin> - </plugins> - </build> - -</project> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/client-kickoff/readme.html ---------------------------------------------------------------------- diff --git a/examples/jms/client-kickoff/readme.html b/examples/jms/client-kickoff/readme.html deleted file mode 100644 index 064f7fb..0000000 --- a/examples/jms/client-kickoff/readme.html +++ /dev/null @@ -1,54 +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 Client Kickoff 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>Client Kickoff 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 kick off a client connected to ActiveMQ - using <a href="http://java.sun.com/javase/technologies/core/mntr-mgmt/javamanagement/">JMX</a></p> - - <p>The example will connect to ActiveMQ Artemis. Using JMX, we will list the remote addresses connected to the - server and close the corresponding connections. The client will be kicked off from ActiveMQ Artemis receiving - an exception that its JMS connection was interrupted.</p> - - <h2>Example configuration</h2> - - <p>ActiveMQ Artemis exposes its managed resources by default on the platform MBeanServer.</p> - <p>To access this MBeanServer remotely, the Java Virtual machine must be started with system properties: - <pre class="prettyprint"> - <code>-Dcom.sun.management.jmxremote - -Dcom.sun.management.jmxremote.port=3000 - -Dcom.sun.management.jmxremote.ssl=false - -Dcom.sun.management.jmxremote.authenticate=false</code> - </pre> - <p>These properties are explained in the Java 5 <a href="http://java.sun.com/j2se/1.5.0/docs/guide/management/agent.html#remote">Management guide</a> - (please note that for this example, we will disable user authentication for simplicity).</p> - <p>With these properties, ActiveMQ Artemis server will be manageable remotely using standard JMX URL on port <code>3000</code>.</p> - </p> - </body> -</html> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/client-kickoff/src/main/java/org/apache/activemq/artemis/jms/example/ClientKickoffExample.java ---------------------------------------------------------------------- diff --git a/examples/jms/client-kickoff/src/main/java/org/apache/activemq/artemis/jms/example/ClientKickoffExample.java b/examples/jms/client-kickoff/src/main/java/org/apache/activemq/artemis/jms/example/ClientKickoffExample.java deleted file mode 100644 index a0b3a7e..0000000 --- a/examples/jms/client-kickoff/src/main/java/org/apache/activemq/artemis/jms/example/ClientKickoffExample.java +++ /dev/null @@ -1,107 +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.ExceptionListener; -import javax.jms.JMSException; -import javax.jms.QueueConnection; -import javax.jms.QueueConnectionFactory; -import javax.management.MBeanServerConnection; -import javax.management.MBeanServerInvocationHandler; -import javax.management.ObjectName; -import javax.management.remote.JMXConnector; -import javax.management.remote.JMXConnectorFactory; -import javax.management.remote.JMXServiceURL; -import javax.naming.InitialContext; -import java.lang.Exception; -import java.util.HashMap; -import java.util.concurrent.atomic.AtomicReference; - -import org.apache.activemq.artemis.api.core.management.ActiveMQServerControl; -import org.apache.activemq.artemis.api.core.management.ObjectNameBuilder; - -/** - * An example that shows how to kick off a client connected to ActiveMQ Artemis by using JMX. - */ -public class ClientKickoffExample { - - private static final String JMX_URL = "service:jmx:rmi:///jndi/rmi://localhost:3000/jmxrmi"; - - 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. Perform a lookup on the Connection Factory - QueueConnectionFactory cf = (QueueConnectionFactory) initialContext.lookup("ConnectionFactory"); - - // Step 3.Create a JMS Connection - connection = cf.createQueueConnection(); - - // Step 4. Set an exception listener on the connection to be notified after a problem occurred - final AtomicReference<JMSException> exception = new AtomicReference<JMSException>(); - connection.setExceptionListener(new ExceptionListener() { - @Override - public void onException(final JMSException e) { - exception.set(e); - } - }); - - // Step 5. We start the connection - connection.start(); - - // Step 6. Create an ActiveMQServerControlMBean proxy to manage the server - ObjectName on = ObjectNameBuilder.DEFAULT.getActiveMQServerObjectName(); - JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(JMX_URL), new HashMap<String, String>()); - MBeanServerConnection mbsc = connector.getMBeanServerConnection(); - ActiveMQServerControl serverControl = MBeanServerInvocationHandler.newProxyInstance(mbsc, on, ActiveMQServerControl.class, false); - - // Step 7. List the remote address connected to the server - System.out.println("List of remote addresses connected to the server:"); - System.out.println("----------------------------------"); - String[] remoteAddresses = serverControl.listRemoteAddresses(); - for (String remoteAddress : remoteAddresses) { - System.out.println(remoteAddress); - } - System.out.println("----------------------------------"); - - // Step 8. Close the connections for the 1st remote address and kickoff the client - serverControl.closeConnectionsForAddress(remoteAddresses[0]); - - // Sleep a little bit so that the stack trace from the server won't be - // mingled with the JMSException received on the ExceptionListener - Thread.sleep(1000); - - // Step 9. Display the exception received by the connection's ExceptionListener - System.err.println("\nException received from the server:"); - System.err.println("----------------------------------"); - exception.get().printStackTrace(); - System.err.println("----------------------------------"); - } - finally { - // Step 10. 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/21bf4406/examples/jms/client-kickoff/src/main/resources/activemq/server0/broker.xml ---------------------------------------------------------------------- diff --git a/examples/jms/client-kickoff/src/main/resources/activemq/server0/broker.xml b/examples/jms/client-kickoff/src/main/resources/activemq/server0/broker.xml deleted file mode 100644 index 3b5a465..0000000 --- a/examples/jms/client-kickoff/src/main/resources/activemq/server0/broker.xml +++ /dev/null @@ -1,47 +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"> - - </jms> - - <core xmlns="urn:activemq:core"> - - <bindings-directory>${data.dir:../data}/bindings</bindings-directory> - - <journal-directory>${data.dir:../data}/journal</journal-directory> - - <large-messages-directory>${data.dir:../data}/largemessages</large-messages-directory> - - <paging-directory>${data.dir:../data}/paging</paging-directory> - - <!-- true to expose ActiveMQ Artemis resources through JMX --> - <jmx-management-enabled>true</jmx-management-enabled> - - <!-- Acceptors --> - <acceptors> - <acceptor name="netty">tcp://localhost:61616</acceptor> - </acceptors> - </core> - -</configuration> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/client-kickoff/src/main/resources/jndi.properties ---------------------------------------------------------------------- diff --git a/examples/jms/client-kickoff/src/main/resources/jndi.properties b/examples/jms/client-kickoff/src/main/resources/jndi.properties deleted file mode 100644 index 5cbe72c..0000000 --- a/examples/jms/client-kickoff/src/main/resources/jndi.properties +++ /dev/null @@ -1,19 +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 http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/client-side-failoverlistener/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/client-side-failoverlistener/pom.xml b/examples/jms/client-side-failoverlistener/pom.xml deleted file mode 100644 index 4f5eaa5..0000000 --- a/examples/jms/client-side-failoverlistener/pom.xml +++ /dev/null @@ -1,109 +0,0 @@ -<?xml version='1.0'?> -<!-- -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. ---> - -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.apache.activemq.examples.jms</groupId> - <artifactId>jms-examples</artifactId> - <version>1.0.1-SNAPSHOT</version> - </parent> - - <artifactId>client-side-fileoverlistener</artifactId> - <packaging>jar</packaging> - <name>ActiveMQ Artemis JMS Client Side Failover listener Example</name> - - <properties> - <activemq.basedir>${project.basedir}/../../..</activemq.basedir> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-cli</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-jms-client</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-maven-plugin</artifactId> - <executions> - <execution> - <id>create0</id> - <goals> - <goal>create</goal> - </goals> - <configuration> - <instance>${basedir}/target/server0</instance> - <dataFolder>../shared</dataFolder> - <sharedStore>true</sharedStore> - <slave>false</slave> - <failoverOnShutdown>true</failoverOnShutdown> - </configuration> - </execution> - <execution> - <id>create1</id> - <goals> - <goal>create</goal> - </goals> - <configuration> - <instance>${basedir}/target/server1</instance> - <dataFolder>../shared</dataFolder> - <sharedStore>true</sharedStore> - <slave>true</slave> - <portOffset>1</portOffset> - </configuration> - </execution> - <execution> - <id>runClient</id> - <goals> - <goal>runClient</goal> - </goals> - <configuration> - <clientClass>org.apache.activemq.artemis.jms.example.ClientSideFailoverListerExample</clientClass> - <args> - <param>${basedir}/target/server0</param> - <param>${basedir}/target/server1</param> - </args> - </configuration> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>org.apache.activemq.examples.jms</groupId> - <artifactId>client-side-fileoverlistener</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - </plugin> - </plugins> - </build> - -</project> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/client-side-failoverlistener/readme.html ---------------------------------------------------------------------- diff --git a/examples/jms/client-side-failoverlistener/readme.html b/examples/jms/client-side-failoverlistener/readme.html deleted file mode 100644 index 9f71893..0000000 --- a/examples/jms/client-side-failoverlistener/readme.html +++ /dev/null @@ -1,37 +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 Client Side Failover Listener 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>Client Side Kickoff Example</h1> - <pre>To run the example, simply type <b>mvn verify</b> from this directory. This example will always spawn and stop multiple servers.</pre> - - <p>This example demonstrates how you can listen on failover event on the client side.</p> - - <p>In this example there are two nodes running in a cluster, both server will be running for start, - but after a while the first server will crash. This will trigger a fail-over event.</p> - - </body> -</html> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/client-side-failoverlistener/src/main/java/org/apache/activemq/artemis/jms/example/ClientSideFailoverListerExample.java ---------------------------------------------------------------------- diff --git a/examples/jms/client-side-failoverlistener/src/main/java/org/apache/activemq/artemis/jms/example/ClientSideFailoverListerExample.java b/examples/jms/client-side-failoverlistener/src/main/java/org/apache/activemq/artemis/jms/example/ClientSideFailoverListerExample.java deleted file mode 100644 index 4dcfd87..0000000 --- a/examples/jms/client-side-failoverlistener/src/main/java/org/apache/activemq/artemis/jms/example/ClientSideFailoverListerExample.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.activemq.artemis.jms.example; - -import org.apache.activemq.artemis.api.core.client.FailoverEventListener; -import org.apache.activemq.artemis.api.core.client.FailoverEventType; -import org.apache.activemq.artemis.jms.client.ActiveMQConnection; -import org.apache.activemq.artemis.util.ServerUtil; - -import javax.jms.Connection; -import javax.jms.ConnectionFactory; -import javax.jms.MessageConsumer; -import javax.jms.MessageProducer; -import javax.jms.Queue; -import javax.jms.Session; -import javax.jms.TextMessage; -import javax.naming.InitialContext; - -/** - * This example demonstrates how you can listen on failover event on the client side - * <p/> - * In this example there are two nodes running in a cluster, both server will be running for start, - * but after a while the first server will crash. This will trigger a fail-over event - */ -public class ClientSideFailoverListerExample { - - private static Process server0; - - private static Process server1; - - public static void main(final String[] args) throws Exception { - InitialContext initialContext = null; - - Connection connectionA = null; - - try { - server0 = ServerUtil.startServer(args[0], ClientSideFailoverListerExample.class.getSimpleName() + "0", 0, 5000); - server1 = ServerUtil.startServer(args[1], ClientSideFailoverListerExample.class.getSimpleName() + "1", 1, 0); - - // Step 1. Get an initial context for looking up JNDI from server 0 - initialContext = new InitialContext(); - - // Step 2. Look-up the JMS Queue object from JNDI - Queue queue = (Queue) initialContext.lookup("queue/exampleQueue"); - - // Step 3. Look-up a JMS Connection Factory object from JNDI on server 0 - ConnectionFactory connectionFactory = (ConnectionFactory) initialContext.lookup("ConnectionFactory"); - - // Step 4. We create 1 JMS connections from the same connection factory. - // Wait a little while to make sure broadcasts from all nodes have reached the client - Thread.sleep(5000); - connectionA = connectionFactory.createConnection(); - ((ActiveMQConnection) connectionA).setFailoverListener(new FailoverListenerImpl()); - - // Step 5. We create JMS Sessions - Session sessionA = connectionA.createSession(false, Session.AUTO_ACKNOWLEDGE); - - // Step 6. We create JMS MessageProducer objects on the sessions - MessageProducer producerA = sessionA.createProducer(queue); - - // Step 7. We send some messages on each producer - final int numMessages = 10; - - for (int i = 0; i < numMessages; i++) { - TextMessage messageA = sessionA.createTextMessage("A:This is text message " + i); - producerA.send(messageA); - System.out.println("Sent message: " + messageA.getText()); - - } - - // Step 8. We start the connection to consume messages - connectionA.start(); - - // Step 9. We consume messages from the session A, one at a time. - // We reached message no 5 the first server will crash - consume(sessionA, queue, numMessages, "A"); - } - finally { - // Step 10. Be sure to close our resources! - - if (connectionA != null) { - connectionA.close(); - } - - if (initialContext != null) { - initialContext.close(); - } - - ServerUtil.killServer(server0); - ServerUtil.killServer(server1); - } - } - - private static void consume(Session session, Queue queue, int numMessages, String node) throws Exception { - MessageConsumer consumer = session.createConsumer(queue); - - for (int i = 0; i < numMessages; i++) { - TextMessage message = (TextMessage) consumer.receive(2000); - System.out.println("Got message: " + message.getText() + " from node " + node); - if (i == 5) { - ServerUtil.killServer(server0); - } - } - - System.out.println("receive other message from node " + node + ": " + consumer.receive(2000)); - - } - - private static class FailoverListenerImpl implements FailoverEventListener { - - public void failoverEvent(FailoverEventType eventType) { - System.out.println("Failover event triggered :" + eventType.toString()); - } - } -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/client-side-failoverlistener/src/main/resources/jndi.properties ---------------------------------------------------------------------- diff --git a/examples/jms/client-side-failoverlistener/src/main/resources/jndi.properties b/examples/jms/client-side-failoverlistener/src/main/resources/jndi.properties deleted file mode 100644 index 7f7a19f..0000000 --- a/examples/jms/client-side-failoverlistener/src/main/resources/jndi.properties +++ /dev/null @@ -1,20 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -java.naming.factory.initial=org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory -connectionFactory.ConnectionFactory=tcp://localhost:61616?ha=true&retryInterval=1000&retryIntervalMultiplier=1.0&reconnectAttempts=-1 -queue.queue/exampleQueue=exampleQueue http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/client-side-load-balancing/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/client-side-load-balancing/pom.xml b/examples/jms/client-side-load-balancing/pom.xml deleted file mode 100644 index 40fed73..0000000 --- a/examples/jms/client-side-load-balancing/pom.xml +++ /dev/null @@ -1,205 +0,0 @@ -<?xml version='1.0'?> -<!-- -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. ---> - -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.apache.activemq.examples.jms</groupId> - <artifactId>jms-examples</artifactId> - <version>1.0.1-SNAPSHOT</version> - </parent> - - <artifactId>client-side-load-balancing</artifactId> - <packaging>jar</packaging> - <name>ActiveMQ Artemis JMS Client Side Load Balancing Example</name> - - <properties> - <activemq.basedir>${project.basedir}/../../..</activemq.basedir> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-jms-client</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - - <profiles> - <profile> - <!-- specify -PnoServer if you don't want to start the server --> - <id>noServer</id> - <properties> - <noServer>true</noServer> - </properties> - </profile> - </profiles> - <build> - <plugins> - <plugin> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-maven-plugin</artifactId> - <executions> - <execution> - <id>create0</id> - <goals> - <goal>create</goal> - </goals> - <configuration> - <ignore>${noServer}</ignore> - <instance>${basedir}/target/server0</instance> - <clustered>true</clustered> - </configuration> - </execution> - <execution> - <id>create1</id> - <goals> - <goal>create</goal> - </goals> - <configuration> - <ignore>${noServer}</ignore> - <instance>${basedir}/target/server1</instance> - <clustered>true</clustered> - <portOffset>1</portOffset> - </configuration> - </execution> - <execution> - <id>create2</id> - <goals> - <goal>create</goal> - </goals> - <configuration> - <ignore>${noServer}</ignore> - <instance>${basedir}/target/server2</instance> - <clustered>true</clustered> - <portOffset>2</portOffset> - </configuration> - </execution> - <execution> - <id>start0</id> - <goals> - <goal>cli</goal> - </goals> - <configuration> - <spawn>true</spawn> - <ignore>${noServer}</ignore> - <location>${basedir}/target/server0</location> - <testURI>tcp://localhost:61616</testURI> - <args> - <param>run</param> - </args> - <name>server0</name> - </configuration> - </execution> - <execution> - <id>start1</id> - <goals> - <goal>cli</goal> - </goals> - <configuration> - <ignore>${noServer}</ignore> - <spawn>true</spawn> - <location>${basedir}/target/server1</location> - <testURI>tcp://localhost:61617</testURI> - <args> - <param>run</param> - </args> - <name>server1</name> - </configuration> - </execution> - <execution> - <id>start2</id> - <goals> - <goal>cli</goal> - </goals> - <configuration> - <ignore>${noServer}</ignore> - <spawn>true</spawn> - <location>${basedir}/target/server2</location> - <testURI>tcp://localhost:61618</testURI> - <args> - <param>run</param> - </args> - <name>server2</name> - </configuration> - </execution> - <execution> - <id>runClient</id> - <goals> - <goal>runClient</goal> - </goals> - <configuration> - <clientClass>org.apache.activemq.artemis.jms.example.ClientSideLoadBalancingExample</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> - <execution> - <id>stop2</id> - <goals> - <goal>cli</goal> - </goals> - <configuration> - <ignore>${noServer}</ignore> - <location>${basedir}/target/server2</location> - <args> - <param>stop</param> - </args> - </configuration> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>org.apache.activemq.examples.jms</groupId> - <artifactId>client-side-load-balancing</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - </plugin> - </plugins> - </build> - -</project> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/client-side-load-balancing/readme.html ---------------------------------------------------------------------- diff --git a/examples/jms/client-side-load-balancing/readme.html b/examples/jms/client-side-load-balancing/readme.html deleted file mode 100644 index dc06623..0000000 --- a/examples/jms/client-side-load-balancing/readme.html +++ /dev/null @@ -1,49 +0,0 @@ -<!-- -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. ---> - -<html> - <head> - <title>ActiveMQ Artemis JMS Client-Side Load-Balancing Example</title> - <link rel="stylesheet" type="text/css" href="../common/common.css" /> - <link rel="stylesheet" type="text/css" href="../common/prettify.css" /> - <script type="text/javascript" src="../common/prettify.js"></script> - </head> - <body onload="prettyPrint()"> - <h1>JMS Client-Side Load-Balancing 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 connnections created from a single JMS Connection factory can be created - to different nodes of the cluster. In other words it demonstrates how ActiveMQ Artemis does <b>client side load balancing</b> of - connections across the cluster.</p> - <p>The particular load-balancing policy can be chosen to be random, round-robin or user-defined. Please see the user - guide for more details of how to configure the specific load-balancing policy. In this example we will use - the default round-robin load balancing policy.</p> - <p>The list of servers over which ActiveMQ Artemis will round-robin the connections can either be specified explicitly - in the connection factory when instantiating it directly, when configuring it on the server or configured - to use UDP discovery to discover the list of servers over which to round-robin. This example will use UDP - discovery to obtain the list.</p> - <p>This example starts three servers which all broadcast their location using UDP discovery. The UDP broadcast configuration - can be seen in the <code>broker.xml</code> file.</p> - <p>A JMS ConnectionFactory is deployed on each server specifying the discovery group that will be used by that - connection factory.</p> - <p>For more information on ActiveMQ Artemis load balancing, and clustering in general, please see the clustering - section of the user manual.</p> - - </body> -</html> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/client-side-load-balancing/src/main/java/org/apache/activemq/artemis/jms/example/ClientSideLoadBalancingExample.java ---------------------------------------------------------------------- diff --git a/examples/jms/client-side-load-balancing/src/main/java/org/apache/activemq/artemis/jms/example/ClientSideLoadBalancingExample.java b/examples/jms/client-side-load-balancing/src/main/java/org/apache/activemq/artemis/jms/example/ClientSideLoadBalancingExample.java deleted file mode 100644 index 1281017..0000000 --- a/examples/jms/client-side-load-balancing/src/main/java/org/apache/activemq/artemis/jms/example/ClientSideLoadBalancingExample.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.activemq.artemis.jms.example; - -import javax.jms.Connection; -import javax.jms.ConnectionFactory; -import javax.jms.JMSException; -import javax.jms.MessageConsumer; -import javax.jms.MessageProducer; -import javax.jms.Queue; -import javax.jms.Session; -import javax.jms.TextMessage; -import javax.naming.InitialContext; - -/** - * This example demonstrates how sessions created from a single connection can be load - * balanced across the different nodes of the cluster. - * - * In this example there are three nodes and we use a round-robin client side load-balancing - * policy. - */ -public class ClientSideLoadBalancingExample { - - public static void main(final String[] args) throws Exception { - InitialContext initialContext = null; - - Connection connectionA = null; - Connection connectionB = null; - Connection connectionC = null; - - try { - // Step 1. Get an initial context for looking up JNDI from server 0 - initialContext = new InitialContext(); - - // Step 2. Look-up the JMS Queue object from JNDI - Queue queue = (Queue) initialContext.lookup("queue/exampleQueue"); - - // Step 3. Look-up a JMS Connection Factory object from JNDI on server 0 - ConnectionFactory connectionFactory = (ConnectionFactory) initialContext.lookup("ConnectionFactory"); - - // Step 4. We create 3 JMS connections from the same connection factory. Since we are using round-robin - // load-balancing this should result in each sessions being connected to a different node of the cluster - Connection conn = connectionFactory.createConnection(); - // Wait a little while to make sure broadcasts from all nodes have reached the client - Thread.sleep(5000); - connectionA = connectionFactory.createConnection(); - connectionB = connectionFactory.createConnection(); - connectionC = connectionFactory.createConnection(); - conn.close(); - - // Step 5. We create JMS Sessions - Session sessionA = connectionA.createSession(false, Session.AUTO_ACKNOWLEDGE); - Session sessionB = connectionB.createSession(false, Session.AUTO_ACKNOWLEDGE); - Session sessionC = connectionC.createSession(false, Session.AUTO_ACKNOWLEDGE); - - System.out.println("Session A - " + ((org.apache.activemq.artemis.core.client.impl.DelegatingSession) ((org.apache.activemq.artemis.jms.client.ActiveMQSession) sessionA).getCoreSession()).getConnection().getRemoteAddress()); - System.out.println("Session B - " + ((org.apache.activemq.artemis.core.client.impl.DelegatingSession) ((org.apache.activemq.artemis.jms.client.ActiveMQSession) sessionB).getCoreSession()).getConnection().getRemoteAddress()); - System.out.println("Session C - " + ((org.apache.activemq.artemis.core.client.impl.DelegatingSession) ((org.apache.activemq.artemis.jms.client.ActiveMQSession) sessionC).getCoreSession()).getConnection().getRemoteAddress()); - - // Step 6. We create JMS MessageProducer objects on the sessions - MessageProducer producerA = sessionA.createProducer(queue); - MessageProducer producerB = sessionB.createProducer(queue); - MessageProducer producerC = sessionC.createProducer(queue); - - // Step 7. We send some messages on each producer - final int numMessages = 10; - - for (int i = 0; i < numMessages; i++) { - TextMessage messageA = sessionA.createTextMessage("A:This is text message " + i); - producerA.send(messageA); - System.out.println("Sent message: " + messageA.getText()); - - TextMessage messageB = sessionB.createTextMessage("B:This is text message " + i); - producerB.send(messageB); - System.out.println("Sent message: " + messageB.getText()); - - TextMessage messageC = sessionC.createTextMessage("C:This is text message " + i); - producerC.send(messageC); - System.out.println("Sent message: " + messageC.getText()); - } - - // Step 8. We start the connection to consume messages - connectionA.start(); - connectionB.start(); - connectionC.start(); - - // Step 9. We consume messages from the 3 session, one at a time. - // We try to consume one more message than expected from each session. If - // the session were not properly load-balanced, we would be missing a - // message from one of the sessions at the end. - consume(sessionA, queue, numMessages, "A"); - consume(sessionB, queue, numMessages, "B"); - consume(sessionC, queue, numMessages, "C"); - } - finally { - // Step 10. Be sure to close our resources! - - if (connectionA != null) { - connectionA.close(); - } - if (connectionB != null) { - connectionB.close(); - } - if (connectionC != null) { - connectionC.close(); - } - - if (initialContext != null) { - initialContext.close(); - } - } - } - - private static void consume(Session session, Queue queue, int numMessages, String node) throws JMSException { - MessageConsumer consumer = session.createConsumer(queue); - - for (int i = 0; i < numMessages; i++) { - TextMessage message = (TextMessage) consumer.receive(2000); - System.out.println("Got message: " + message.getText() + " from node " + node); - } - - System.out.println("receive other message from node " + node + ": " + consumer.receive(2000)); - } -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/client-side-load-balancing/src/main/resources/jndi.properties ---------------------------------------------------------------------- diff --git a/examples/jms/client-side-load-balancing/src/main/resources/jndi.properties b/examples/jms/client-side-load-balancing/src/main/resources/jndi.properties deleted file mode 100644 index d3f932c..0000000 --- a/examples/jms/client-side-load-balancing/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=udp://231.7.7.7:9876 -queue.queue/exampleQueue=exampleQueue
