You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2006/11/14 03:12:37 UTC
svn commit: r474626 [2/7] - /incubator/activemq/site/
Modified: incubator/activemq/site/cms.html
URL: http://svn.apache.org/viewvc/incubator/activemq/site/cms.html?view=diff&rev=474626&r1=474625&r2=474626
==============================================================================
--- incubator/activemq/site/cms.html (original)
+++ incubator/activemq/site/cms.html Mon Nov 13 18:12:35 2006
@@ -272,6 +272,7 @@
#include <cms/ExceptionListener.h>
#include <cms/MessageListener.h>
#include <stdlib.h>
+#include <iostream>
using namespace activemq::core;
using namespace activemq::util;
@@ -281,27 +282,29 @@
class HelloWorldProducer : <SPAN class="code-keyword">public</SPAN> <SPAN class="code-object">Runnable</SPAN> {
<SPAN class="code-keyword">private</SPAN>:
-
- Connection* connection;
- Session* session;
- Destination* destination;
- MessageProducer* producer;
- <SPAN class="code-object">int</SPAN> numMessages;
+
+ Connection* connection;
+ Session* session;
+ Destination* destination;
+ MessageProducer* producer;
+ <SPAN class="code-object">int</SPAN> numMessages;
+ bool useTopic;
<SPAN class="code-keyword">public</SPAN>:
-
- HelloWorldProducer( <SPAN class="code-object">int</SPAN> numMessages ){
- connection = NULL;
- session = NULL;
- destination = NULL;
- producer = NULL;
- <SPAN class="code-keyword">this</SPAN>->numMessages = numMessages;
- }
-
- virtual ~HelloWorldProducer(){
- cleanup();
- }
-
+
+ HelloWorldProducer( <SPAN class="code-object">int</SPAN> numMessages, bool useTopic = <SPAN class="code-keyword">false</SPAN> ){
+ connection = NULL;
+ session = NULL;
+ destination = NULL;
+ producer = NULL;
+ <SPAN class="code-keyword">this</SPAN>->numMessages = numMessages;
+ <SPAN class="code-keyword">this</SPAN>->useTopic = useTopic;
+ }
+
+ virtual ~HelloWorldProducer(){
+ cleanup();
+ }
+
virtual void run() {
<SPAN class="code-keyword">try</SPAN> {
<SPAN class="code-comment">// Create a ConnectionFactory
@@ -315,7 +318,11 @@
</SPAN> session = connection->createSession( Session::AUTO_ACKNOWLEDGE );
<SPAN class="code-comment">// Create the destination (Topic or Queue)
-</SPAN> destination = session->createQueue( <SPAN class="code-quote">"TEST.FOO"</SPAN> );
+</SPAN> <SPAN class="code-keyword">if</SPAN>( useTopic ) {
+ destination = session->createTopic( <SPAN class="code-quote">"TEST.FOO"</SPAN> );
+ } <SPAN class="code-keyword">else</SPAN> {
+ destination = session->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->createProducer( destination );
@@ -328,15 +335,15 @@
</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<numMessages; ++ix ){
- TextMessage* message = session->createTextMessage( text );
+ TextMessage* message = session->createTextMessage( text );
- <SPAN class="code-comment">// Tell the producer to send the message
-</SPAN> printf( <SPAN class="code-quote">"Sent message from thread %s\n"</SPAN>, threadIdStr.c_str() );
- producer->send( message );
-
- delete message;
+ <SPAN class="code-comment">// Tell the producer to send the message
+</SPAN> printf( <SPAN class="code-quote">"Sent message from thread %s\n"</SPAN>, threadIdStr.c_str() );
+ producer->send( message );
+
+ delete message;
}
-
+
}<SPAN class="code-keyword">catch</SPAN> ( CMSException& e ) {
e.printStackTrace();
}
@@ -345,63 +352,65 @@
<SPAN class="code-keyword">private</SPAN>:
void cleanup(){
-
- <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& e ) {}
- 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& e ) {}
- 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->close();
- <SPAN class="code-keyword">if</SPAN>( connection != NULL ) connection->close();
- }<SPAN class="code-keyword">catch</SPAN> ( CMSException& e ) {}
-
- <SPAN class="code-keyword">try</SPAN>{
- <SPAN class="code-keyword">if</SPAN>( session != NULL ) delete session;
- }<SPAN class="code-keyword">catch</SPAN> ( CMSException& e ) {}
- session = NULL;
-
+
+ <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& e ) {}
+ 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& e ) {}
+ 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->close();
+ <SPAN class="code-keyword">if</SPAN>( connection != NULL ) connection->close();
+ }<SPAN class="code-keyword">catch</SPAN> ( CMSException& e ) {}
+
+ <SPAN class="code-keyword">try</SPAN>{
+ <SPAN class="code-keyword">if</SPAN>( session != NULL ) delete session;
+ }<SPAN class="code-keyword">catch</SPAN> ( CMSException& e ) {}
+ 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& e ) {}
- connection = NULL;
+ <SPAN class="code-keyword">if</SPAN>( connection != NULL ) delete connection;
+ }<SPAN class="code-keyword">catch</SPAN> ( CMSException& e ) {}
+ connection = NULL;
}
};
class HelloWorldConsumer : <SPAN class="code-keyword">public</SPAN> ExceptionListener,
<SPAN class="code-keyword">public</SPAN> MessageListener,
<SPAN class="code-keyword">public</SPAN> <SPAN class="code-object">Runnable</SPAN> {
-
+
<SPAN class="code-keyword">private</SPAN>:
-
- Connection* connection;
- Session* session;
- Destination* destination;
- MessageConsumer* consumer;
- <SPAN class="code-object">long</SPAN> waitMillis;
-
+
+ Connection* connection;
+ Session* session;
+ Destination* destination;
+ MessageConsumer* consumer;
+ <SPAN class="code-object">long</SPAN> waitMillis;
+ bool useTopic;
+
<SPAN class="code-keyword">public</SPAN>:
- HelloWorldConsumer( <SPAN class="code-object">long</SPAN> waitMillis ){
- connection = NULL;
- session = NULL;
- destination = NULL;
- consumer = NULL;
- <SPAN class="code-keyword">this</SPAN>->waitMillis = waitMillis;
- }
- virtual ~HelloWorldConsumer(){
- cleanup();
+ HelloWorldConsumer( <SPAN class="code-object">long</SPAN> waitMillis, bool useTopic = <SPAN class="code-keyword">false</SPAN> ){
+ connection = NULL;
+ session = NULL;
+ destination = NULL;
+ consumer = NULL;
+ <SPAN class="code-keyword">this</SPAN>->waitMillis = waitMillis;
+ <SPAN class="code-keyword">this</SPAN>->useTopic = useTopic;
+ }
+ virtual ~HelloWorldConsumer(){
+ cleanup();
}
virtual void run() {
-
+
<SPAN class="code-keyword">try</SPAN> {
<SPAN class="code-comment">// Create a ConnectionFactory
@@ -419,7 +428,11 @@
</SPAN> session = connection->createSession( Session::AUTO_ACKNOWLEDGE );
<SPAN class="code-comment">// Create the destination (Topic or Queue)
-</SPAN> destination = session->createQueue( <SPAN class="code-quote">"TEST.FOO"</SPAN> );
+</SPAN> <SPAN class="code-keyword">if</SPAN>( useTopic ) {
+ destination = session->createTopic( <SPAN class="code-quote">"TEST.FOO"</SPAN> );
+ } <SPAN class="code-keyword">else</SPAN> {
+ destination = session->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->createConsumer( destination );
@@ -427,79 +440,109 @@
consumer->setMessageListener( <SPAN class="code-keyword">this</SPAN> );
<SPAN class="code-comment">// Sleep <SPAN class="code-keyword">while</SPAN> asynchronous messages come in.
-</SPAN> <SPAN class="code-object">Thread</SPAN>::sleep( waitMillis );
+</SPAN> <SPAN class="code-object">Thread</SPAN>::sleep( waitMillis );
} <SPAN class="code-keyword">catch</SPAN> (CMSException& e) {
e.printStackTrace();
}
}
- virtual void onMessage( <SPAN class="code-keyword">const</SPAN> Message* message ){
-
+ <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 class="code-keyword">static</SPAN> <SPAN class="code-object">int</SPAN> count = 0;
+
<SPAN class="code-keyword">try</SPAN>
{
- <SPAN class="code-keyword">const</SPAN> TextMessage* textMessage =
+ count++;
+ <SPAN class="code-keyword">const</SPAN> TextMessage* textMessage =
dynamic_cast< <SPAN class="code-keyword">const</SPAN> TextMessage* >( message );
string text = textMessage->getText();
- printf( <SPAN class="code-quote">"Received: %s\n"</SPAN>, 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& e) {
e.printStackTrace();
}
}
- virtual void onException( <SPAN class="code-keyword">const</SPAN> CMSException& ex ) {
+ <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& ex ) {
printf(<SPAN class="code-quote">"JMS Exception occured. Shutting down client.\n"</SPAN>);
}
<SPAN class="code-keyword">private</SPAN>:
void cleanup(){
-
- <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& e) {}
- destination = NULL;
-
- <SPAN class="code-keyword">try</SPAN>{
+
+ <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& e) {}
+ 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& e) {}
- 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->close();
- <SPAN class="code-keyword">if</SPAN>( connection != NULL ) connection->close();
- }<SPAN class="code-keyword">catch</SPAN> (CMSException& e) {}
-
+ }<SPAN class="code-keyword">catch</SPAN> (CMSException& e) {}
+ 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->close();
+ <SPAN class="code-keyword">if</SPAN>( connection != NULL ) connection->close();
+ }<SPAN class="code-keyword">catch</SPAN> (CMSException& e) {}
+
+ <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& e) {}
+ session = NULL;
+
<SPAN class="code-keyword">try</SPAN>{
- <SPAN class="code-keyword">if</SPAN>( session != NULL ) delete session;
- }<SPAN class="code-keyword">catch</SPAN> (CMSException& e) {}
- 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& e) {}
- connection = NULL;
+ <SPAN class="code-keyword">if</SPAN>( connection != NULL ) delete connection;
+ }<SPAN class="code-keyword">catch</SPAN> (CMSException& e) {}
+ connection = NULL;
}
};
<SPAN class="code-object">int</SPAN> main(<SPAN class="code-object">int</SPAN> argc, <SPAN class="code-object">char</SPAN>* argv[]) {
+
+ std::cout << <SPAN class="code-quote">"=====================================================\n"</SPAN>;
+ std::cout << <SPAN class="code-quote">"Starting the example:"</SPAN> << std::endl;
+ std::cout << <SPAN class="code-quote">"-----------------------------------------------------\n"</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
+</SPAN> <SPAN class="code-comment">// createQueue to be used in both consumer an producer.
+</SPAN> <SPAN class="code-comment">//============================================================
+</SPAN> bool useTopics = <SPAN class="code-keyword">false</SPAN>;
+
+ HelloWorldProducer producer( 1000, useTopics );
+ HelloWorldConsumer consumer( 8000, useTopics );
+
+ <SPAN class="code-comment">// Start the consumer thread.
+</SPAN> <SPAN class="code-object">Thread</SPAN> consumerThread( &consumer );
+ consumerThread.start();
- HelloWorldProducer producer( 1000 );
- HelloWorldConsumer consumer( 5000 );
-
- <SPAN class="code-comment">// Start the consumer thread.
-</SPAN> <SPAN class="code-object">Thread</SPAN> consumerThread( &consumer );
- consumerThread.start();
-
- <SPAN class="code-comment">// Start the producer thread.
-</SPAN> <SPAN class="code-object">Thread</SPAN> producerThread( &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-comment">// Start the producer thread.
+</SPAN> <SPAN class="code-object">Thread</SPAN> producerThread( &producer );
+ producerThread.start();
+
+ <SPAN class="code-comment">// Wait <SPAN class="code-keyword">for</SPAN> the threads to complete.
+</SPAN> producerThread.join();
+ consumerThread.join();
+
+ std::cout << <SPAN class="code-quote">"-----------------------------------------------------\n"</SPAN>;
+ std::cout << <SPAN class="code-quote">"Finished with the example, ignore errors from <SPAN class="code-keyword">this</SPAN>"</SPAN>
+ << std::endl
+ << <SPAN class="code-quote">"point on as the sockets breaks when we shutdown."</SPAN>
+ << std::endl;
+ std::cout << <SPAN class="code-quote">"=====================================================\n"</SPAN>;
}</PRE>
</DIV></DIV></DIV>
Modified: incubator/activemq/site/connectivity.html
URL: http://svn.apache.org/viewvc/incubator/activemq/site/connectivity.html?view=diff&rev=474626&r1=474625&r2=474626
==============================================================================
--- incubator/activemq/site/connectivity.html (original)
+++ incubator/activemq/site/connectivity.html Mon Nov 13 18:12:35 2006
@@ -41,7 +41,7 @@
</TD>
<TD align="right" valign="middle" nowrap="">
<DIV id="site-quicklinks">
-<P><A href="downloa2.html" title="Downloa2">Downloa2</A> | <SPAN class="nobr"><A href="http://incubator.apache.org/activemq/maven/activemq-core/apidocs/" title="Visit page outside Confluence" rel="nofollow">JavaDocs<SUP><IMG class="rendericon" src="http://goopen.org/confluence/images/icons/linkext7.gif" height="0" width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN> <A href="javadocs.html" title="JavaDocs">More...</A> | <A href="source.html" title="Source">Source</A> | <A href="site.html" title="Site">Wiki</A> |<SPAN class="nobr"><A href="irc://irc.codehaus.org/activemq" title="Visit page outside Confluence" rel="nofollow">IRC<SUP><IMG class="rendericon" src="http://goopen.org/confluence/images/icons/linkext7.gif" height="0" width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN> | <SPAN class="nobr"><A href="http://servlet.uwyn.com/drone/log/hausbot/activemq" title="Visit page outside Confluence" rel="nofollow">IRC Log<SUP><IMG cl
ass="rendericon" src="http://goopen.org/confluence/images/icons/linkext7.gif" height="0" width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN> | <A href="mailing-lists.html" title="Mailing Lists">Mailing Lists</A> | <A href="discussion-forums.html" title="Discussion Forums">Discussion Forums</A> | <A href="support.html" title="Support">Support</A></P>
+<P><A href="download.html" title="Download">Download</A> | <SPAN class="nobr"><A href="http://incubator.apache.org/activemq/maven/activemq-core/apidocs/" title="Visit page outside Confluence" rel="nofollow">JavaDocs<SUP><IMG class="rendericon" src="http://goopen.org/confluence/images/icons/linkext7.gif" height="0" width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN> <A href="javadocs.html" title="JavaDocs">More...</A> | <A href="source.html" title="Source">Source</A> | <A href="site.html" title="Site">Wiki</A> |<SPAN class="nobr"><A href="irc://irc.codehaus.org/activemq" title="Visit page outside Confluence" rel="nofollow">IRC<SUP><IMG class="rendericon" src="http://goopen.org/confluence/images/icons/linkext7.gif" height="0" width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN> | <SPAN class="nobr"><A href="http://servlet.uwyn.com/drone/log/hausbot/activemq" title="Visit page outside Confluence" rel="nofollow">IRC Log<SUP><IMG cl
ass="rendericon" src="http://goopen.org/confluence/images/icons/linkext7.gif" height="0" width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN> | <A href="mailing-lists.html" title="Mailing Lists">Mailing Lists</A> | <A href="discussion-forums.html" title="Discussion Forums">Discussion Forums</A> | <A href="support.html" title="Support">Support</A></P>
</DIV>
</TD>
</TR>
@@ -74,7 +74,7 @@
<LI><A href="faq.html" title="FAQ">FAQ</A></LI>
<LI><A href="site.html" title="Site">Site</A></LI>
<LI><A href="articles.html" title="Articles">Articles</A></LI>
- <LI><A href="downloa2.html" title="Downloa2">Downloa2</A></LI>
+ <LI><A href="download.html" title="Download">Download</A></LI>
</UL>