activemq-artemis/examples/jms/aerogear
jbertram dc78dd4c50 Re-enable & refactor license check 2015-05-05 16:38:19 -05:00
..
src/main fixed examples and some docs after Artemis renaming 2015-04-30 10:44:16 +01:00
pom.xml Re-enable & refactor license check 2015-05-05 16:38:19 -05:00
readme.html renamed config to broker.xml 2015-04-29 10:30:32 +01:00

readme.html

<!--
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 JMS AeroGear 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 AeroGear Example</h1>

     <p>This example shows how you can send a message to a mobile device by leveraging <a href="http://aerogear.org/push/">AeroGears push</a> technology which
         provides support for different push notification technologies like Google Cloud Messaging, Apple's APNs or
         Mozilla's SimplePush.</p>

     <p>For this example you will need an AeroGear Application running somewhere, a good way to do this is to deploy the
        Push Application on <href a="">openshift</href>, you can follow the AeroGear Push 0.X Quickstart.</p>

     <p>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.</p>

     <p>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 <a href="http://aerogear.org/docs/guides/aerogear-push-android/google-setup/">article</a> 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</p>

     <p>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 <a href="http://downloads.jboss.org.apache.activemq/ActiveMQAeroGear.apk">here</a>. For a more in depth mobile
         app example visit the AeroGear site.</p>

     <p>Once you have installed the mobile app you will need to configure the following:</p>
     <p>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.
     </p>

     <p>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.</p>


     <p>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'</p>

   <p>You should see something like this in your ActiveMQServer</p>
     <ol>
        <pre class="prettyprint">
           <code>
   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
           </code>
        </pre>
     </ol>
   <p>And on your mobile app you should see a message from ActiveMQ</p>

  <p>Now lets look a bit more closely at the configuration in broker.xml</p>
     <ol>
        <pre class="prettyprint">
           <code>
   &lt;queues>
       &lt;queue name="jms.queue.exampleQueue">
           &lt;address>jms.queue.exampleQueue&lt;/address>
       &lt;/queue>
   &lt;/queues>

   &lt;connector-services>
       &lt;connector-service name="aerogear-connector">
           &lt;factory-class>org.apache.activemq.integration.aerogear.AeroGearConnectorServiceFactory&lt;/factory-class>
           &lt;param key="endpoint" value="${endpoint}"/>
           &lt;param key="queue" value="jms.queue.exampleQueue"/>
           &lt;param key="application-id" value="${applicationid}"/>
           &lt;param key="master-secret" value="${mastersecret}"/>
       &lt;/connector-service>
   &lt;/connector-services>
           </code>
        </pre>
     </ol>
  <p>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:</p>
  <ol>
      <li>endpoint - The endpoint or URL of you AeroGear application</li>
      <li>queue - The name of the queue to consume from</li>
      <li>application-id - The application id of your mobile application in AeroGear</li>
      <li>master-secret - the secret of your mobile application in AeroGear</li>
  </ol>
  <p>as well as those there are also the following optional parameters</p>
  <ol>
      <li>ttl - The time to live for the message once AeroGear receives it</li>
      <li>badge - The badge the mobile app should use for the notification</li>
      <li>sound - The sound the mobile app should use for the notification</li>
      <li>filter - A message filter(selector) to use on the connector</li>
      <li>retry-interval - If an error occurs on send, how long before we try again</li>
      <li>retry-attempts - How many times we should try to reconnect after an error</li>
      <li>variants - A comma separated list of variants that should get the message</li>
      <li>aliases - A list of aliases that should get the message</li>
      <li>device-types - A list of device types that should get the message</li>
  </ol>
  <p>More in depth explanations of these can be found in the AeroGear docs.</p>
  <p>Now lets look at a snippet of code we used to send the message for our JMS client</p>
  <pre class="prettyprint">
      <code>
  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);
      </code>
  </pre>
  <p> 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</p>
  <p>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</p>
  </body>
</html>