This closes #218
This commit is contained in:
commit
7f60ff20a5
|
@ -32,6 +32,8 @@ import org.apache.activemq.artemis.api.core.SimpleString;
|
|||
import org.apache.activemq.artemis.api.core.client.ClientMessage;
|
||||
import org.apache.activemq.artemis.api.core.client.ClientSession.QueueQuery;
|
||||
import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
|
||||
import org.apache.activemq.artemis.api.core.client.FailoverEventListener;
|
||||
import org.apache.activemq.artemis.api.core.client.FailoverEventType;
|
||||
import org.apache.activemq.artemis.api.core.client.MessageHandler;
|
||||
import org.apache.activemq.artemis.core.client.impl.ClientConsumerInternal;
|
||||
import org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal;
|
||||
|
@ -48,7 +50,7 @@ import org.apache.activemq.artemis.utils.VersionLoader;
|
|||
/**
|
||||
* The message handler
|
||||
*/
|
||||
public class ActiveMQMessageHandler implements MessageHandler {
|
||||
public class ActiveMQMessageHandler implements MessageHandler, FailoverEventListener {
|
||||
|
||||
/**
|
||||
* Trace enabled
|
||||
|
@ -80,6 +82,8 @@ public class ActiveMQMessageHandler implements MessageHandler {
|
|||
|
||||
private ClientSessionFactory cf;
|
||||
|
||||
private volatile boolean connected;
|
||||
|
||||
public ActiveMQMessageHandler(final ActiveMQActivation activation,
|
||||
final TransactionManager tm,
|
||||
final ClientSessionInternal session,
|
||||
|
@ -187,6 +191,8 @@ public class ActiveMQMessageHandler implements MessageHandler {
|
|||
endpoint = endpointFactory.createEndpoint(null);
|
||||
useXA = false;
|
||||
}
|
||||
connected = true;
|
||||
session.addFailoverListener(this);
|
||||
consumer.setMessageHandler(this);
|
||||
}
|
||||
|
||||
|
@ -224,6 +230,8 @@ public class ActiveMQMessageHandler implements MessageHandler {
|
|||
ActiveMQRALogger.LOGGER.debug("Error releasing endpoint " + endpoint, t);
|
||||
}
|
||||
|
||||
//only do this if we haven't been disconnected at some point whilst failing over
|
||||
if (connected) {
|
||||
try {
|
||||
consumer.close();
|
||||
if (activation.getTopicTemporaryQueue() != null) {
|
||||
|
@ -249,7 +257,6 @@ public class ActiveMQMessageHandler implements MessageHandler {
|
|||
catch (Throwable t) {
|
||||
ActiveMQRALogger.LOGGER.debug("Error releasing session " + session, t);
|
||||
}
|
||||
|
||||
try {
|
||||
if (cf != null) {
|
||||
cf.close();
|
||||
|
@ -259,6 +266,19 @@ public class ActiveMQMessageHandler implements MessageHandler {
|
|||
ActiveMQRALogger.LOGGER.debug("Error releasing session factory " + session, t);
|
||||
}
|
||||
}
|
||||
else {
|
||||
//otherwise we just clean up
|
||||
try {
|
||||
if (cf != null) {
|
||||
cf.cleanup();
|
||||
}
|
||||
}
|
||||
catch (Throwable t) {
|
||||
ActiveMQRALogger.LOGGER.debug("Error releasing session factory " + session, t);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void onMessage(final ClientMessage message) {
|
||||
if (ActiveMQMessageHandler.trace) {
|
||||
|
@ -364,4 +384,9 @@ public class ActiveMQMessageHandler implements MessageHandler {
|
|||
public void start() throws ActiveMQException {
|
||||
session.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failoverEvent(FailoverEventType eventType) {
|
||||
connected = eventType == FailoverEventType.FAILOVER_COMPLETED;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue