Return-Path: X-Original-To: apmail-activemq-commits-archive@www.apache.org Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1E76A1869A for ; Wed, 12 Aug 2015 03:46:58 +0000 (UTC) Received: (qmail 57274 invoked by uid 500); 12 Aug 2015 03:46:57 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 57203 invoked by uid 500); 12 Aug 2015 03:46:57 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 55341 invoked by uid 99); 12 Aug 2015 03:46:56 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Aug 2015 03:46:56 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 6B284E188B; Wed, 12 Aug 2015 03:46:56 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: clebertsuconic@apache.org To: commits@activemq.apache.org Date: Wed, 12 Aug 2015 03:47:20 -0000 Message-Id: In-Reply-To: <9f945b5dbf20413381634a841d402097@git.apache.org> References: <9f945b5dbf20413381634a841d402097@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [26/52] [abbrv] [partial] activemq-artemis git commit: This commit has improvements on the examples including: http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/core/vertx-connector/readme.html ---------------------------------------------------------------------- diff --git a/examples/core/vertx-connector/readme.html b/examples/core/vertx-connector/readme.html deleted file mode 100644 index a91735f..0000000 --- a/examples/core/vertx-connector/readme.html +++ /dev/null @@ -1,103 +0,0 @@ - - - - - ActiveMQ Artemis Vert.x Connector Service Example - - - - - -

Vert.x Connector Service Example

- -

This example shows you how to configure ActiveMQ Artemis to use the Vert.x Connector Service.

- -

ActiveMQ Artemis supports 2 types of Vert.x connector, incoming and outgoing. - Incoming connector consumes from Vert.x event bus and forwards to a configurable address. - Outgoing connector consumes from a configurable address and forwards to a configurable Vert.x event bus. -

- -

In this example, an incoming connector and an outgoing connector are configured. A simple java Verticle - is deployed. The verticle registers a message handler on the outgoing connector's address ("outgoing.vertx.address"). - A String message is sent to Vert.x event bus on the incoming connector's address("incoming.vertx.address"). - The message then will be forwarded to a ActiveMQ Artemis queue by the incoming connector. The outgoing connector listens to - the ActiveMQ Artemis queue and forwards the message from ActiveMQ Artemis to Vert.x event bus on the outgoing connector's address. - The verticle finally receives the message from it's event bus.

- -

For more information on Vert.x concept please visit the Vertx site

- -

Example step-by-step

-

To run the server, simply type mvn verify - from this directory.

- -
    -
  1. First we need to create a Vert.x PlatformManager
  2. -
    -           platformManager = PlatformLocator.factory.createPlatformManager(PORT, HOST);
    -        
    - -
  3. We deploy a Verticle using the platformManager
  4. -
    -           String verticle = "org.apache.activemq.artemis.core.example.ExampleVerticle";
    -           platformManager.deployVerticle(verticle, null, new URL[0], 1, null,
    -                  new Handler>(){
    -
    -                     @Override
    -                     public void handle(AsyncResult result)
    -                     {
    -                        if (!result.succeeded())
    -                        {
    -                           throw new RuntimeException("failed to deploy verticle", result.cause());
    -                        }
    -                        latch0.countDown();
    -                     }
    -
    -           });
    -        
    - -
  5. We register a message handler with the event bus in the Verticle to listen on the outgoing connector's address.
  6. -
    -           EventBus eventBus = vertx.eventBus();
    -           eventBus.registerHandler(VertxConnectorExample.OUTGOING,
    -                      new Handler>() {
    -                         @Override
    -                         public void handle(Message startMsg)
    -                         {
    -                            Object body = startMsg.body();
    -                            System.out.println("Verticle receives a message: " + body);
    -                            VertxConnectorExample.result.set(VertxConnectorExample.MSG.equals(body));
    -                            latch0.countDown();
    -                         }
    -                      });
    -           
    -        
    - -
  7. We send a message to incoming connector's address via event bus
  8. -
    -           
    -              EventBus bus = platformManager.vertx().eventBus();
    -              bus.send(INCOMING, MSG);
    -           
    -        
    - -
  9. The message will eventually arrives at the Verticle's message handler.
  10. -
- - http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/core/vertx-connector/src/main/java/org/apache/activemq/artemis/core/example/ExampleVerticle.java ---------------------------------------------------------------------- diff --git a/examples/core/vertx-connector/src/main/java/org/apache/activemq/artemis/core/example/ExampleVerticle.java b/examples/core/vertx-connector/src/main/java/org/apache/activemq/artemis/core/example/ExampleVerticle.java deleted file mode 100644 index 50a8f79..0000000 --- a/examples/core/vertx-connector/src/main/java/org/apache/activemq/artemis/core/example/ExampleVerticle.java +++ /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. - */ -package org.apache.activemq.artemis.core.example; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import org.vertx.java.core.Handler; -import org.vertx.java.core.eventbus.EventBus; -import org.vertx.java.core.eventbus.Message; -import org.vertx.java.platform.Verticle; - -public class ExampleVerticle extends Verticle { - - @Override - public void start() { - EventBus eventBus = vertx.eventBus(); - - final CountDownLatch latch0 = new CountDownLatch(1); - - // Register a handler on the outgoing connector's address - eventBus.registerHandler(VertxConnectorExample.OUTGOING, new Handler>() { - @Override - public void handle(Message startMsg) { - Object body = startMsg.body(); - System.out.println("Verticle receives a message: " + body); - VertxConnectorExample.result.set(VertxConnectorExample.MSG.equals(body)); - latch0.countDown(); - //Tell the example to finish. - VertxConnectorExample.latch.countDown(); - } - }); - - try { - latch0.await(5000, TimeUnit.MILLISECONDS); - } - catch (InterruptedException e) { - } - } -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/core/vertx-connector/src/main/java/org/apache/activemq/artemis/core/example/VertxConnectorExample.java ---------------------------------------------------------------------- diff --git a/examples/core/vertx-connector/src/main/java/org/apache/activemq/artemis/core/example/VertxConnectorExample.java b/examples/core/vertx-connector/src/main/java/org/apache/activemq/artemis/core/example/VertxConnectorExample.java deleted file mode 100644 index 2194e30..0000000 --- a/examples/core/vertx-connector/src/main/java/org/apache/activemq/artemis/core/example/VertxConnectorExample.java +++ /dev/null @@ -1,105 +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.core.example; - -import java.net.URL; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; - -import org.vertx.java.core.AsyncResult; -import org.vertx.java.core.Handler; -import org.vertx.java.core.eventbus.EventBus; -import org.vertx.java.platform.PlatformLocator; -import org.vertx.java.platform.PlatformManager; -import org.vertx.java.spi.cluster.impl.hazelcast.HazelcastClusterManagerFactory; - -/** - * A simple example of using Vert.x connector service. - */ -public class VertxConnectorExample { - - public static final String INCOMING = "incoming.vertx.address"; - public static final String OUTGOING = "outgoing.vertx.address"; - public static final String MSG = "Welcome to Vertx world!"; - - public final static CountDownLatch latch = new CountDownLatch(1); - public final static AtomicBoolean result = new AtomicBoolean(false); - - private static final String HOST = "127.0.0.1"; - private static final int PORT = 0; - - public static void main(final String[] args) throws Exception { - System.setProperty("vertx.clusterManagerFactory", HazelcastClusterManagerFactory.class.getName()); - PlatformManager platformManager = null; - - try { - // Step 1 Create a Vert.x PlatformManager - platformManager = PlatformLocator.factory.createPlatformManager(PORT, HOST); - - final CountDownLatch latch0 = new CountDownLatch(1); - - // Step 2 Deploy a Verticle to receive message - String verticle = "org.apache.activemq.artemis.core.example.ExampleVerticle"; - platformManager.deployVerticle(verticle, null, new URL[0], 1, null, new Handler>() { - - @Override - public void handle(AsyncResult result) { - if (!result.succeeded()) { - throw new RuntimeException("failed to deploy verticle", result.cause()); - } - latch0.countDown(); - } - - }); - - latch0.await(); - - // Step 3 Send a message to the incoming connector's address - EventBus bus = platformManager.vertx().eventBus(); - bus.send(INCOMING, MSG); - - // Step 4 Waiting for the Verticle to process the message - latch.await(10000, TimeUnit.MILLISECONDS); - } - finally { - if (platformManager != null) { - platformManager.undeployAll(null); - platformManager.stop(); - } - reportResultAndExit(); - } - } - - private static void reportResultAndExit() { - if (!result.get()) { - System.err.println(); - System.err.println("#####################"); - System.err.println("### FAILURE! ###"); - System.err.println("#####################"); - System.exit(1); - } - else { - System.out.println(); - System.out.println("#####################"); - System.out.println("### SUCCESS! ###"); - System.out.println("#####################"); - System.exit(0); - } - } - -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/core/vertx-connector/src/main/resources/activemq/server0/broker.xml ---------------------------------------------------------------------- diff --git a/examples/core/vertx-connector/src/main/resources/activemq/server0/broker.xml b/examples/core/vertx-connector/src/main/resources/activemq/server0/broker.xml deleted file mode 100644 index 9be6726..0000000 --- a/examples/core/vertx-connector/src/main/resources/activemq/server0/broker.xml +++ /dev/null @@ -1,81 +0,0 @@ - - - - - - - - - - target/server0/data/messaging/bindings - - target/server0/data/messaging/journal - - target/server0/data/messaging/largemessages - - target/server0/data/messaging/paging - - - - tcp://localhost:61616 - - - - - tcp://localhost:61616 - - - - - - - - - - - - - - -
queue.vertxQueue
-
-
- - - - org.apache.activemq.artemis.integration.vertx.VertxIncomingConnectorServiceFactory - - - - - - - org.apache.activemq.artemis.integration.vertx.VertxOutgoingConnectorServiceFactory - - - - - - -
- -
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/README.md ---------------------------------------------------------------------- diff --git a/examples/jms/README.md b/examples/jms/README.md deleted file mode 100644 index e9d9e36..0000000 --- a/examples/jms/README.md +++ /dev/null @@ -1,32 +0,0 @@ -Running the ActiveMQ Artemis Examples -============================ - -To run an individual example firstly cd into the example directory and run - -```sh -mvn verify -``` - -Most examples offer a way to start them without creating and starting the server (say if you want to do it manually) - -```sh -mvn verify -PnoServer -``` - -If you are running against an un released version, i.e. from master branch, you will have to run `mvn install` on the root -pom.xml and the example/activemq-jms-examples-common/pom.xml first. - -If you want to run all the examples (except those that need to be run standalone) you can run `mvn verify -Pexamples` in the examples -directory but before you do you will need to up the memory used by running: - -``` -export MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=256m" -``` -### Recreating the examples - -If you are trying to copy the examples somewhere else and modifying them. Consider asking Maven to explicitly list all the dependencies: - -``` -# if trying to modify the 'topic' example: -cd examples/jms/topic && mvn dependency:list -``` http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/aerogear/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/aerogear/pom.xml b/examples/jms/aerogear/pom.xml deleted file mode 100644 index fc224d6..0000000 --- a/examples/jms/aerogear/pom.xml +++ /dev/null @@ -1,134 +0,0 @@ - - - - - 4.0.0 - - - org.apache.activemq.examples.jms - jms-examples - 1.0.1-SNAPSHOT - - - - - - - ${project.basedir}/../../.. - - - aerogear - jar - ActiveMQ Artemis JMS AeroGear Example - - - - org.apache.activemq - artemis-cli - ${project.version} - - - - - - - noServer - - true - - - - - - - org.apache.activemq - artemis-maven-plugin - - - create - - create - - - ${noServer} - - - org.apache.activemq:artemis-aerogear-integration:${project.version} - org.jboss.aerogear:unifiedpush-java-client:1.0.0 - net.iharder:base64:2.3.8 - com.fasterxml.jackson.core:jackson-annotations:2.3.0 - com.fasterxml.jackson.core:jackson-core:2.3.0 - org.jboss.resteasy:resteasy-jackson-provider:2.3.2.Final - org.codehaus.jackson:jackson-core-asl:1.8.5 - org.codehaus.jackson:jackson-mapper-asl:1.8.5 - org.codehaus.jackson:jackson-jaxrs:1.8.5 - org.codehaus.jackson:jackson-xc:1.8.5 - - - - - start - - cli - - - ${noServer} - true - tcp://localhost:61616 - - run - - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.AerogearExample - - - - stop - - cli - - - ${noServer} - - stop - - - - - - - org.apache.activemq.examples.jms - aerogear - ${project.version} - - - - - - - http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/aerogear/readme.html ---------------------------------------------------------------------- diff --git a/examples/jms/aerogear/readme.html b/examples/jms/aerogear/readme.html deleted file mode 100644 index bdddfa6..0000000 --- a/examples/jms/aerogear/readme.html +++ /dev/null @@ -1,157 +0,0 @@ - - - - - ActiveMQ Artemis JMS AeroGear Example - - - - - -

JMS AeroGear Example

- - -
To run the example, simply type mvn verify from this directory, 
or mvn -PnoServer verify if you want to start and create the server manually.
- -

This example shows how you can send a message to a mobile device by leveraging AeroGears push technology which - provides support for different push notification technologies like Google Cloud Messaging, Apple's APNs or - Mozilla's SimplePush.

- -

For this example you will need an AeroGear Application running somewhere, a good way to do this is to deploy the - Push Application on openshift, you can follow the AeroGear Push 0.X Quickstart.

- -

Once you have created your AeroGear Push Application you can create a mobile application. Simply log into the application - on the web and create a new mobile application by clicking the 'create' button. Once created you will see an application id - and a master secret, you will need the later to run the example.

- -

lastly you will need to create a variant. For this example we will be using Android so you will need to create a google project, - this article explains how to do this. - Once created click on your app then click 'add' to add a variant. choose 'google cloud messaging', enter your google - API key and the project number from your google project and click create

- -

Now before we run the example we need a mobile application to receive it. Writing a mobile app is beyond the scope - of this example but for testing purposes we have supplied an Android app you can use, simply install on your android phone. - It can be found here. For a more in depth mobile - app example visit the AeroGear site.

- -

Once you have installed the mobile app you will need to configure the following:

-

AeroGear Unified Push URL : This is the URL where your aerogear server is running, something like http://myapp-mydomain.rhcloud.com - AeroGear Variant ID : This is the ID of the variant you created in AeroGear - AeroGear Variant Secret : This is the secret for your variant - GCM Sender ID : this is the Google project Number you created on Google - Variant : you can use this to target messages if needed. -

- -

Once you set all these correctly you should get a message saying your mobile app is registered, if you log into - your AeroGear app you should see it registered with the variant.

- - -

Now to run the example simply run the following command - 'mvn -Dendpoint=my aerogear url -Dapplicationid=my application id -Dmastersecret=my master secret -Djsse.enableSNIExtension=false clean verify'. - If you arent using java 7 you can omit the 'jsse.enableSNIExtension=false'

- -

You should see something like this in your ActiveMQServer

-
    -
    -           
    -   Dec 04, 2013 3:25:39 PM org.jboss.aerogear.unifiedpush.SenderClient submitPayload
    -   INFO: HTTP Response code from UnifiedPush Server: 302
    -   Dec 04, 2013 3:25:39 PM org.jboss.aerogear.unifiedpush.SenderClient submitPayload
    -   INFO: Performing redirect to 'https://myapp-mydomain.rhcloud.com/rest/sender/'
    -   Dec 04, 2013 3:25:40 PM org.jboss.aerogear.unifiedpush.SenderClient submitPayload
    -   INFO: HTTP Response code from UnifiedPush Server: 200
    -           
    -        
    -
-

And on your mobile app you should see a message from ActiveMQ

- -

Now lets look a bit more closely at the configuration in broker.xml

-
    -
    -           
    -   <queues>
    -       <queue name="jms.queue.exampleQueue">
    -           <address>jms.queue.exampleQueue</address>
    -       </queue>
    -   </queues>
    -
    -   <connector-services>
    -       <connector-service name="aerogear-connector">
    -           <factory-class>org.apache.activemq.integration.aerogear.AeroGearConnectorServiceFactory</factory-class>
    -           <param key="endpoint" value="${endpoint}"/>
    -           <param key="queue" value="jms.queue.exampleQueue"/>
    -           <param key="application-id" value="${applicationid}"/>
    -           <param key="master-secret" value="${mastersecret}"/>
    -       </connector-service>
    -   </connector-services>
    -           
    -        
    -
-

Firstly you will see that we have to create a core queue so it is available when the connector is started, the following are mandatory parameters:

-
    -
  1. endpoint - The endpoint or URL of you AeroGear application
  2. -
  3. queue - The name of the queue to consume from
  4. -
  5. application-id - The application id of your mobile application in AeroGear
  6. -
  7. master-secret - the secret of your mobile application in AeroGear
  8. -
-

as well as those there are also the following optional parameters

-
    -
  1. ttl - The time to live for the message once AeroGear receives it
  2. -
  3. badge - The badge the mobile app should use for the notification
  4. -
  5. sound - The sound the mobile app should use for the notification
  6. -
  7. filter - A message filter(selector) to use on the connector
  8. -
  9. retry-interval - If an error occurs on send, how long before we try again
  10. -
  11. retry-attempts - How many times we should try to reconnect after an error
  12. -
  13. variants - A comma separated list of variants that should get the message
  14. -
  15. aliases - A list of aliases that should get the message
  16. -
  17. device-types - A list of device types that should get the message
  18. -
-

More in depth explanations of these can be found in the AeroGear docs.

-

Now lets look at a snippet of code we used to send the message for our JMS client

-
-      
-  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
-  connection = cf.createConnection();
-
-  // Step 5. Create a JMS Session
-  Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
-  // Step 6. Create a JMS Message Producer
-  MessageProducer producer = session.createProducer(queue);
-
-  // Step 7. Create a Text Message
-  Message message = session.createMessage();
-
-  message.setStringProperty("AEROGEAR_ALERT", "Hello this is a notification from ActiveMQ");
-
-  producer.send(message);
-      
-  
-

The most important thing here is string propert we have set on the message, i.e. 'AEROGEAR_ALERT'. This is the - actual alert that is sent via AeroGear

-

As well as the alert itself you can override any of the above optional parameters in the same fashionby using the - following propert names: AEROGEAR_SOUND,AEROGEAR_BADGE,AEROGEAR_TTL,AEROGEAR_VARIANTS,AEROGEAR_ALIASES and AEROGEAR_DEVICE_TYPES

- - http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/aerogear/src/main/java/org/apache/activemq/artemis/jms/example/AerogearExample.java ---------------------------------------------------------------------- diff --git a/examples/jms/aerogear/src/main/java/org/apache/activemq/artemis/jms/example/AerogearExample.java b/examples/jms/aerogear/src/main/java/org/apache/activemq/artemis/jms/example/AerogearExample.java deleted file mode 100644 index b412d87..0000000 --- a/examples/jms/aerogear/src/main/java/org/apache/activemq/artemis/jms/example/AerogearExample.java +++ /dev/null @@ -1,77 +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.MessageProducer; -import javax.jms.Queue; -import javax.jms.Session; -import javax.naming.InitialContext; - -/** - * A simple JMS Queue example that creates a producer and consumer on a queue and sends then receives a message. - */ -public class AerogearExample { - - 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 - 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 a Text Message - Message message = session.createMessage(); - - message.setStringProperty("AEROGEAR_ALERT", "Hello this is a notification from ActiveMQ"); - - producer.send(message); - - System.out.println("Sent message"); - - System.out.println("now check your mobile app and press enter"); - - System.in.read(); - } - finally { - // Step 12. 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/aerogear/src/main/resources/activemq/server0/broker.xml ---------------------------------------------------------------------- diff --git a/examples/jms/aerogear/src/main/resources/activemq/server0/broker.xml b/examples/jms/aerogear/src/main/resources/activemq/server0/broker.xml deleted file mode 100644 index 1095761..0000000 --- a/examples/jms/aerogear/src/main/resources/activemq/server0/broker.xml +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - - - - - - - - ./data/bindings - - ./data/journal - - ./data/largemessages - - ./data/paging - - - - tcp://localhost:61616 - - - - - -
jms.queue.exampleQueue
-
-
- - - - org.apache.activemq.artemis.integration.aerogear.AeroGearConnectorServiceFactory - - - - - - - - - - - - - - - - - - - - -
-
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/aerogear/src/main/resources/jndi.properties ---------------------------------------------------------------------- diff --git a/examples/jms/aerogear/src/main/resources/jndi.properties b/examples/jms/aerogear/src/main/resources/jndi.properties deleted file mode 100644 index 93537c4..0000000 --- a/examples/jms/aerogear/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/application-layer-failover/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/application-layer-failover/pom.xml b/examples/jms/application-layer-failover/pom.xml deleted file mode 100644 index b670d18..0000000 --- a/examples/jms/application-layer-failover/pom.xml +++ /dev/null @@ -1,102 +0,0 @@ - - - - - 4.0.0 - - - org.apache.activemq.examples.jms - jms-examples - 1.0.1-SNAPSHOT - - - application-layer-failover - jar - ActiveMQ Artemis JMS Application Layer Failover Example - - - ${project.basedir}/../../.. - - - - - org.apache.activemq - artemis-cli - ${project.version} - - - org.apache.activemq - artemis-jms-client - ${project.version} - - - - - - - org.apache.activemq - artemis-maven-plugin - - - create0 - - create - - - ${basedir}/target/server0 - - - - create1 - - create - - - ${basedir}/target/server1 - 1 - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.ApplicationLayerFailoverExample - - ${basedir}/target/server0 - ${basedir}/target/server1 - - - - - - - org.apache.activemq.examples.jms - application-layer-failover - ${project.version} - - - - - - - http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/application-layer-failover/readme.html ---------------------------------------------------------------------- diff --git a/examples/jms/application-layer-failover/readme.html b/examples/jms/application-layer-failover/readme.html deleted file mode 100644 index 3a23b62..0000000 --- a/examples/jms/application-layer-failover/readme.html +++ /dev/null @@ -1,169 +0,0 @@ - - - - - ActiveMQ Artemis Application-Layer Failover Example - - - - - -

Application-Layer Failover Example

- -
To run the example, simply type mvn verify from this directory. This example will always spawn and stop multiple servers.
- -

ActiveMQ Artemis implements fully transparent automatic failover of connections from a live node to a backup node which requires - no special coding. This is described in a different example and requires server replication.

-

However, ActiveMQ Artemis also supports Application-Layer failover which is useful in the case where replication is not enabled.

-

With Application-Layer failover, it's up to the application to register a JMS ExceptionListener with ActiveMQ Artemis. - This listener will then be called by ActiveMQ Artemis in the event that connection failure is detected.

-

User code in the ExceptionListener can then recreate any JMS Connection, Session, etc on another node and the application - can continue.

-

Application-Layer failover is an alternative approach to High Availabilty (HA).

-

Application-Layer failover differs from automatic failover in that some client side coding is required in order - to implement this. Also, with Application-Layer failover, since the old Session object dies and a new is created, any uncommitted - work in the old Session will be lost, and any unacknowledged messages might be redelivered.

-

For more information on ActiveMQ Artemis failover and HA, and clustering in general, please see the clustering - section of the user manual.

- -

Example step-by-step

-

In this example, the live server is server 1, which will failover onto server 0.

-

The connection will initially be created to server1, server 1 will crash, and the client will carry on - on server 0, the new server. With Application-Layer failover the node that is failed over onto, does not need to - be specially configured as a backup server, it can be any node.

- -
    -
  1. We create our JMS Connection, Session, MessageProducer and MessageConsumer on server 1
  2. -
    -           createJMSObjects(1);
    -        
    - -
  3. We set a JMS ExceptionListener on the connection. On failure this will be called and the connection, - session, etc. will be manually recreated on the backup node.
  4. -
    -           connection.setExceptionListener(new ExampleListener());
    -        
    - -
  5. We send some messages to server 1, the live server.
  6. -
    -           
    -         final int numMessages = 10;
    -
    -         for (int i = 0; i < numMessages; i++)
    -         {
    -            TextMessage message = session.createTextMessage("This is text message " + i);
    -
    -            producer.send(message);
    -
    -            System.out.println("Sent message: " + message.getText());
    -         }
    -           
    -        
    - -
  7. We consume those messages on server 1.
  8. -
    -          
    -          for (int i = 0; i < numMessages; i++)
    -         {
    -            TextMessage message0 = (TextMessage)consumer.receive(5000);
    -
    -            System.out.println("Got message: " + message0.getText());
    -         }
    -          
    -        
    - -
  9. We now cause server 1, the live server to crash. After a little while the connection's - ExceptionListener will register the failure and reconnection will occur.
  10. -
    -           killServer(1);
    -        
    - -
  11. The connection's ExceptionListener gets called, and we lookup the JMS objects and - recreate the connection, session, etc on the other node 0.
  12. -
    -           
    -   private class ExampleListener implements ExceptionListener
    -   {
    -      public void onException(JMSException exception)
    -      {
    -         try
    -         {
    -            // Close the old resources
    -
    -            closeResources();
    -
    -            // Create new JMS objects on the backup server
    -
    -            createJMSObjects(0);
    -
    -            failoverLatch.countDown();
    -         }
    -         catch (Exception e)
    -         {
    -            System.err.println("Failed to handle failover");
    -
    -            e.printStackTrace();
    -         }
    -      }
    -   }
    -           
    -        
    - -
  13. We are now connected to the other node. We now send some more messages.
  14. -
    -           
    -   for (int i = numMessages; i < numMessages * 2; i++)
    -         {
    -            TextMessage message = session.createTextMessage("This is text message " + i);
    -
    -            producer.send(message);
    -
    -            System.out.println("Sent message: " + message.getText());
    -         }
    -           
    -        
    - -
  15. And consume them.
  16. -
    -           
    -   for (int i = 0; i < numMessages; i++)
    -         {
    -            TextMessage message0 = (TextMessage)consumer.receive(5000);
    -
    -            System.out.println("Got message: " + message0.getText());
    -         }
    -           
    -        
    - - -
  17. And finally (no pun intended), always remember to close your resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
  18. - -
    -           
    -	finally
    -	{
    -	   closeResources();
    -	}
    -           
    -        
    - -
- - http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/application-layer-failover/src/main/java/org/apache/activemq/artemis/jms/example/ApplicationLayerFailoverExample.java ---------------------------------------------------------------------- diff --git a/examples/jms/application-layer-failover/src/main/java/org/apache/activemq/artemis/jms/example/ApplicationLayerFailoverExample.java b/examples/jms/application-layer-failover/src/main/java/org/apache/activemq/artemis/jms/example/ApplicationLayerFailoverExample.java deleted file mode 100644 index 2d0dc0c..0000000 --- a/examples/jms/application-layer-failover/src/main/java/org/apache/activemq/artemis/jms/example/ApplicationLayerFailoverExample.java +++ /dev/null @@ -1,221 +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.ExceptionListener; -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; -import javax.naming.NamingException; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; -import org.apache.activemq.artemis.util.ServerUtil; - -/** - * A simple example that demonstrates application-layer failover of the JMS connection from one node to another - * when the live server crashes - */ -public class ApplicationLayerFailoverExample { - - private static InitialContext initialContext; - - private static Connection connection; - - private static Session session; - - private static MessageConsumer consumer; - - private static MessageProducer producer; - - private static final CountDownLatch failoverLatch = new CountDownLatch(1); - - private static Process server0; - - private static Process server1; - - public static void main(final String[] args) throws Exception { - try { - server0 = ServerUtil.startServer(args[0], ApplicationLayerFailoverExample.class.getSimpleName() + "0", 0, 5000); - server1 = ServerUtil.startServer(args[1], ApplicationLayerFailoverExample.class.getSimpleName() + "1", 1, 5000); - - // Step 1. We create our JMS Connection, Session, MessageProducer and MessageConsumer on server 1. - createJMSObjects(0); - - // Step 2. We set a JMS ExceptionListener on the connection. On failure this will be called and the connection, - // session, etc. will be then recreated on the backup node. - connection.setExceptionListener(new ExampleListener()); - - System.out.println("The initial JMS objects have been created, and the ExceptionListener set"); - - // Step 3. We send some messages to server 1, the live server - - final int numMessages = 10; - - for (int i = 0; i < numMessages; i++) { - TextMessage message = session.createTextMessage("This is text message " + i); - - producer.send(message); - - System.out.println("Sent message: " + message.getText()); - } - - // Step 4. We consume those messages on server 1. - - for (int i = 0; i < numMessages; i++) { - TextMessage message0 = (TextMessage) consumer.receive(5000); - - System.out.println("Got message: " + message0.getText()); - } - - // Step 5. We now cause server 1, the live server to crash. After a little while the connection's - // ExceptionListener will register the failure and reconnection will occur. - - System.out.println("Killing the server"); - - ServerUtil.killServer(server0); - - // Step 6. Wait for the client side to register the failure and reconnect - - boolean ok = failoverLatch.await(5000, TimeUnit.MILLISECONDS); - - System.out.println("Reconnection has occurred. Now sending more messages."); - - // Step 8. We now send some more messages - - for (int i = numMessages; i < numMessages * 2; i++) { - TextMessage message = session.createTextMessage("This is text message " + i); - - producer.send(message); - - System.out.println("Sent message: " + message.getText()); - } - - // Step 9. And consume them. - - for (int i = 0; i < numMessages; i++) { - TextMessage message0 = (TextMessage) consumer.receive(5000); - - System.out.println("Got message: " + message0.getText()); - } - } - catch (Throwable t) { - t.printStackTrace(); - } - finally { - // Step 14. Be sure to close our resources! - closeResources(); - ServerUtil.killServer(server0); - ServerUtil.killServer(server1); - } - } - - private static void createJMSObjects(final int server) throws Exception { - // Step 1. Instantiate a JMS Connection Factory object from JNDI on server 1 - ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://127.0.0.1:" + (61616 + server)); - - // Step 2. We create a JMS Connection connection - connection = connectionFactory.createConnection(); - - // Step 3. We start the connection to ensure delivery occurs - connection.start(); - - // Step 4. We create a JMS Session - session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - - // Step 5. Look-up the JMS Queue object from JNDI - Queue queue = session.createQueue("exampleQueue"); - - // Step 6. We create a JMS MessageConsumer object - consumer = session.createConsumer(queue); - - // Step 7. We create a JMS MessageProducer object - producer = session.createProducer(queue); - } - - private static void closeResources() { - if (initialContext != null) { - try { - initialContext.close(); - } - catch (NamingException e) { - e.printStackTrace(); - } - } - - if (connection != null) { - try { - connection.close(); - } - catch (JMSException e) { - e.printStackTrace(); - } - } - } - - private static class ExampleListener implements ExceptionListener { - - public void onException(final JMSException exception) { - try { - connection.close(); - } - catch (JMSException e) { - //ignore - } - for (int i = 0; i < 10; i++) { - try { - // Step 7. The ExceptionListener gets called and we recreate the JMS objects on the new node - - System.out.println("Connection failure has been detected on a the client."); - - // Close the old resources - - // closeResources(); - - System.out.println("The old resources have been closed."); - - // Create new JMS objects on the backup server - - createJMSObjects(1); - - System.out.println("The new resources have been created."); - - failoverLatch.countDown(); - - return; - } - catch (Exception e) { - System.out.println("Failed to handle failover, trying again."); - try { - Thread.sleep(500); - } - catch (InterruptedException e1) { - //ignored - } - } - } - System.out.println("tried 10 times to reconnect, giving up"); - } - } -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/artemis-ra-rar/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/artemis-ra-rar/pom.xml b/examples/jms/artemis-ra-rar/pom.xml deleted file mode 100644 index 7f40bd7..0000000 --- a/examples/jms/artemis-ra-rar/pom.xml +++ /dev/null @@ -1,101 +0,0 @@ - - - - - 4.0.0 - - - org.apache.activemq.examples.jms - jms-examples - 1.0.1-SNAPSHOT - - - artemis-rar - rar - ActiveMQ Artemis JMS RA - - - ${project.basedir}/../../.. - - - - - org.apache.activemq - artemis-jms-client - ${project.version} - - - org.apache.activemq - artemis-core-client - - - org.apache.activemq - artemis-jms-client - - - org.apache.geronimo.specs - geronimo-jms_2.0_spec - - - org.apache.geronimo.specs - geronimo-ejb_3.0_spec - - - - - org.apache.activemq - artemis-ra - ${project.version} - - - org.apache.activemq - artemis-jms-server - ${project.version} - - - org.apache.activemq - artemis-core-client - ${project.version} - - - org.apache.activemq - artemis-core-client - - - - - io.netty - netty-all - - - - - - - org.apache.maven.plugins - maven-rar-plugin - - src/main/resources/ra.xml - - - - - - http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/artemis-ra-rar/src/main/resources/ra.xml ---------------------------------------------------------------------- diff --git a/examples/jms/artemis-ra-rar/src/main/resources/ra.xml b/examples/jms/artemis-ra-rar/src/main/resources/ra.xml deleted file mode 100644 index db571a3..0000000 --- a/examples/jms/artemis-ra-rar/src/main/resources/ra.xml +++ /dev/null @@ -1,308 +0,0 @@ - - - - - - - ActiveMQ Artemis 2.0 Resource Adapter - ActiveMQ Artemis 2.0 Resource Adapter - - Apache Software Foundation - JMS 1.1 Server - 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. - - true - - - - org.apache.activemq.artemis.ra.ActiveMQResourceAdapter - - - The transport type. Multiple connectors can be configured by using a comma separated list, - i.e. org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory,org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory. - - ConnectorClassName - java.lang.String - org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory - - - The transport configuration. These values must be in the form of key=val;key=val;, - if multiple connectors are used then each set must be separated by a comma i.e. host=host1;port=61616,host=host2;port=61617. - Each set of params maps to the connector classname specified. - - ConnectionParameters - java.lang.String - server-id=0 - - - - - - org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory - - - The default session type - SessionDefaultType - java.lang.String - javax.jms.Queue - - - Try to obtain a lock within specified number of seconds; less than or equal to 0 disable this functionality - UseTryLock - java.lang.Integer - 0 - - - org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactory - org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl - javax.jms.Session - org.apache.activemq.artemis.ra.ActiveMQRASession - - XATransaction - - BasicPassword - javax.resource.spi.security.PasswordCredential - - false - - - - - - javax.jms.MessageListener - - org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec - - destination - - - - - - - - http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/jms/bridge/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/bridge/pom.xml b/examples/jms/bridge/pom.xml deleted file mode 100644 index 8c835de..0000000 --- a/examples/jms/bridge/pom.xml +++ /dev/null @@ -1,176 +0,0 @@ - - - - - 4.0.0 - - - org.apache.activemq.examples.jms - jms-examples - 1.0.1-SNAPSHOT - - - core-bridge - jar - ActiveMQ Artemis Core Bridge Example - - - ${project.basedir}/../../.. - - - - - org.apache.activemq - artemis-server - ${project.version} - - - org.apache.geronimo.specs - geronimo-jms_2.0_spec - - - - - - - noServer - - true - - - - - - - org.apache.activemq - artemis-maven-plugin - - - create0 - - create - - - - - org.apache.activemq.examples.jms:core-bridge:${project.version} - - ${noServer} - ${basedir}/target/server0 - ${basedir}/target/classes/activemq/server0 - - - - create1 - - create - - - - - org.apache.activemq.examples.jms:core-bridge:${project.version} - - ${noServer} - ${basedir}/target/server1 - ${basedir}/target/classes/activemq/server1 - 1 - - - - start0 - - cli - - - ${noServer} - true - ${basedir}/target/server0 - tcp://localhost:61616 - - run - - server0 - - - - start1 - - cli - - - ${noServer} - true - ${basedir}/target/server1 - tcp://localhost:61617 - - run - - server1 - - - - runClient - - runClient - - - org.apache.activemq.artemis.jms.example.BridgeExample - - - - stop0 - - cli - - - ${noServer} - ${basedir}/target/server0 - - stop - - - - - stop1 - - cli - - - ${noServer} - ${basedir}/target/server1 - - stop - - - - - - - org.apache.activemq.examples.jms - core-bridge - ${project.version} - - - - - - -