diff --git a/README.md b/README.md index 3b5d87d..dd865e7 100644 --- a/README.md +++ b/README.md @@ -127,3 +127,22 @@ Bitte beachten: Der XML-Parser von monitord unterstützt *keine* leeren Tags (also oder ). Sollte die Konfiguration dennoch einen solchen enthalten, gibt es einen Segmentation Fault. +##### Wiederherstellung der ActiveMQ-Verbindung +Je nach Einsatz kann es sein, dass die Verbindung zwischen monitord und dem ActiveMQ-Broker abbricht. Dies kann zum Beispiel auftreten, wenn es Probleme mit der TCP-Verbindung gibt oder aber der Broker zwischenzeitlich neugestartet worden ist. +Um darauf zu reagieren, kann der ActiveMQ-Client ein Failover nutzen: + + + + failover://(tcp://127.0.0.1:61616) + + + +bzw. wenn mehrere Broker genutzt werden sollen: + + + + failover://(tcp://192.168.0.1:61616,192.168.0.2:61616) + + + + diff --git a/monitord/plugins/libmplugin_activemq.cpp b/monitord/plugins/libmplugin_activemq.cpp index fab9c8b..3f553bb 100644 --- a/monitord/plugins/libmplugin_activemq.cpp +++ b/monitord/plugins/libmplugin_activemq.cpp @@ -194,16 +194,18 @@ // create a connection try { - m_connection = m_connectionFactory->createConnection(); + m_connection = dynamic_cast(m_connectionFactory->createConnection()); LOG_INFO("Connection prepared") m_connection->start(); LOG_INFO("Connection started") if (m_bClientAck) { - m_session = m_connection->createSession(Session::CLIENT_ACKNOWLEDGE); + LOG_DEBUG("Setting: client acknowledge required") + m_session = dynamic_cast(m_connection->createSession(Session::CLIENT_ACKNOWLEDGE)); } else { - m_session = m_connection->createSession(Session::AUTO_ACKNOWLEDGE); + LOG_DEBUG("Setting: auto acknowledge enabled") + m_session = dynamic_cast(m_connection->createSession(Session::AUTO_ACKNOWLEDGE)); } m_bConnected = true; @@ -224,10 +226,12 @@ // close open resources try { if (m_session != NULL) { + LOG_DEBUG("Closing session..") m_session->close(); } if (m_connection != NULL) { + LOG_DEBUG("Closing connection...") m_connection->close(); } } @@ -280,6 +284,24 @@ } bool MonitorPlugInActiveMQ::establishConnection() { + // if some connection issue has occured, try to reconnect to the broker + try { + if (m_connection != NULL) { + LOG_DEBUG("Checking for closed connection") + m_connection->checkClosed(); + } + + if (m_session != NULL && (false == m_session->isStarted())) { + throw CMSException("Connection open but session not started"); + } + + } + catch (CMSException& ex) { + LOG_ERROR("Connection is broke:" << ex.getMessage()) + LOG_INFO("Freeing resources for reconnecting...") + freeConnection(); + } + if (m_bConnected == false) { LOG_DEBUG("m_bConnected is false: \"" << m_bConnected << "\"") diff --git a/monitord/plugins/libmplugin_activemq.h b/monitord/plugins/libmplugin_activemq.h index 52d4f88..e7c4540 100644 --- a/monitord/plugins/libmplugin_activemq.h +++ b/monitord/plugins/libmplugin_activemq.h @@ -14,6 +14,8 @@ #include "base64.h" #include "../MonitorLogging.h" #include +#include +#include #include #include #include @@ -78,8 +80,8 @@ bool m_bTopicsInitialized; std::auto_ptr m_connectionFactory; - cms::Connection* m_connection; - cms::Session* m_session; + activemq::core::ActiveMQConnection* m_connection; + activemq::core::ActiveMQSession* m_session; TopicInfo m_genericTopic; Topics m_topics;