Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 1960 invoked from network); 26 Oct 2007 16:58:31 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 26 Oct 2007 16:58:31 -0000 Received: (qmail 58675 invoked by uid 500); 26 Oct 2007 16:58:18 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 58620 invoked by uid 500); 26 Oct 2007 16:58:18 -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 58611 invoked by uid 99); 26 Oct 2007 16:58:18 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 26 Oct 2007 09:58:18 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 26 Oct 2007 16:58:30 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 0978E1A9832; Fri, 26 Oct 2007 09:58:07 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@activemq.apache.org From: tabish@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071026165807.0978E1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 );