activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r857985 - in /websites/production/activemq/content: cache/docs.pageCache cms/cms-api-overview.html cms/example.html
Date Wed, 10 Apr 2013 14:21:31 GMT
Author: buildbot
Date: Wed Apr 10 14:21:31 2013
New Revision: 857985

Log:
Production update by buildbot for activemq

Modified:
    websites/production/activemq/content/cache/docs.pageCache
    websites/production/activemq/content/cms/cms-api-overview.html
    websites/production/activemq/content/cms/example.html

Modified: websites/production/activemq/content/cache/docs.pageCache
==============================================================================
Binary files - no diff available.

Modified: websites/production/activemq/content/cms/cms-api-overview.html
==============================================================================
--- websites/production/activemq/content/cms/cms-api-overview.html (original)
+++ websites/production/activemq/content/cms/cms-api-overview.html Wed Apr 10 14:21:31 2013
@@ -460,27 +460,32 @@ using namespace std;
     Destination* destination;
     MessageConsumer* consumer;
     bool useTopic;
-    bool clientAck;
     std::string brokerURI;
     std::string destURI;
+    bool clientAck;
+
+<span class="code-keyword">private</span>:
+
+    SimpleAsyncConsumer( <span class="code-keyword">const</span> SimpleAsyncConsumer&amp;
);
+    SimpleAsyncConsumer&amp; <span class="code-keyword">operator</span>=
( <span class="code-keyword">const</span> SimpleAsyncConsumer&amp; );
 
 <span class="code-keyword">public</span>:
 
     SimpleAsyncConsumer( <span class="code-keyword">const</span> std::string&amp;
brokerURI,
                          <span class="code-keyword">const</span> std::string&amp;
destURI,
                          bool useTopic = <span class="code-keyword">false</span>,
-                         bool clientAck = <span class="code-keyword">false</span>
) {
-        connection = NULL;
-        session = NULL;
-        destination = NULL;
-        consumer = NULL;
-        <span class="code-keyword">this</span>-&gt;useTopic = useTopic;
-        <span class="code-keyword">this</span>-&gt;brokerURI = brokerURI;
-        <span class="code-keyword">this</span>-&gt;destURI = destURI;
-        <span class="code-keyword">this</span>-&gt;clientAck = clientAck;
+                         bool clientAck = <span class="code-keyword">false</span>
) :
+        connection(NULL),
+        session(NULL),
+        destination(NULL),
+        consumer(NULL),
+        useTopic(useTopic),
+        brokerURI(brokerURI),
+        destURI(destURI),
+        clientAck(clientAck) {
     }
 
-    virtual ~SimpleAsyncConsumer(){
+    virtual ~SimpleAsyncConsumer() {
         <span class="code-keyword">this</span>-&gt;cleanup();
     }
 
@@ -533,7 +538,7 @@ using namespace std;
     }
 
     <span class="code-comment">// Called from the consumer since <span class="code-keyword">this</span>
class is a registered MessageListener.
-</span>    virtual void onMessage( <span class="code-keyword">const</span>
Message* message ){
+</span>    virtual void onMessage( <span class="code-keyword">const</span>
Message* message ) {
 
         <span class="code-keyword">static</span> <span class="code-object">int</span>
count = 0;
 
@@ -564,8 +569,8 @@ using namespace std;
 </span>    <span class="code-comment">// registered as an ExceptionListener with
the connection.
 </span>    virtual void onException( <span class="code-keyword">const</span>
CMSException&amp; ex AMQCPP_UNUSED ) {
         printf(<span class="code-quote">"CMS Exception occurred.  Shutting down client.\n"</span>);
-        <span class="code-comment">//exit(1);
-</span>    }
+        exit(1);
+    }
 
     virtual void transportInterrupted() {
         std::cout &lt;&lt; <span class="code-quote">"The Connection's Transport
has been Interrupted."</span> &lt;&lt; std::endl;
@@ -630,24 +635,9 @@ using namespace std;
 </span>    <span class="code-comment">//
 </span>    <span class="code-comment">//  http://activemq.apache.org/cms/
 </span>    <span class="code-comment">//
-</span>    <span class="code-comment">// Wire Format Options:
-</span>    <span class="code-comment">// =====================
-</span>    <span class="code-comment">// Use either stomp or openwire, the <span
class="code-keyword">default</span> ports are different <span class="code-keyword">for</span>
each
-</span>    <span class="code-comment">//
-</span>    <span class="code-comment">// Examples:
-</span>    <span class="code-comment">//    tcp://127.0.0.1:61616           
          <span class="code-keyword">default</span> to openwire
-</span>    <span class="code-comment">//    tcp://127.0.0.1:61616?wireFormat=openwire
 same as above
-</span>    <span class="code-comment">//    tcp://127.0.0.1:61613?wireFormat=stomp
    use stomp instead
-</span>    <span class="code-comment">//
 </span>    std::string brokerURI =
-        <span class="code-quote">"failover:(tcp:<span class="code-comment">//127.0.0.1:61616"</span>
-</span><span class="code-comment">//        <span class="code-quote">"?wireFormat=openwire"</span>
-</span><span class="code-comment">//        <span class="code-quote">"&amp;connection.useAsyncSend=<span
class="code-keyword">true</span>"</span>
-</span><span class="code-comment">//        <span class="code-quote">"&amp;transport.commandTracingEnabled=<span
class="code-keyword">true</span>"</span>
-</span><span class="code-comment">//        <span class="code-quote">"&amp;transport.tcpTracingEnabled=<span
class="code-keyword">true</span>"</span>
-</span><span class="code-comment">//        <span class="code-quote">"&amp;wireFormat.tightEncodingEnabled=<span
class="code-keyword">true</span>"</span>
-</span>        <span class="code-quote">")"</span>;
-
+        <span class="code-quote">"failover:(tcp:<span class="code-comment">//127.0.0.1:61616)"</span>;
+</span>
     <span class="code-comment">//============================================================
 </span>    <span class="code-comment">// This is the Destination Name and URI
options.  Use <span class="code-keyword">this</span> to
 </span>    <span class="code-comment">// customize where the consumer listens,
to have the consumer
@@ -758,22 +748,24 @@ using namespace std;
     std::string brokerURI;
     std::string destURI;
 
+<span class="code-keyword">private</span>:
+
+    SimpleProducer( <span class="code-keyword">const</span> SimpleProducer&amp;
);
+    SimpleProducer&amp; <span class="code-keyword">operator</span>= ( <span
class="code-keyword">const</span> SimpleProducer&amp; );
+
 <span class="code-keyword">public</span>:
 
-    SimpleProducer( <span class="code-keyword">const</span> std::string&amp;
brokerURI,
-                    unsigned <span class="code-object">int</span> numMessages,
-                    <span class="code-keyword">const</span> std::string&amp;
destURI,
-                    bool useTopic = <span class="code-keyword">false</span>,
-                    bool clientAck = <span class="code-keyword">false</span>
){
-        connection = NULL;
-        session = NULL;
-        destination = NULL;
-        producer = NULL;
-        <span class="code-keyword">this</span>-&gt;numMessages = numMessages;
-        <span class="code-keyword">this</span>-&gt;useTopic = useTopic;
-        <span class="code-keyword">this</span>-&gt;brokerURI = brokerURI;
-        <span class="code-keyword">this</span>-&gt;destURI = destURI;
-        <span class="code-keyword">this</span>-&gt;clientAck = clientAck;
+    SimpleProducer( <span class="code-keyword">const</span> std::string&amp;
brokerURI, unsigned <span class="code-object">int</span> numMessages,
+                    <span class="code-keyword">const</span> std::string&amp;
destURI, bool useTopic = <span class="code-keyword">false</span>, bool clientAck
= <span class="code-keyword">false</span> ) :
+        connection(NULL),
+        session(NULL),
+        destination(NULL),
+        producer(NULL),
+        useTopic(useTopic),
+        clientAck(clientAck),
+        numMessages(numMessages),
+        brokerURI(brokerURI),
+        destURI(destURI) {
     }
 
     virtual ~SimpleProducer(){
@@ -786,6 +778,7 @@ using namespace std;
 
     virtual void run() {
         <span class="code-keyword">try</span> {
+
             <span class="code-comment">// Create a ConnectionFactory
 </span>            auto_ptr&lt;ActiveMQConnectionFactory&gt; connectionFactory(
                 <span class="code-keyword">new</span> ActiveMQConnectionFactory(
brokerURI ) );
@@ -818,7 +811,7 @@ using namespace std;
             producer-&gt;setDeliveryMode( DeliveryMode::NON_PERSISTENT );
 
             <span class="code-comment">// Create the <span class="code-object">Thread</span>
Id <span class="code-object">String</span>
-</span>            string threadIdStr = <span class="code-object">Long</span>::toString(
<span class="code-object">Thread</span>::getId() );
+</span>            string threadIdStr = <span class="code-object">Long</span>::toString(
<span class="code-object">Thread</span>::currentThread()-&gt;getId() );
 
             <span class="code-comment">// Create a messages
 </span>            string text = (string)<span class="code-quote">"Hello world!
from thread "</span> + threadIdStr;
@@ -889,24 +882,9 @@ using namespace std;
 </span>    <span class="code-comment">//
 </span>    <span class="code-comment">//  http://activemq.apache.org/cms/
 </span>    <span class="code-comment">//
-</span>    <span class="code-comment">// Wire Format Options:
-</span>    <span class="code-comment">// =====================
-</span>    <span class="code-comment">// Use either stomp or openwire, the <span
class="code-keyword">default</span> ports are different <span class="code-keyword">for</span>
each
-</span>    <span class="code-comment">//
-</span>    <span class="code-comment">// Examples:
-</span>    <span class="code-comment">//    tcp://127.0.0.1:61616           
          <span class="code-keyword">default</span> to openwire
-</span>    <span class="code-comment">//    tcp://127.0.0.1:61616?wireFormat=openwire
 same as above
-</span>    <span class="code-comment">//    tcp://127.0.0.1:61613?wireFormat=stomp
    use stomp instead
-</span>    <span class="code-comment">//
 </span>    std::string brokerURI =
-        <span class="code-quote">"failover:(tcp:<span class="code-comment">//127.0.0.1:61616"</span>
-</span><span class="code-comment">//        <span class="code-quote">"?wireFormat=openwire"</span>
-</span><span class="code-comment">//        <span class="code-quote">"&amp;connection.useAsyncSend=<span
class="code-keyword">true</span>"</span>
-</span><span class="code-comment">//        <span class="code-quote">"&amp;transport.commandTracingEnabled=<span
class="code-keyword">true</span>"</span>
-</span><span class="code-comment">//        <span class="code-quote">"&amp;transport.tcpTracingEnabled=<span
class="code-keyword">true</span>"</span>
-</span><span class="code-comment">//        <span class="code-quote">"&amp;wireFormat.tightEncodingEnabled=<span
class="code-keyword">true</span>"</span>
-</span>        <span class="code-quote">")"</span>;
-
+        <span class="code-quote">"failover:<span class="code-comment">//(tcp://127.0.0.1:61616)"</span>;
+</span>
     <span class="code-comment">//============================================================
 </span>    <span class="code-comment">// Total number of messages <span class="code-keyword">for</span>
<span class="code-keyword">this</span> producer to send.
 </span>    <span class="code-comment">//============================================================
@@ -928,8 +906,12 @@ using namespace std;
 
     <span class="code-comment">// Create the producer and run it.
 </span>    SimpleProducer producer( brokerURI, numMessages, destURI, useTopics );
-    producer.run();
-    producer.close();
+
+    <span class="code-comment">// Publish the given number of Messages
+</span>    producer.run();
+
+    <span class="code-comment">// Before exiting we ensure that all CMS resources are
closed.
+</span>    producer.close();
 
     std::cout &lt;&lt; <span class="code-quote">"-----------------------------------------------------\n"</span>;
     std::cout &lt;&lt; <span class="code-quote">"Finished with the example."</span>
&lt;&lt; std::endl;

Modified: websites/production/activemq/content/cms/example.html
==============================================================================
--- websites/production/activemq/content/cms/example.html (original)
+++ websites/production/activemq/content/cms/example.html Wed Apr 10 14:21:31 2013
@@ -99,11 +99,13 @@
 
 <span class="code-comment">// START SNIPPET: demo
 </span>
+#include &lt;activemq/library/ActiveMQCPP.h&gt;
 #include &lt;decaf/lang/<span class="code-object">Thread</span>.h&gt;
 #include &lt;decaf/lang/<span class="code-object">Runnable</span>.h&gt;
 #include &lt;decaf/util/concurrent/CountDownLatch.h&gt;
 #include &lt;decaf/lang/<span class="code-object">Integer</span>.h&gt;
-#include &lt;decaf/util/Date.h&gt;
+#include &lt;decaf/lang/<span class="code-object">Long</span>.h&gt;
+#include &lt;decaf/lang/<span class="code-object">System</span>.h&gt;
 #include &lt;activemq/core/ActiveMQConnectionFactory.h&gt;
 #include &lt;activemq/util/Config.h&gt;
 #include &lt;cms/Connection.h&gt;
@@ -114,6 +116,7 @@
 #include &lt;cms/ExceptionListener.h&gt;
 #include &lt;cms/MessageListener.h&gt;
 #include &lt;stdlib.h&gt;
+#include &lt;stdio.h&gt;
 #include &lt;iostream&gt;
 #include &lt;memory&gt;
 
@@ -136,108 +139,105 @@ class HelloWorldProducer : <span class="
     bool sessionTransacted;
     std::string brokerURI;
 
+<span class="code-keyword">private</span>:
+
+    HelloWorldProducer(<span class="code-keyword">const</span> HelloWorldProducer&amp;);
+    HelloWorldProducer&amp; <span class="code-keyword">operator</span>=(<span
class="code-keyword">const</span> HelloWorldProducer&amp;);
+
 <span class="code-keyword">public</span>:
 
-    HelloWorldProducer( <span class="code-keyword">const</span> std::string&amp;
brokerURI,
-                        <span class="code-object">int</span> numMessages,
-                        bool useTopic = <span class="code-keyword">false</span>,
-                        bool sessionTransacted = <span class="code-keyword">false</span>
){
-        <span class="code-keyword">this</span>-&gt;connection = NULL;
-        <span class="code-keyword">this</span>-&gt;session = NULL;
-        <span class="code-keyword">this</span>-&gt;destination = NULL;
-        <span class="code-keyword">this</span>-&gt;producer = NULL;
-        <span class="code-keyword">this</span>-&gt;numMessages = numMessages;
-        <span class="code-keyword">this</span>-&gt;useTopic = useTopic;
-        <span class="code-keyword">this</span>-&gt;sessionTransacted = sessionTransacted;
-        <span class="code-keyword">this</span>-&gt;brokerURI = brokerURI;
+    HelloWorldProducer(<span class="code-keyword">const</span> std::string&amp;
brokerURI, <span class="code-object">int</span> numMessages, bool useTopic = <span
class="code-keyword">false</span>, bool sessionTransacted = <span class="code-keyword">false</span>)
:
+        connection(NULL),
+        session(NULL),
+        destination(NULL),
+        producer(NULL),
+        numMessages(numMessages),
+        useTopic(useTopic),
+        sessionTransacted(sessionTransacted),
+        brokerURI(brokerURI) {
     }
 
     virtual ~HelloWorldProducer(){
         cleanup();
     }
 
+    void close() {
+        <span class="code-keyword">this</span>-&gt;cleanup();
+    }
+
     virtual void run() {
 
         <span class="code-keyword">try</span> {
+
             <span class="code-comment">// Create a ConnectionFactory
 </span>            auto_ptr&lt;ConnectionFactory&gt; connectionFactory(
-                ConnectionFactory::createCMSConnectionFactory( brokerURI ) );
+                ConnectionFactory::createCMSConnectionFactory(brokerURI));
 
             <span class="code-comment">// Create a Connection
 </span>            connection = connectionFactory-&gt;createConnection();
             connection-&gt;start();
 
             <span class="code-comment">// Create a Session
-</span>            <span class="code-keyword">if</span>( <span class="code-keyword">this</span>-&gt;sessionTransacted
) {
-                session = connection-&gt;createSession( Session::SESSION_TRANSACTED );
+</span>            <span class="code-keyword">if</span> (<span class="code-keyword">this</span>-&gt;sessionTransacted)
{
+                session = connection-&gt;createSession(Session::SESSION_TRANSACTED);
             } <span class="code-keyword">else</span> {
-                session = connection-&gt;createSession( Session::AUTO_ACKNOWLEDGE );
+                session = connection-&gt;createSession(Session::AUTO_ACKNOWLEDGE);
             }
 
             <span class="code-comment">// Create the destination (Topic or Queue)
-</span>            <span class="code-keyword">if</span>( useTopic ) {
-                destination = session-&gt;createTopic( <span class="code-quote">"TEST.FOO"</span>
);
+</span>            <span class="code-keyword">if</span> (useTopic) {
+                destination = session-&gt;createTopic(<span class="code-quote">"TEST.FOO"</span>);
             } <span class="code-keyword">else</span> {
-                destination = session-&gt;createQueue( <span class="code-quote">"TEST.FOO"</span>
);
+                destination = session-&gt;createQueue(<span class="code-quote">"TEST.FOO"</span>);
             }
 
             <span class="code-comment">// Create a MessageProducer from the Session
to the Topic or Queue
-</span>            producer = session-&gt;createProducer( destination );
-            producer-&gt;setDeliveryMode( DeliveryMode::NON_PERSISTENT );
+</span>            producer = session-&gt;createProducer(destination);
+            producer-&gt;setDeliveryMode(DeliveryMode::NON_PERSISTENT);
 
             <span class="code-comment">// Create the <span class="code-object">Thread</span>
Id <span class="code-object">String</span>
-</span>            string threadIdStr = <span class="code-object">Integer</span>::toString(
<span class="code-object">Thread</span>::getId() );
+</span>            string threadIdStr = <span class="code-object">Long</span>::toString(<span
class="code-object">Thread</span>::currentThread()-&gt;getId());
 
             <span class="code-comment">// Create a messages
-</span>            string text = (string)<span class="code-quote">"Hello world!
from thread "</span> + threadIdStr;
+</span>            string text = (string) <span class="code-quote">"Hello world!
from thread "</span> + threadIdStr;
 
-            <span class="code-keyword">for</span>( <span class="code-object">int</span>
ix=0; ix&lt;numMessages; ++ix ){
-                TextMessage* message = session-&gt;createTextMessage( text );
-
-                message-&gt;setIntProperty( <span class="code-quote">"<span
class="code-object">Integer</span>"</span>, ix );
-
-                <span class="code-comment">// Tell the producer to send the message
-</span>                printf( <span class="code-quote">"Sent message #%d from
thread %s\n"</span>, ix+1, threadIdStr.c_str() );
-                producer-&gt;send( message );
-
-                delete message;
+            <span class="code-keyword">for</span> (<span class="code-object">int</span>
ix = 0; ix &lt; numMessages; ++ix) {
+                std::auto_ptr&lt;TextMessage&gt; message(session-&gt;createTextMessage(text));
+                message-&gt;setIntProperty(<span class="code-quote">"<span class="code-object">Integer</span>"</span>,
ix);
+                printf(<span class="code-quote">"Sent message #%d from thread %s\n"</span>,
ix + 1, threadIdStr.c_str());
+                producer-&gt;send(message.get());
             }
 
-        }<span class="code-keyword">catch</span> ( CMSException&amp; e )
{
+        } <span class="code-keyword">catch</span> (CMSException&amp; e) {
             e.printStackTrace();
         }
     }
 
 <span class="code-keyword">private</span>:
 
-    void cleanup(){
+    void cleanup() {
+
+        <span class="code-keyword">if</span> (connection != NULL) {
+            <span class="code-keyword">try</span> {
+                connection-&gt;close();
+            } <span class="code-keyword">catch</span> (cms::CMSException&amp;
ex) {
+                ex.printStackTrace();
+            }
+        }
 
         <span class="code-comment">// Destroy resources.
-</span>        <span class="code-keyword">try</span>{
-            <span class="code-keyword">if</span>( destination != NULL ) delete
destination;
-        }<span class="code-keyword">catch</span> ( CMSException&amp; e )
{ e.printStackTrace(); }
-        destination = NULL;
-
-        <span class="code-keyword">try</span>{
-            <span class="code-keyword">if</span>( producer != NULL ) delete producer;
-        }<span class="code-keyword">catch</span> ( CMSException&amp; e )
{ e.printStackTrace(); }
-        producer = NULL;
-
-        <span class="code-comment">// Close open resources.
-</span>        <span class="code-keyword">try</span>{
-            <span class="code-keyword">if</span>( session != NULL ) session-&gt;close();
-            <span class="code-keyword">if</span>( connection != NULL ) connection-&gt;close();
-        }<span class="code-keyword">catch</span> ( CMSException&amp; e )
{ e.printStackTrace(); }
-
-        <span class="code-keyword">try</span>{
-            <span class="code-keyword">if</span>( session != NULL ) delete session;
-        }<span class="code-keyword">catch</span> ( CMSException&amp; e )
{ e.printStackTrace(); }
-        session = NULL;
-
-        <span class="code-keyword">try</span>{
-            <span class="code-keyword">if</span>( connection != NULL ) delete
connection;
-        }<span class="code-keyword">catch</span> ( CMSException&amp; e )
{ e.printStackTrace(); }
-        connection = NULL;
+</span>        <span class="code-keyword">try</span> {
+            delete destination;
+            destination = NULL;
+            delete producer;
+            producer = NULL;
+            delete session;
+            session = NULL;
+            delete connection;
+            connection = NULL;
+        } <span class="code-keyword">catch</span> (CMSException&amp; e) {
+            e.printStackTrace();
+        }
     }
 };
 
@@ -258,27 +258,34 @@ class HelloWorldConsumer : <span class="
     bool sessionTransacted;
     std::string brokerURI;
 
+<span class="code-keyword">private</span>:
+
+    HelloWorldConsumer(<span class="code-keyword">const</span> HelloWorldConsumer&amp;);
+    HelloWorldConsumer&amp; <span class="code-keyword">operator</span>=(<span
class="code-keyword">const</span> HelloWorldConsumer&amp;);
+
 <span class="code-keyword">public</span>:
 
-    HelloWorldConsumer( <span class="code-keyword">const</span> std::string&amp;
brokerURI,
-                        <span class="code-object">long</span> numMessages,
-                        bool useTopic = <span class="code-keyword">false</span>,
-                        bool sessionTransacted = <span class="code-keyword">false</span>,
-                        <span class="code-object">long</span> waitMillis = 30000
)
-                         : latch(1), doneLatch(numMessages){
-        <span class="code-keyword">this</span>-&gt;connection = NULL;
-        <span class="code-keyword">this</span>-&gt;session = NULL;
-        <span class="code-keyword">this</span>-&gt;destination = NULL;
-        <span class="code-keyword">this</span>-&gt;consumer = NULL;
-        <span class="code-keyword">this</span>-&gt;waitMillis = waitMillis;
-        <span class="code-keyword">this</span>-&gt;useTopic = useTopic;
-        <span class="code-keyword">this</span>-&gt;sessionTransacted = sessionTransacted;
-        <span class="code-keyword">this</span>-&gt;brokerURI = brokerURI;
+    HelloWorldConsumer(<span class="code-keyword">const</span> std::string&amp;
brokerURI, <span class="code-object">int</span> numMessages, bool useTopic = <span
class="code-keyword">false</span>, bool sessionTransacted = <span class="code-keyword">false</span>,
<span class="code-object">int</span> waitMillis = 30000) :
+        latch(1),
+        doneLatch(numMessages),
+        connection(NULL),
+        session(NULL),
+        destination(NULL),
+        consumer(NULL),
+        waitMillis(waitMillis),
+        useTopic(useTopic),
+        sessionTransacted(sessionTransacted),
+        brokerURI(brokerURI) {
     }
-    virtual ~HelloWorldConsumer(){
+
+    virtual ~HelloWorldConsumer() {
         cleanup();
     }
 
+    void close() {
+        <span class="code-keyword">this</span>-&gt;cleanup();
+    }
+
     void waitUntilReady() {
         latch.await();
     }
@@ -289,7 +296,7 @@ class HelloWorldConsumer : <span class="
 
             <span class="code-comment">// Create a ConnectionFactory
 </span>            auto_ptr&lt;ConnectionFactory&gt; connectionFactory(
-                ConnectionFactory::createCMSConnectionFactory( brokerURI ) );
+                ConnectionFactory::createCMSConnectionFactory(brokerURI));
 
             <span class="code-comment">// Create a Connection
 </span>            connection = connectionFactory-&gt;createConnection();
@@ -297,23 +304,23 @@ class HelloWorldConsumer : <span class="
             connection-&gt;setExceptionListener(<span class="code-keyword">this</span>);
 
             <span class="code-comment">// Create a Session
-</span>            <span class="code-keyword">if</span>( <span class="code-keyword">this</span>-&gt;sessionTransacted
== <span class="code-keyword">true</span> ) {
-                session = connection-&gt;createSession( Session::SESSION_TRANSACTED );
+</span>            <span class="code-keyword">if</span> (<span class="code-keyword">this</span>-&gt;sessionTransacted
== <span class="code-keyword">true</span>) {
+                session = connection-&gt;createSession(Session::SESSION_TRANSACTED);
             } <span class="code-keyword">else</span> {
-                session = connection-&gt;createSession( Session::AUTO_ACKNOWLEDGE );
+                session = connection-&gt;createSession(Session::AUTO_ACKNOWLEDGE);
             }
 
             <span class="code-comment">// Create the destination (Topic or Queue)
-</span>            <span class="code-keyword">if</span>( useTopic ) {
-                destination = session-&gt;createTopic( <span class="code-quote">"TEST.FOO"</span>
);
+</span>            <span class="code-keyword">if</span> (useTopic) {
+                destination = session-&gt;createTopic(<span class="code-quote">"TEST.FOO"</span>);
             } <span class="code-keyword">else</span> {
-                destination = session-&gt;createQueue( <span class="code-quote">"TEST.FOO"</span>
);
+                destination = session-&gt;createQueue(<span class="code-quote">"TEST.FOO"</span>);
             }
 
             <span class="code-comment">// Create a MessageConsumer from the Session
to the Topic or Queue
-</span>            consumer = session-&gt;createConsumer( destination );
+</span>            consumer = session-&gt;createConsumer(destination);
 
-            consumer-&gt;setMessageListener( <span class="code-keyword">this</span>
);
+            consumer-&gt;setMessageListener(<span class="code-keyword">this</span>);
 
             std::cout.flush();
             std::cerr.flush();
@@ -322,43 +329,39 @@ class HelloWorldConsumer : <span class="
 </span>            latch.countDown();
 
             <span class="code-comment">// Wait <span class="code-keyword">while</span>
asynchronous messages come in.
-</span>            doneLatch.await( waitMillis );
-
-        } <span class="code-keyword">catch</span>( CMSException&amp; e )
{
+</span>            doneLatch.await(waitMillis);
 
+        } <span class="code-keyword">catch</span> (CMSException&amp; e) {
             <span class="code-comment">// Indicate we are ready <span class="code-keyword">for</span>
messages.
 </span>            latch.countDown();
-
             e.printStackTrace();
         }
     }
 
     <span class="code-comment">// Called from the consumer since <span class="code-keyword">this</span>
class is a registered MessageListener.
-</span>    virtual void onMessage( <span class="code-keyword">const</span>
Message* message ){
+</span>    virtual void onMessage(<span class="code-keyword">const</span>
Message* message) {
 
         <span class="code-keyword">static</span> <span class="code-object">int</span>
count = 0;
 
-        <span class="code-keyword">try</span>
-        {
+        <span class="code-keyword">try</span> {
             count++;
-            <span class="code-keyword">const</span> TextMessage* textMessage
=
-                dynamic_cast&lt; <span class="code-keyword">const</span>
TextMessage* &gt;( message );
+            <span class="code-keyword">const</span> TextMessage* textMessage
= dynamic_cast&lt;<span class="code-keyword">const</span> TextMessage*&gt;
(message);
             string text = "";
 
-            <span class="code-keyword">if</span>( textMessage != NULL ) {
+            <span class="code-keyword">if</span> (textMessage != NULL) {
                 text = textMessage-&gt;getText();
             } <span class="code-keyword">else</span> {
                 text = <span class="code-quote">"NOT A TEXTMESSAGE!"</span>;
             }
 
-            printf( <span class="code-quote">"Message #%d Received: %s\n"</span>,
count, text.c_str() );
+            printf(<span class="code-quote">"Message #%d Received: %s\n"</span>,
count, text.c_str());
 
         } <span class="code-keyword">catch</span> (CMSException&amp; e) {
             e.printStackTrace();
         }
 
         <span class="code-comment">// Commit all messages.
-</span>        <span class="code-keyword">if</span>( <span class="code-keyword">this</span>-&gt;sessionTransacted
) {
+</span>        <span class="code-keyword">if</span> (<span class="code-keyword">this</span>-&gt;sessionTransacted)
{
             session-&gt;commit();
         }
 
@@ -368,56 +371,48 @@ class HelloWorldConsumer : <span class="
 
     <span class="code-comment">// If something bad happens you see it here as <span
class="code-keyword">this</span> class is also been
 </span>    <span class="code-comment">// registered as an ExceptionListener with
the connection.
-</span>    virtual void onException( <span class="code-keyword">const</span>
CMSException&amp; ex AMQCPP_UNUSED) {
+</span>    virtual void onException(<span class="code-keyword">const</span>
CMSException&amp; ex AMQCPP_UNUSED) {
         printf(<span class="code-quote">"CMS Exception occurred.  Shutting down client.\n"</span>);
+        ex.printStackTrace();
         exit(1);
     }
 
 <span class="code-keyword">private</span>:
 
-    void cleanup(){
+    void cleanup() {
+        <span class="code-keyword">if</span> (connection != NULL) {
+            <span class="code-keyword">try</span> {
+                connection-&gt;close();
+            } <span class="code-keyword">catch</span> (cms::CMSException&amp;
ex) {
+                ex.printStackTrace();
+            }
+        }
 
-        <span class="code-comment">//*************************************************
-</span>        <span class="code-comment">// Always close destination, consumers
and producers before
-</span>        <span class="code-comment">// you destroy their sessions and connection.
-</span>        <span class="code-comment">//*************************************************
-</span>
         <span class="code-comment">// Destroy resources.
-</span>        <span class="code-keyword">try</span>{
-            <span class="code-keyword">if</span>( destination != NULL ) delete
destination;
-        }<span class="code-keyword">catch</span> (CMSException&amp; e) {
e.printStackTrace(); }
-        destination = NULL;
-
-        <span class="code-keyword">try</span>{
-            <span class="code-keyword">if</span>( consumer != NULL ) delete consumer;
-        }<span class="code-keyword">catch</span> (CMSException&amp; e) {
e.printStackTrace(); }
-        consumer = NULL;
-
-        <span class="code-comment">// Close open resources.
-</span>        <span class="code-keyword">try</span>{
-            <span class="code-keyword">if</span>( session != NULL ) session-&gt;close();
-            <span class="code-keyword">if</span>( connection != NULL ) connection-&gt;close();
-        }<span class="code-keyword">catch</span> (CMSException&amp; e) {
e.printStackTrace(); }
-
-        <span class="code-comment">// Now Destroy them
-</span>        <span class="code-keyword">try</span>{
-            <span class="code-keyword">if</span>( session != NULL ) delete session;
-        }<span class="code-keyword">catch</span> (CMSException&amp; e) {
e.printStackTrace(); }
-        session = NULL;
-
-        <span class="code-keyword">try</span>{
-            <span class="code-keyword">if</span>( connection != NULL ) delete
connection;
-        }<span class="code-keyword">catch</span> (CMSException&amp; e) {
e.printStackTrace(); }
-        connection = NULL;
+</span>        <span class="code-keyword">try</span> {
+            delete destination;
+            destination = NULL;
+            delete consumer;
+            consumer = NULL;
+            delete session;
+            session = NULL;
+            delete connection;
+            connection = NULL;
+        } <span class="code-keyword">catch</span> (CMSException&amp; e) {
+            e.printStackTrace();
+        }
     }
 };
 
 <span class="code-object">int</span> main(<span class="code-object">int</span>
argc AMQCPP_UNUSED, <span class="code-object">char</span>* argv[] AMQCPP_UNUSED)
{
 
+    activemq::library::ActiveMQCPP::initializeLibrary();
+    {
     std::cout &lt;&lt; <span class="code-quote">"=====================================================\n"</span>;
     std::cout &lt;&lt; <span class="code-quote">"Starting the example:"</span>
&lt;&lt; std::endl;
     std::cout &lt;&lt; <span class="code-quote">"-----------------------------------------------------\n"</span>;
 
+
     <span class="code-comment">// Set the URI to point to the IP Address of your broker.
 </span>    <span class="code-comment">// add any optional params to the url to
enable things like
 </span>    <span class="code-comment">// tightMarshalling or tcp logging etc.
 See the CMS web site <span class="code-keyword">for</span>
@@ -426,24 +421,32 @@ class HelloWorldConsumer : <span class="
 </span>    <span class="code-comment">//  http://activemq.apache.org/cms/
 </span>    <span class="code-comment">//
 </span>    <span class="code-comment">// Wire Format Options:
-</span>    <span class="code-comment">// =====================
+</span>    <span class="code-comment">// =========================
 </span>    <span class="code-comment">// Use either stomp or openwire, the <span
class="code-keyword">default</span> ports are different <span class="code-keyword">for</span>
each
 </span>    <span class="code-comment">//
 </span>    <span class="code-comment">// Examples:
 </span>    <span class="code-comment">//    tcp://127.0.0.1:61616           
          <span class="code-keyword">default</span> to openwire
-</span>    <span class="code-comment">//    tcp://127.0.0.1:61616?wireFormat=openwire
 same as above
 </span>    <span class="code-comment">//    tcp://127.0.0.1:61613?wireFormat=stomp
    use stomp instead
 </span>    <span class="code-comment">//
+</span>    <span class="code-comment">// SSL:
+</span>    <span class="code-comment">// =========================
+</span>    <span class="code-comment">// To use SSL you need to specify the location
of the trusted Root CA or the
+</span>    <span class="code-comment">// certificate <span class="code-keyword">for</span>
the broker you want to connect to.  Using the Root CA allows
+</span>    <span class="code-comment">// you to use failover with multiple servers
all using certificates signed by
+</span>    <span class="code-comment">// the trusted root.  If using client authentication
you also need to specify
+</span>    <span class="code-comment">// the location of the client Certificate.
+</span>    <span class="code-comment">//
+</span>    <span class="code-comment">//     <span class="code-object">System</span>::setProperty(
<span class="code-quote">"decaf.net.ssl.keyStore"</span>, <span class="code-quote">"&lt;path&gt;/client.pem"</span>
);
+</span>    <span class="code-comment">//     <span class="code-object">System</span>::setProperty(
<span class="code-quote">"decaf.net.ssl.keyStorePassword"</span>, <span class="code-quote">"password"</span>
);
+</span>    <span class="code-comment">//     <span class="code-object">System</span>::setProperty(
<span class="code-quote">"decaf.net.ssl.trustStore"</span>, <span class="code-quote">"&lt;path&gt;/rootCA.pem"</span>
);
+</span>    <span class="code-comment">//
+</span>    <span class="code-comment">// The you just specify the ssl transport
in the URI, <span class="code-keyword">for</span> example:
+</span>    <span class="code-comment">//
+</span>    <span class="code-comment">//     ssl://localhost:61617
+</span>    <span class="code-comment">//
 </span>    std::string brokerURI =
-        <span class="code-quote">"tcp:<span class="code-comment">//127.1.0.1:61616"</span>
-</span>        <span class="code-quote">"?wireFormat=openwire"</span>
-<span class="code-comment">//        <span class="code-quote">"&amp;connection.alwaysSyncSend=<span
class="code-keyword">true</span>"</span>
-</span><span class="code-comment">//        <span class="code-quote">"&amp;connection.useAsyncSend=<span
class="code-keyword">true</span>"</span>
-</span><span class="code-comment">//        <span class="code-quote">"&amp;transport.commandTracingEnabled=<span
class="code-keyword">true</span>"</span>
-</span><span class="code-comment">//        <span class="code-quote">"&amp;transport.tcpTracingEnabled=<span
class="code-keyword">true</span>"</span>
-</span><span class="code-comment">//        <span class="code-quote">"&amp;wireFormat.tightEncodingEnabled=<span
class="code-keyword">true</span>"</span>
-</span>        ;
-
+        <span class="code-quote">"failover:(tcp:<span class="code-comment">//localhost:61616)"</span>;
+</span>
     <span class="code-comment">//============================================================
 </span>    <span class="code-comment">// set to <span class="code-keyword">true</span>
to use topics instead of queues
 </span>    <span class="code-comment">// Note in the code above that <span
class="code-keyword">this</span> causes createTopic or
@@ -453,36 +456,43 @@ class HelloWorldConsumer : <span class="
     bool sessionTransacted = <span class="code-keyword">false</span>;
     <span class="code-object">int</span> numMessages = 2000;
 
-    <span class="code-object">long</span> <span class="code-object">long</span>
startTime = Date::getCurrentTimeMilliseconds();
+    <span class="code-object">long</span> <span class="code-object">long</span>
startTime = <span class="code-object">System</span>::currentTimeMillis();
 
-    HelloWorldProducer producer( brokerURI, numMessages, useTopics );
-    HelloWorldConsumer consumer( brokerURI, numMessages, useTopics, sessionTransacted );
+    HelloWorldProducer producer(brokerURI, numMessages, useTopics);
+        HelloWorldConsumer consumer(brokerURI, numMessages, useTopics, sessionTransacted);
 
     <span class="code-comment">// Start the consumer thread.
-</span>    <span class="code-object">Thread</span> consumerThread( &amp;consumer
);
+</span>    <span class="code-object">Thread</span> consumerThread(&amp;consumer);
     consumerThread.start();
 
     <span class="code-comment">// Wait <span class="code-keyword">for</span>
the consumer to indicate that its ready to go.
 </span>    consumer.waitUntilReady();
 
     <span class="code-comment">// Start the producer thread.
-</span>    <span class="code-object">Thread</span> producerThread( &amp;producer
);
+</span>    <span class="code-object">Thread</span> producerThread(&amp;producer);
     producerThread.start();
 
     <span class="code-comment">// Wait <span class="code-keyword">for</span>
the threads to complete.
 </span>    producerThread.join();
     consumerThread.join();
 
-    <span class="code-object">long</span> <span class="code-object">long</span>
endTime = Date::getCurrentTimeMilliseconds();
-    <span class="code-object">double</span> totalTime = (endTime - startTime)
/ 1000.0;
+    <span class="code-object">long</span> <span class="code-object">long</span>
endTime = <span class="code-object">System</span>::currentTimeMillis();
+    <span class="code-object">double</span> totalTime = (<span class="code-object">double</span>)(endTime
- startTime) / 1000.0;
+
+    consumer.close();
+    producer.close();
 
     std::cout &lt;&lt; <span class="code-quote">"Time to completion = "</span>
&lt;&lt; totalTime &lt;&lt; <span class="code-quote">" seconds."</span>
&lt;&lt; std::endl;
     std::cout &lt;&lt; <span class="code-quote">"-----------------------------------------------------\n"</span>;
     std::cout &lt;&lt; <span class="code-quote">"Finished with the example."</span>
&lt;&lt; std::endl;
     std::cout &lt;&lt; <span class="code-quote">"=====================================================\n"</span>;
+
+    }
+    activemq::library::ActiveMQCPP::shutdownLibrary();
 }
 
-<span class="code-comment">// END SNIPPET: demo</span>
+<span class="code-comment">// END SNIPPET: demo
+</span>
 </pre>
 </div></div>
           </div>



Mime
View raw message