You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2009/06/15 23:47:23 UTC
svn commit: r784996 - in
/activemq/activemq-cpp/trunk/activemq-cpp/src/examples: ./ advisories/
Author: tabish
Date: Mon Jun 15 21:47:23 2009
New Revision: 784996
URL: http://svn.apache.org/viewvc?rev=784996&view=rev
Log:
Add another AdvisoryMessage example to show how to handle embedded command objects.
Added:
activemq/activemq-cpp/trunk/activemq-cpp/src/examples/advisories/TempDestinationAdvisoryConsumer.cpp (with props)
activemq/activemq-cpp/trunk/activemq-cpp/src/examples/advisories/TempDestinationAdvisoryConsumer.h (with props)
activemq/activemq-cpp/trunk/activemq-cpp/src/examples/advisories/TempDestinationAdvisoryConsumerMain.cpp (with props)
activemq/activemq-cpp/trunk/activemq-cpp/src/examples/advisories/TempDestinationAdvisoryProducerMain.cpp (with props)
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/examples/Makefile.am
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/examples/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/examples/Makefile.am?rev=784996&r1=784995&r2=784996&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/examples/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/examples/Makefile.am Mon Jun 15 21:47:23 2009
@@ -63,3 +63,18 @@
advisory_consumer_SOURCES = $(advisory_consumer_sources)
advisory_consumer_LDADD= $(AMQ_TEST_LIBS)
advisory_consumer_CXXFLAGS = $(AMQ_TEST_CXXFLAGS) -I$(srcdir)/../main
+
+## Temp Destination Advisory Consumer Example
+tempdest_advisory_consumer_sources = advisories/TempDestinationAdvisoryConsumer.cpp \
+ advisories/TempDestinationAdvisoryConsumerMain.cpp
+noinst_PROGRAMS += tempdest_advisory_consumer
+tempdest_advisory_consumer_SOURCES = $(tempdest_advisory_consumer_sources)
+tempdest_advisory_consumer_LDADD= $(AMQ_TEST_LIBS)
+tempdest_advisory_consumer_CXXFLAGS = $(AMQ_TEST_CXXFLAGS) -I$(srcdir)/../main
+
+## Temp Destination Advisory Producer Example
+tempdest_advisory_producer_sources = advisories/TempDestinationAdvisoryProducerMain.cpp
+noinst_PROGRAMS += tempdest_advisory_producer
+tempdest_advisory_producer_SOURCES = $(tempdest_advisory_producer_sources)
+tempdest_advisory_producer_LDADD= $(AMQ_TEST_LIBS)
+tempdest_advisory_producer_CXXFLAGS = $(AMQ_TEST_CXXFLAGS) -I$(srcdir)/../main
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/examples/advisories/TempDestinationAdvisoryConsumer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/examples/advisories/TempDestinationAdvisoryConsumer.cpp?rev=784996&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/examples/advisories/TempDestinationAdvisoryConsumer.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/examples/advisories/TempDestinationAdvisoryConsumer.cpp Mon Jun 15 21:47:23 2009
@@ -0,0 +1,106 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "TempDestinationAdvisoryConsumer.h"
+
+#include <cms/Topic.h>
+#include <cms/Message.h>
+#include <cms/TextMessage.h>
+#include <activemq/core/ActiveMQConstants.h>
+#include <activemq/commands/ActiveMQMessage.h>
+#include <activemq/commands/DestinationInfo.h>
+#include <decaf/lang/exceptions/NullPointerException.h>
+#include <decaf/lang/exceptions/ClassCastException.h>
+#include <decaf/lang/Integer.h>
+
+using namespace std;
+using namespace activemqcpp;
+using namespace activemqcpp::examples;
+using namespace activemqcpp::examples::advisories;
+using namespace activemq;
+using namespace activemq::commands;
+using namespace activemq::core;
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+TempDestinationAdvisoryConsumer::TempDestinationAdvisoryConsumer( cms::Session* session ) {
+
+ if( session == NULL ) {
+ throw NullPointerException(
+ __FILE__, __LINE__, "Session Object passed was Null." );
+ }
+
+ std::auto_ptr<cms::Topic> advisories( session->createTopic(
+ "ActiveMQ.Advisory.TempTopic,ActiveMQ.Advisory.TempQueue" ) );
+
+ this->session = session;
+ this->consumer.reset( session->createConsumer( advisories.get() ) );
+ this->consumer->setMessageListener( this );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+TempDestinationAdvisoryConsumer::~TempDestinationAdvisoryConsumer() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void TempDestinationAdvisoryConsumer::onMessage( const cms::Message* message ) {
+
+ if( message->getCMSType() == "Advisory" ) {
+
+ std::cout << "Received an Advisory Message!" << std::endl;
+
+ const ActiveMQMessage* amqMessage =
+ dynamic_cast<const ActiveMQMessage*>( message );
+
+ if( amqMessage != NULL && amqMessage->getDataStructure() != NULL ) {
+ std::cout << "Advisory Message contains a Command Object!" << std::endl;
+
+ try {
+
+ Pointer<DestinationInfo> info =
+ amqMessage->getDataStructure().dynamicCast<DestinationInfo>();
+
+ unsigned char operationType = info->getOperationType();
+
+ if( operationType == ActiveMQConstants::DESTINATION_REMOVE_OPERATION ) {
+ std::cout << "Temporary Destination {"
+ << info->getDestination()->getPhysicalName()
+ << "} Removed."
+ << std::endl;
+ } else if( operationType == ActiveMQConstants::DESTINATION_ADD_OPERATION ) {
+ std::cout << "Temporary Destination {"
+ << info->getDestination()->getPhysicalName()
+ << "} Added."
+ << std::endl;
+ } else {
+ std::cout << "ERROR: I have no Idea what just happened!"
+ << std::endl;
+ }
+
+ } catch( ClassCastException& ex ) {
+ std::cout << "ERROR: Expected the Command to be a DestinationInfo, "
+ << "it wasn't so PANIC!!"
+ << std::endl;
+ }
+ }
+
+ } else {
+ std::cout << "Received a Non-Advisory Message!" << std::endl;
+ }
+}
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/examples/advisories/TempDestinationAdvisoryConsumer.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/examples/advisories/TempDestinationAdvisoryConsumer.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/examples/advisories/TempDestinationAdvisoryConsumer.h?rev=784996&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/examples/advisories/TempDestinationAdvisoryConsumer.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/examples/advisories/TempDestinationAdvisoryConsumer.h Mon Jun 15 21:47:23 2009
@@ -0,0 +1,60 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _ACTIVEMQCPP_EXAMPLES_ADVISORIES_TEMPDESTINATIONADVISORYCONSUMER_H_
+#define _ACTIVEMQCPP_EXAMPLES_ADVISORIES_TEMPDESTINATIONADVISORYCONSUMER_H_
+
+#include <string>
+#include <memory>
+
+#include <cms/Session.h>
+#include <cms/MessageProducer.h>
+#include <cms/MessageConsumer.h>
+#include <cms/MessageListener.h>
+
+#include <decaf/lang/Runnable.h>
+
+namespace activemqcpp {
+namespace examples {
+namespace advisories {
+
+ /**
+ * Monitors a Broker for Temporary Topic creation and destruction.
+ *
+ * @since 3.0
+ */
+ class TempDestinationAdvisoryConsumer : public cms::MessageListener {
+ private:
+
+ cms::Session* session;
+ std::auto_ptr<cms::MessageConsumer> consumer;
+
+ public:
+
+ TempDestinationAdvisoryConsumer( cms::Session* session );
+ virtual ~TempDestinationAdvisoryConsumer();
+
+ /**
+ * Async Message callback.
+ */
+ virtual void onMessage( const cms::Message* message );
+
+ };
+
+}}}
+
+#endif /* _ACTIVEMQCPP_EXAMPLES_ADVISORIES_TEMPDESTINATIONADVISORYCONSUMER_H_ */
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/examples/advisories/TempDestinationAdvisoryConsumer.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/examples/advisories/TempDestinationAdvisoryConsumerMain.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/examples/advisories/TempDestinationAdvisoryConsumerMain.cpp?rev=784996&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/examples/advisories/TempDestinationAdvisoryConsumerMain.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/examples/advisories/TempDestinationAdvisoryConsumerMain.cpp Mon Jun 15 21:47:23 2009
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "TempDestinationAdvisoryConsumer.h"
+
+#include <activemq/library/ActiveMQCPP.h>
+#include <cms/ConnectionFactory.h>
+#include <cms/Connection.h>
+#include <cms/Session.h>
+#include <stdlib.h>
+#include <iostream>
+#include <memory>
+
+using namespace activemqcpp::examples::advisories;
+using namespace cms;
+using namespace std;
+
+////////////////////////////////////////////////////////////////////////////////
+int main( int argc AMQCPP_UNUSED, char* argv[] AMQCPP_UNUSED ) {
+
+ // We must always init the library first before using any methods in it.
+ activemq::library::ActiveMQCPP::initializeLibrary();
+
+ std::cout << "=====================================================\n";
+ std::cout << "Starting the example:" << std::endl;
+ std::cout << "-----------------------------------------------------\n";
+
+ // Set the URI to point to the IPAddress of your broker.
+ // add any optional params to the url to enable things like
+ // tightMarshalling or tcp logging etc. See the CMS web site for
+ // a full list of configuration options.
+ //
+ // http://activemq.apache.org/cms/
+ //
+ std::string brokerURI = "failover:(tcp://127.0.0.1:61616)";
+
+ // Create the Connection
+ auto_ptr<cms::ConnectionFactory> connectionFactory(
+ cms::ConnectionFactory::createCMSConnectionFactory( brokerURI ) );
+
+ auto_ptr<cms::Connection> connection;
+
+ // Create a Connection
+ try{
+ connection.reset( connectionFactory->createConnection() );
+ } catch( CMSException& e ) {
+ e.printStackTrace();
+ return 1;
+ }
+
+ // Create the Session
+ std::auto_ptr<cms::Session> session( connection->createSession() );
+
+ // Create the Advisory Consumer and run it.
+ TempDestinationAdvisoryConsumer advisoryConsumer( session.get() );
+
+ // Start the Connection now.
+ connection->start();
+
+ // Wait until we are told to quit.
+ std::cout << "Press 'q' to quit" << std::endl;
+ while( std::cin.get() != 'q') {}
+
+ // Shutdown now
+ connection->stop();
+
+ std::cout << "-----------------------------------------------------\n";
+ std::cout << "Finished with the example." << std::endl;
+ std::cout << "=====================================================\n";
+
+ // We must also always remember to shut down the Library when done.
+ activemq::library::ActiveMQCPP::shutdownLibrary();
+
+ return 0;
+}
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/examples/advisories/TempDestinationAdvisoryConsumerMain.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/examples/advisories/TempDestinationAdvisoryProducerMain.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/examples/advisories/TempDestinationAdvisoryProducerMain.cpp?rev=784996&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/examples/advisories/TempDestinationAdvisoryProducerMain.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/examples/advisories/TempDestinationAdvisoryProducerMain.cpp Mon Jun 15 21:47:23 2009
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <decaf/lang/Thread.h>
+#include <decaf/lang/Runnable.h>
+#include <activemq/library/ActiveMQCPP.h>
+#include <cms/ConnectionFactory.h>
+#include <cms/Connection.h>
+#include <cms/Session.h>
+#include <cms/Destination.h>
+#include <stdlib.h>
+#include <iostream>
+#include <memory>
+
+using namespace decaf;
+using namespace decaf::lang;
+using namespace cms;
+using namespace std;
+
+////////////////////////////////////////////////////////////////////////////////
+int main( int argc AMQCPP_UNUSED, char* argv[] AMQCPP_UNUSED ) {
+
+ // We must always init the library first before using any methods in it.
+ activemq::library::ActiveMQCPP::initializeLibrary();
+
+ std::cout << "=====================================================\n";
+ std::cout << "Starting the example:" << std::endl;
+ std::cout << "-----------------------------------------------------\n";
+
+ // Set the URI to point to the IPAddress of your broker.
+ // add any optional params to the url to enable things like
+ // tightMarshalling or tcp logging etc. See the CMS web site for
+ // a full list of configuration options.
+ //
+ // http://activemq.apache.org/cms/
+ //
+ std::string brokerURI = "failover:(tcp://127.0.0.1:61616)";
+
+ // Create the Connection
+ auto_ptr<cms::ConnectionFactory> connectionFactory(
+ cms::ConnectionFactory::createCMSConnectionFactory( brokerURI ) );
+
+ auto_ptr<cms::Connection> connection;
+
+ // Create a Connection
+ try{
+ connection.reset( connectionFactory->createConnection() );
+ } catch( CMSException& e ) {
+ e.printStackTrace();
+ return 1;
+ }
+
+ // Create the Session
+ std::auto_ptr<cms::Session> session( connection->createSession() );
+
+ // Start the Connection now.
+ connection->start();
+
+ // Create a Temporary Topic and Queue.
+ std::auto_ptr<cms::Destination> tempTopic( session->createTemporaryTopic() );
+ std::auto_ptr<cms::Destination> tempQueue( session->createTemporaryQueue() );
+
+ // Give the Broker some time
+ Thread::sleep( 2000 );
+
+ // Shutdown now
+ connection->stop();
+
+ std::cout << "-----------------------------------------------------\n";
+ std::cout << "Finished with the example." << std::endl;
+ std::cout << "=====================================================\n";
+
+ // We must also always remember to shut down the Library when done.
+ activemq::library::ActiveMQCPP::shutdownLibrary();
+
+ return 0;
+}
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/examples/advisories/TempDestinationAdvisoryProducerMain.cpp
------------------------------------------------------------------------------
svn:eol-style = native