Return-Path: Delivered-To: apmail-activemq-users-archive@www.apache.org Received: (qmail 85421 invoked from network); 17 Nov 2010 15:41:43 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 17 Nov 2010 15:41:43 -0000 Received: (qmail 32366 invoked by uid 500); 17 Nov 2010 15:42:08 -0000 Delivered-To: apmail-activemq-users-archive@activemq.apache.org Received: (qmail 31232 invoked by uid 500); 17 Nov 2010 15:42:06 -0000 Mailing-List: contact users-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@activemq.apache.org Delivered-To: mailing list users@activemq.apache.org Received: (qmail 31001 invoked by uid 99); 17 Nov 2010 15:42:05 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 17 Nov 2010 15:42:05 +0000 X-ASF-Spam-Status: No, hits=4.2 required=10.0 tests=HTML_MESSAGE,SPF_HELO_PASS,SPF_NEUTRAL,URI_HEX X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [216.139.236.158] (HELO kuber.nabble.com) (216.139.236.158) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 17 Nov 2010 15:41:59 +0000 Received: from joe.nabble.com ([192.168.236.151]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1PIk8g-0000V3-8f for users@activemq.apache.org; Wed, 17 Nov 2010 07:41:38 -0800 Date: Wed, 17 Nov 2010 07:41:38 -0800 (PST) From: jandeclercq To: users@activemq.apache.org Message-ID: In-Reply-To: <1290007857.2490.1.camel@office> References: <1289994967052-3046566.post@n4.nabble.com> <1290007857.2490.1.camel@office> Subject: RE: activemq-cpp-library-3.2.2 - reconnect fails MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_8825_14391284.1290008498264" X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_8825_14391284.1290008498264 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hey, Thank you thank you,.. you solved my problem ! It does make my architecture puzzle a lot bigger, but that is the fun in programming, isn't it? :-) (yes it is a lot bigger than the example I posted) Thanks! ________________________________________ Van: Timothy Bish [via ActiveMQ] [ml-node+3046971-419590077-202575@n4.nabble.com] Verzonden: woensdag 17 november 2010 16:31 Aan: Jan Declercq Onderwerp: Re: activemq-cpp-library-3.2.2 - reconnect fails On Wed, 2010-11-17 at 03:56 -0800, jandeclercq wrote: > Hey, > > When I disconnected and closed down a producer. And afterwards I'm trying to > reconnect, the cpp-library crashes. I don't know what I'm doing wrong. > > See the code below (choose option R) > > The problem most likely results from the fact that you are calling the library init and shutdown methods more than once per application run by placing them in the constructor and cleanup methods of the class. Try placing them in the main method at start and end. Regards > > #include > #include > #include > > #include > #include > #include > #include > #include > #include > #include > #include > #include > #include > #include > #include > #include > #include > #include > #include > #include > > using namespace activemq; > using namespace activemq::transport; > using namespace activemq::core; > using namespace decaf; > using namespace decaf::lang; > using namespace decaf::util; > using namespace decaf::util::concurrent; > using namespace cms; > using namespace std; > > using namespace std; > > class SimpleProducer: public ExceptionListener, public > DefaultTransportListener { > private: > > Connection* connection; > Session* session; > Destination* destination; > MessageProducer* producer; > bool useTopic; > bool clientAck; > std::string brokerURI; > std::string destURI; > bool isClosed; > > public: > SimpleProducer(const std::string& brokerURI, const std::string& destURI, > bool useTopic, bool clientAck) { > activemq::library::ActiveMQCPP::initializeLibrary(); > this->connection = NULL; > this->session = NULL; > this->destination = NULL; > this->producer = NULL; > this->useTopic = useTopic; > this->brokerURI = brokerURI; > this->destURI = destURI; > this->clientAck = clientAck; > this->isClosed = true; > } > > virtual ~SimpleProducer() { > close(); > } > > void close() { > if (!isClosed) { > isClosed = true; > this->cleanup(); > } > } > > virtual void connect() { > try { > try { > this->isClosed = false; > // Create a ConnectionFactory > ActiveMQConnectionFactory* connectionFactory = new > ActiveMQConnectionFactory(this->brokerURI); > // Create a Connection > this->connection = connectionFactory->createConnection(); > delete connectionFactory; > ActiveMQConnection* amqConnection = dynamic_cast > (connection); > if (amqConnection != NULL) { > amqConnection->addTransportListener(this); > } > //This will crash the 2nd time!: > this->connection->start(); > this->connection->setExceptionListener(this); > > } catch (Exception& e) { > throw e; > } > > // Create a Session > if (this->clientAck) { > this->session = connection->createSession(Session::CLIENT_ACKNOWLEDGE); > } else { > this->session = connection->createSession(Session::AUTO_ACKNOWLEDGE); > } > > // Create the destination (Topic or Queue) > if (this->useTopic) { > this->destination = this->session->createTopic(this->destURI); > } else { > this->destination = this->session->createQueue(this->destURI); > } > > // Create a MessageProducer from the Session to the Topic or Queue > this->producer = this->session->createProducer(this->destination); > > this->producer->setDeliveryMode(DeliveryMode::NON_PERSISTENT); > > fprintf(stdout, "Producer connected to %s", this->brokerURI.c_str()); > fflush(stdout); > > } catch (CMSException& e) { > fprintf(stdout, e.getMessage().c_str()); > fflush(stdout); > } > } > > virtual void send(const char *msg) { > try { > > string text(msg); > TextMessage* message = this->session->createTextMessage(text); > > char logMessage[256]; > > this->producer->send(message); > > //logging: > sprintf(logMessage, "Message '%s' send to serviceBus", msg); > > //end logging > delete message; > } catch (CMSException& e) { > fprintf(stdout, e.getMessage().c_str()); > fflush(stdout); > } > } > //Exception Listener > virtual void onException(const CMSException& ex AMQCPP_UNUSED ) { > fprintf(stdout, "!! CMS lib Exception occured !!"); > fflush(stdout); > } > //Transport Listener > virtual void transportInterrupted() { > fprintf(stdout, "The Connection's Transport has been Interrupted."); > fflush(stdout); > } > virtual void transportResumed() { > fprintf(stdout, "The Connection's Transport has been Restored."); > fflush(stdout); > } > private: > > void cleanup() { > //Producer > try { > if (producer != NULL) { > producer->close(); > delete producer; > } > } catch (CMSException& e) { > fprintf(stdout, e.getMessage().c_str()); > fflush(stdout); > > } > producer = NULL; > > // Destination > try { > if (destination != NULL) { > delete destination; > } > } catch (CMSException& e) { > fprintf(stdout, e.getMessage().c_str()); > fflush(stdout); > } > destination = NULL; > > //SESSION > try { > if (session != NULL) { > session->close(); > delete session; > } > } catch (Exception& e) { > fprintf(stdout, e.getMessage().c_str()); > fflush(stdout); > } > session = NULL; > > //CONNECTION > try { > if (connection != NULL) { > connection->close(); > delete connection; > } > connection = NULL; > } catch (Exception& e) { > fprintf(stdout, e.getMessage().c_str()); > fflush(stdout); > } > connection = NULL; > activemq::library::ActiveMQCPP::shutdownLibrary(); > } > > };//class SimpleProducer > > > SimpleProducer *amq_producer; > void connect(void) { > std::string _brokerURI = "failover:tcp://10.1.1.9:61616"; > std::string _destURI = "TEST.FOO"; > amq_producer = new SimpleProducer(_brokerURI, _destURI, true, true); > amq_producer->connect(); > } > > void disconnect(void) { > if(amq_producer != NULL){ > amq_producer->close(); > } > delete amq_producer; > } > void send(void) { > amq_producer->send("TEST MESSAGE"); > } > > int main(int argc, const char* argv[]) { > string str; > connect(); > while (str.compare("Q") != 0) { > printf("\n P = to produce\n R = to reset Producer\n Q = quit\n"); > getline(cin, str); > > if (str.compare("P") == 0) { > send(); > } else if (str.compare("R") == 0) { > disconnect(); > connect(); > } > } > disconnect(); > return 0; > } > > > -- Tim Bish ------------ FuseSource Email: [hidden email] Web: http://fusesource.com Twitter: tabish121 Blog: http://timbish.blogspot.com/ ________________________________ View message @ http://activemq.2283324.n4.nabble.com/activemq-cpp-library-3-2-2-reconnect-fails-tp3046566p3046971.html To unsubscribe from activemq-cpp-library-3.2.2 - reconnect fails, click here. -- View this message in context: http://activemq.2283324.n4.nabble.com/activemq-cpp-library-3-2-2-reconnect-fails-tp3046566p3046993.html Sent from the ActiveMQ - User mailing list archive at Nabble.com. ------=_Part_8825_14391284.1290008498264--