activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r588708 - in /activemq/activemq-cpp/trunk/src/examples: consumers/SimpleAsyncConsumer.cpp producers/SimpleProducer.cpp
Date Fri, 26 Oct 2007 16:58:06 GMT
Author: tabish
Date: Fri Oct 26 09:58:03 2007
New Revision: 588708

URL: http://svn.apache.org/viewvc?rev=588708&view=rev
Log:
Adding more examples for the CPP client, this is a simple async consumer example and a simple
producer.

Modified:
    activemq/activemq-cpp/trunk/src/examples/consumers/SimpleAsyncConsumer.cpp
    activemq/activemq-cpp/trunk/src/examples/producers/SimpleProducer.cpp

Modified: activemq/activemq-cpp/trunk/src/examples/consumers/SimpleAsyncConsumer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/examples/consumers/SimpleAsyncConsumer.cpp?rev=588708&r1=588707&r2=588708&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/examples/consumers/SimpleAsyncConsumer.cpp (original)
+++ activemq/activemq-cpp/trunk/src/examples/consumers/SimpleAsyncConsumer.cpp Fri Oct 26
09:58:03 2007
@@ -49,6 +49,7 @@
     Destination* destination;
     MessageConsumer* consumer;
     bool useTopic;
+    bool clientAck;
     std::string brokerURI;
     std::string destURI;
 
@@ -56,7 +57,8 @@
 
     SimpleAsyncConsumer( const std::string& brokerURI,
                          const std::string& destURI,
-                         bool useTopic = false ) {
+                         bool useTopic = false,
+                         bool clientAck = false ) {
         connection = NULL;
         session = NULL;
         destination = NULL;
@@ -64,6 +66,7 @@
         this->useTopic = useTopic;
         this->brokerURI = brokerURI;
         this->destURI = destURI;
+        this->clientAck = clientAck;
     }
 
     virtual ~SimpleAsyncConsumer(){
@@ -86,7 +89,11 @@
             connection->setExceptionListener(this);
 
             // Create a Session
-            session = connection->createSession( Session::AUTO_ACKNOWLEDGE );
+            if( clientAck ) {
+                session = connection->createSession( Session::CLIENT_ACKNOWLEDGE );
+            } else {
+                session = connection->createSession( Session::AUTO_ACKNOWLEDGE );
+            }
 
             // Create the destination (Topic or Queue)
             if( useTopic ) {
@@ -122,6 +129,10 @@
                 text = "NOT A TEXTMESSAGE!";
             }
 
+            if( clientAck ) {
+                message->acknowledge();
+            }
+
             printf( "Message #%d Received: %s\n", count, text.c_str() );
         } catch (CMSException& e) {
             e.printStackTrace();
@@ -199,10 +210,10 @@
     std::string brokerURI =
         "tcp://127.0.0.1:61616"
         "?wireFormat=openwire"
-        "&transport.useAsyncSend=true";
+        "&transport.useAsyncSend=true"
 //        "&transport.commandTracingEnabled=true"
 //        "&transport.tcpTracingEnabled=true";
-//        "&wireFormat.tightEncodingEnabled=true";
+        "&wireFormat.tightEncodingEnabled=true";
 
     //============================================================
     // This is the Destination Name and URI options.  Use this to
@@ -216,10 +227,16 @@
     // Note in the code above that this causes createTopic or
     // createQueue to be used in the consumer.
     //============================================================
-    bool useTopics = true;
+    bool useTopics = false;
+
+    //============================================================
+    // set to true if you want the consumer to use client ack mode
+    // instead of the default auto ack mode.
+    //============================================================
+    bool clientAck = false;
 
     // Create the consumer
-    SimpleAsyncConsumer consumer( brokerURI, destURI, useTopics );
+    SimpleAsyncConsumer consumer( brokerURI, destURI, useTopics, clientAck );
 
     // Start it up and it will listen forever.
     consumer.runConsumer();

Modified: activemq/activemq-cpp/trunk/src/examples/producers/SimpleProducer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/examples/producers/SimpleProducer.cpp?rev=588708&r1=588707&r2=588708&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/examples/producers/SimpleProducer.cpp (original)
+++ activemq/activemq-cpp/trunk/src/examples/producers/SimpleProducer.cpp Fri Oct 26 09:58:03
2007
@@ -48,6 +48,7 @@
     Destination* destination;
     MessageProducer* producer;
     bool useTopic;
+    bool clientAck;
     unsigned int numMessages;
     std::string brokerURI;
     std::string destURI;
@@ -57,7 +58,8 @@
     SimpleProducer( const std::string& brokerURI,
                     unsigned int numMessages,
                     const std::string& destURI,
-                    bool useTopic = false ){
+                    bool useTopic = false,
+                    bool clientAck = false ){
         connection = NULL;
         session = NULL;
         destination = NULL;
@@ -66,6 +68,7 @@
         this->useTopic = useTopic;
         this->brokerURI = brokerURI;
         this->destURI = destURI;
+        this->clientAck = clientAck;
     }
 
     virtual ~SimpleProducer(){
@@ -86,7 +89,11 @@
             delete connectionFactory;
 
             // Create a Session
-            session = connection->createSession( Session::AUTO_ACKNOWLEDGE );
+            if( clientAck ) {
+                session = connection->createSession( Session::CLIENT_ACKNOWLEDGE );
+            } else {
+                session = connection->createSession( Session::AUTO_ACKNOWLEDGE );
+            }
 
             // Create the destination (Topic or Queue)
             if( useTopic ) {
@@ -181,15 +188,15 @@
     std::string brokerURI =
         "tcp://127.0.0.1:61616"
         "?wireFormat=openwire"
-        "&transport.useAsyncSend=true";
+        "&transport.useAsyncSend=true"
 //        "&transport.commandTracingEnabled=true"
 //        "&transport.tcpTracingEnabled=true";
-//        "&wireFormat.tightEncodingEnabled=true";
+        "&wireFormat.tightEncodingEnabled=true";
 
     //============================================================
     // Total number of messages for this producer to send.
     //============================================================
-    unsigned int numMessages = 32730;
+    unsigned int numMessages = 2000;
 
     //============================================================
     // This is the Destination Name and URI options.  Use this to
@@ -203,7 +210,7 @@
     // Note in the code above that this causes createTopic or
     // createQueue to be used in the producer.
     //============================================================
-    bool useTopics = true;
+    bool useTopics = false;
 
     // Create the producer and run it.
     SimpleProducer producer( brokerURI, numMessages, destURI, useTopics );



Mime
View raw message