Author: nmittler
Date: Sun Aug 13 16:01:56 2006
New Revision: 431268
URL: http://svn.apache.org/viewvc?rev=431268&view=rev
Log:
AMQ-874 - updating example on the wiki for basic activemq-cpp usage
Added:
incubator/activemq/trunk/activemq-cpp/src/examples/examples.vcproj
Modified:
incubator/activemq/trunk/activemq-cpp/src/examples/main.cpp
Added: incubator/activemq/trunk/activemq-cpp/src/examples/examples.vcproj
URL:
http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/examples/examples.vcproj?rev=431268&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/examples/examples.vcproj (added)
+++ incubator/activemq/trunk/activemq-cpp/src/examples/examples.vcproj Sun Aug
13 16:01:56 2006
@@ -0,0 +1,205 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="examples"
+ ProjectGUID="{5830D72A-1239-45B7-B94E-04153B2D4EA4}"
+ RootNamespace="examples"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="1"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories=""D:\Program
Files\Microsoft Platform
SDK\Include";"E:\Eclipse\ActiveMQ\activemq-cpp\src\main";"E:\dev\cppunit-1.11.6\include";"E:\Eclipse\ActiveMQ\activemq-cpp\src\test""
+
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="2"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="activemq-cpp.lib
ws2_32.lib cppunitd.lib rpcrt4.lib"
+ LinkIncremental="2"
+
AdditionalLibraryDirectories=""E:\dev\cppunit-1.11.6\lib";"D:\Program
Files\Microsoft Platform
SDK\Lib";"E:\Eclipse\ActiveMQ\activemq-cpp\src\main\Debug""
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="1"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+ RuntimeLibrary="2"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="kernel32.lib
$(NoInherit)"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+ >
+ <File
+ RelativePath=".\main.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+ >
+ </Filter>
+ <Filter
+ Name="Resource Files"
+
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+ >
+ </Filter>
+ <File
+ RelativePath=".\ReadMe.txt"
+ >
+ </File>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
Modified: incubator/activemq/trunk/activemq-cpp/src/examples/main.cpp
URL:
http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/examples/main.cpp?rev=431268&r1=431267&r2=431268&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/examples/main.cpp (original)
+++ incubator/activemq/trunk/activemq-cpp/src/examples/main.cpp Sun Aug 13
16:01:56 2006
@@ -1,243 +1,243 @@
-
-// START SNIPPET: demo
-
-#include <activemq/concurrent/Thread.h>
-#include <activemq/concurrent/Runnable.h>
-#include <activemq/core/ActiveMQConnectionFactory.h>
-#include <cms/Connection.h>
-#include <cms/Session.h>
-#include <cms/TextMessage.h>
-#include <cms/ExceptionListener.h>
-#include <cms/MessageListener.h>
-#include <stdlib.h>
-
-using namespace activemq::core;
-using namespace activemq::concurrent;
-using namespace cms;
-using namespace std;
-
-class HelloWorldProducer : public Runnable {
-private:
-
- Connection* connection;
- Session* session;
- Destination* destination;
- MessageProducer* producer;
- int numMessages;
-
-public:
-
- HelloWorldProducer( int numMessages ){
- connection = NULL;
- session = NULL;
- destination = NULL;
- producer = NULL;
- this->numMessages = numMessages;
- }
-
- virtual ~HelloWorldProducer(){
- cleanup();
- }
-
- virtual void run() {
- try {
- // Create a ConnectionFactory
- ActiveMQConnectionFactory* connectionFactory = new
ActiveMQConnectionFactory("tcp://127.0.0.1:61613");
-
- // Create a Connection
- connection = connectionFactory->createConnection();
- connection->start();
-
- // Create a Session
- session = connection->createSession( Session::AutoAcknowledge );
-
- // Create the destination (Topic or Queue)
- destination = session->createQueue("TEST.FOO");
-
- // Create a MessageProducer from the Session to the Topic or Queue
- producer = session->createProducer(*destination);
- producer->setDeliveryMode( Message::NONPERSISTANT);
-
- // Stringify the thread id
- char threadIdStr[100];
- itoa( Thread::getId(), threadIdStr, 10 );
-
- // Create a messages
- string text = (string)"Hello world! from thread " + threadIdStr;
-
- for( int ix=0; ix<numMessages; ++ix ){
- TextMessage* message = session->createTextMessage( text );
-
- // Tell the producer to send the message
- printf( "Sent message from thread %s\n", threadIdStr );
- producer->send(*message);
-
- delete message;
- }
-
- }catch (CMSException& e) {
- e.printStackTrace();
- }
- }
-
-private:
-
- void cleanup(){
-
- // Close open resources.
- try{
- if( session != NULL ) session->close();
- if( connection != NULL ) connection->close();
- }catch (CMSException& e) {}
-
- // Destroy resources.
- try{
- if( destination != NULL ) delete destination;
- }catch (CMSException& e) {}
- destination = NULL;
-
- try{
- if( producer != NULL ) delete producer;
- }catch (CMSException& e) {}
- producer = NULL;
-
- try{
- if( session != NULL ) delete session;
- }catch (CMSException& e) {}
- session = NULL;
-
- try{
- if( connection != NULL ) delete connection;
- }catch (CMSException& e) {}
- connection = NULL;
- }
-};
-
-class HelloWorldConsumer : public ExceptionListener,
- public MessageListener,
- public Runnable {
-
-private:
-
- Connection* connection;
- Session* session;
- Destination* destination;
- MessageConsumer* consumer;
- long waitMillis;
-
-public:
-
- HelloWorldConsumer( long waitMillis ){
- connection = NULL;
- session = NULL;
- destination = NULL;
- consumer = NULL;
- this->waitMillis = waitMillis;
- }
- virtual ~HelloWorldConsumer(){
- cleanup();
- }
-
- virtual void run() {
-
- try {
-
- // Create a ConnectionFactory
- ActiveMQConnectionFactory* connectionFactory = new
ActiveMQConnectionFactory("tcp://127.0.0.1:61613");
-
- // Create a Connection
- connection = connectionFactory->createConnection();
- delete connectionFactory;
- connection->start();
-
- connection->setExceptionListener(this);
-
- // Create a Session
- session = connection->createSession( Session::AutoAcknowledge );
-
- // Create the destination (Topic or Queue)
- destination = session->createQueue("TEST.FOO");
-
- // Create a MessageConsumer from the Session to the Topic or Queue
- consumer = session->createConsumer(*destination);
-
- consumer->setMessageListener( this );
-
- // Sleep while asynchronous messages come in.
- Thread::sleep( waitMillis );
-
- } catch (CMSException& e) {
- e.printStackTrace();
- }
- }
-
- virtual void onMessage( const Message& message ){
-
- try
- {
- const TextMessage& textMessage = dynamic_cast<const
TextMessage&>(message);
- string text = textMessage.getText();
- printf( "Received: %s\n", text.c_str() );
- }
- catch( std::bad_cast& ex )
- {
- printf( "Received something other than a text Message\n" );
- }
- }
-
- virtual void onException( const CMSException& ex ) {
- printf("JMS Exception occured. Shutting down client.\n");
- }
-
-private:
-
- void cleanup(){
-
- // Close open resources.
- try{
- if( session != NULL ) session->close();
- if( connection != NULL ) connection->close();
- }catch (CMSException& e) {}
-
- // Destroy resources.
- try{
- if( destination != NULL ) delete destination;
- }catch (CMSException& e) {}
- destination = NULL;
-
- try{
- if( consumer != NULL ) delete consumer;
- }catch (CMSException& e) {}
- consumer = NULL;
-
- try{
- if( session != NULL ) delete session;
- }catch (CMSException& e) {}
- session = NULL;
-
- try{
- if( connection != NULL ) delete connection;
- }catch (CMSException& e) {}
- connection = NULL;
- }
-};
-
-void main(int argc, char* argv[]) {
-
- HelloWorldProducer producer( 1000 );
- HelloWorldConsumer consumer( 5000 );
-
- // Start the consumer thread.
- Thread consumerThread( &consumer );
- consumerThread.start();
-
- // Start the producer thread.
- Thread producerThread( &producer );
- producerThread.start();
-
- // Wait for the threads to complete.
- producerThread.join();
- consumerThread.join();
-}
-
-// END SNIPPET: demo
+
+// START SNIPPET: demo
+
+#include <activemq/concurrent/Thread.h>
+#include <activemq/concurrent/Runnable.h>
+#include <activemq/core/ActiveMQConnectionFactory.h>
+#include <cms/Connection.h>
+#include <cms/Session.h>
+#include <cms/TextMessage.h>
+#include <cms/ExceptionListener.h>
+#include <cms/MessageListener.h>
+#include <stdlib.h>
+
+using namespace activemq::core;
+using namespace activemq::concurrent;
+using namespace cms;
+using namespace std;
+
+class HelloWorldProducer : public Runnable {
+private:
+
+ Connection* connection;
+ Session* session;
+ Destination* destination;
+ MessageProducer* producer;
+ int numMessages;
+
+public:
+
+ HelloWorldProducer( int numMessages ){
+ connection = NULL;
+ session = NULL;
+ destination = NULL;
+ producer = NULL;
+ this->numMessages = numMessages;
+ }
+
+ virtual ~HelloWorldProducer(){
+ cleanup();
+ }
+
+ virtual void run() {
+ try {
+ // Create a ConnectionFactory
+ ActiveMQConnectionFactory* connectionFactory = new
ActiveMQConnectionFactory("tcp://127.0.0.1:61613");
+
+ // Create a Connection
+ connection = connectionFactory->createConnection();
+ connection->start();
+
+ // Create a Session
+ session = connection->createSession( Session::AUTO_ACKNOWLEDGE );
+
+ // Create the destination (Topic or Queue)
+ destination = session->createQueue( "TEST.FOO" );
+
+ // Create a MessageProducer from the Session to the Topic or Queue
+ producer = session->createProducer( destination );
+ producer->setDeliveryMode( DeliveryMode::NON_PERSISTANT );
+
+ // Stringify the thread id
+ char threadIdStr[100];
+ itoa( Thread::getId(), threadIdStr, 10 );
+
+ // Create a messages
+ string text = (string)"Hello world! from thread " + threadIdStr;
+
+ for( int ix=0; ix<numMessages; ++ix ){
+ TextMessage* message = session->createTextMessage( text );
+
+ // Tell the producer to send the message
+ printf( "Sent message from thread %s\n", threadIdStr );
+ producer->send( message );
+
+ delete message;
+ }
+
+ }catch ( CMSException& e ) {
+ e.printStackTrace();
+ }
+ }
+
+private:
+
+ void cleanup(){
+
+ // Destroy resources.
+ try{
+ if( destination != NULL ) delete destination;
+ }catch ( CMSException& e ) {}
+ destination = NULL;
+
+ try{
+ if( producer != NULL ) delete producer;
+ }catch ( CMSException& e ) {}
+ producer = NULL;
+
+ // Close open resources.
+ try{
+ if( session != NULL ) session->close();
+ if( connection != NULL ) connection->close();
+ }catch ( CMSException& e ) {}
+
+ try{
+ if( session != NULL ) delete session;
+ }catch ( CMSException& e ) {}
+ session = NULL;
+
+ try{
+ if( connection != NULL ) delete connection;
+ }catch ( CMSException& e ) {}
+ connection = NULL;
+ }
+};
+
+class HelloWorldConsumer : public ExceptionListener,
+ public MessageListener,
+ public Runnable {
+
+private:
+
+ Connection* connection;
+ Session* session;
+ Destination* destination;
+ MessageConsumer* consumer;
+ long waitMillis;
+
+public:
+
+ HelloWorldConsumer( long waitMillis ){
+ connection = NULL;
+ session = NULL;
+ destination = NULL;
+ consumer = NULL;
+ this->waitMillis = waitMillis;
+ }
+ virtual ~HelloWorldConsumer(){
+ cleanup();
+ }
+
+ virtual void run() {
+
+ try {
+
+ // Create a ConnectionFactory
+ ActiveMQConnectionFactory* connectionFactory =
+ new ActiveMQConnectionFactory( "tcp://127.0.0.1:61613" );
+
+ // Create a Connection
+ connection = connectionFactory->createConnection();
+ delete connectionFactory;
+ connection->start();
+
+ connection->setExceptionListener(this);
+
+ // Create a Session
+ session = connection->createSession( Session::AUTO_ACKNOWLEDGE );
+
+ // Create the destination (Topic or Queue)
+ destination = session->createQueue( "TEST.FOO" );
+
+ // Create a MessageConsumer from the Session to the Topic or Queue
+ consumer = session->createConsumer( destination );
+
+ consumer->setMessageListener( this );
+
+ // Sleep while asynchronous messages come in.
+ Thread::sleep( waitMillis );
+
+ } catch (CMSException& e) {
+ e.printStackTrace();
+ }
+ }
+
+ virtual void onMessage( const Message* message ){
+
+ try
+ {
+ const TextMessage* textMessage =
+ dynamic_cast< const TextMessage* >( message );
+ string text = textMessage->getText();
+ printf( "Received: %s\n", text.c_str() );
+ } catch (CMSException& e) {
+ e.printStackTrace();
+ }
+ }
+
+ virtual void onException( const CMSException& ex ) {
+ printf("JMS Exception occured. Shutting down client.\n");
+ }
+
+private:
+
+ void cleanup(){
+
+ // Destroy resources.
+ try{
+ if( destination != NULL ) delete destination;
+ }catch (CMSException& e) {}
+ destination = NULL;
+
+ try{
+ if( consumer != NULL ) delete consumer;
+ }catch (CMSException& e) {}
+ consumer = NULL;
+
+ // Close open resources.
+ try{
+ if( session != NULL ) session->close();
+ if( connection != NULL ) connection->close();
+ }catch (CMSException& e) {}
+
+ try{
+ if( session != NULL ) delete session;
+ }catch (CMSException& e) {}
+ session = NULL;
+
+ try{
+ if( connection != NULL ) delete connection;
+ }catch (CMSException& e) {}
+ connection = NULL;
+ }
+};
+
+void main(int argc, char* argv[]) {
+
+ HelloWorldProducer producer( 1000 );
+ HelloWorldConsumer consumer( 5000 );
+
+ // Start the consumer thread.
+ Thread consumerThread( &consumer );
+ consumerThread.start();
+
+ // Start the producer thread.
+ Thread producerThread( &producer );
+ producerThread.start();
+
+ // Wait for the threads to complete.
+ producerThread.join();
+ consumerThread.join();
+}
+
+// END SNIPPET: demo