INT-4307: JMS: Endpoint Stop: Shutdown Container

JIRA: https://jira.spring.io/browse/INT-4307

Shut down the container (to close the connection) when a message-driven
endpoint is stopped while the application continues to run.
This commit is contained in:
Gary Russell
2018-09-13 14:32:49 -04:00
committed by Artem Bilan
parent 02c8e0ade2
commit 76b1d1df06
7 changed files with 191 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 the original author or authors.
* Copyright 2016-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,6 +48,18 @@ public class JmsInboundGateway extends MessagingGatewaySupport implements Dispos
this.endpoint.getListener().setRequestChannel(requestChannel);
}
/**
* Set to false to prevent listener container shutdown when the endpoint is stopped.
* Then, if so configured, any cached consumer(s) in the container will remain.
* Otherwise the shared connection and will be closed and the listener invokers shut
* down; this behavior is new starting with version 5.1. Default: true.
* @param shutdownContainerOnStop false to not shutdown.
* @since 5.1
*/
public void setShutdownContainerOnStop(boolean shutdownContainerOnStop) {
this.endpoint.setShutdownContainerOnStop(shutdownContainerOnStop);
}
@Override
public String getComponentType() {
return this.endpoint.getComponentType();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,7 +44,11 @@ public class JmsMessageDrivenEndpoint extends MessageProducerSupport implements
private final ChannelPublishingJmsMessageListener listener;
private volatile String sessionAcknowledgeMode;
private String sessionAcknowledgeMode;
private boolean shutdownContainerOnStop = true;
private volatile boolean hasStopped;
/**
* Construct an instance with an externally configured container.
@@ -128,6 +132,18 @@ public class JmsMessageDrivenEndpoint extends MessageProducerSupport implements
this.listener.setShouldTrack(shouldTrack);
}
/**
* Set to false to prevent listener container shutdown when the endpoint is stopped.
* Then, if so configured, any cached consumer(s) in the container will remain.
* Otherwise the shared connection and will be closed and the listener invokers shut
* down; this behavior is new starting with version 5.1. Default: true.
* @param shutdownContainerOnStop false to not shutdown.
* @since 5.1
*/
public void setShutdownContainerOnStop(boolean shutdownContainerOnStop) {
this.shutdownContainerOnStop = shutdownContainerOnStop;
}
public ChannelPublishingJmsMessageListener getListener() {
return this.listener;
}
@@ -177,6 +193,10 @@ public class JmsMessageDrivenEndpoint extends MessageProducerSupport implements
protected void doStart() {
this.listener.start();
if (!this.listenerContainer.isRunning()) {
if (this.hasStopped) {
this.listenerContainer.initialize();
this.hasStopped = false;
}
this.listenerContainer.start();
}
}
@@ -184,6 +204,10 @@ public class JmsMessageDrivenEndpoint extends MessageProducerSupport implements
@Override
protected void doStop() {
this.listenerContainer.stop();
if (this.shutdownContainerOnStop) {
this.hasStopped = true;
this.listenerContainer.shutdown();
}
this.listener.stop();
}

View File

@@ -35,6 +35,7 @@ import org.springframework.util.Assert;
* @param <S> the target {@link JmsInboundGatewaySpec} implementation type.
*
* @author Artem Bilan
* @author Gary Russell
*
* @since 5.0
*/
@@ -176,6 +177,20 @@ public class JmsInboundGatewaySpec<S extends JmsInboundGatewaySpec<S>>
return _this();
}
/**
* Set to false to prevent listener container shutdown when the endpoint is stopped.
* Then, if so configured, any cached consumer(s) in the container will remain.
* Otherwise the shared connection and will be closed and the listener invokers shut
* down; this behavior is new starting with version 5.1. Default: true.
* @param shutdown false to not shutdown.
* @return the spec.
* @since 5.1
*/
public S shutdownContainerOnStop(boolean shutdown) {
this.target.setShutdownContainerOnStop(shutdown);
return _this();
}
/**
* An {@link AbstractMessageListenerContainer}-based {@link JmsInboundGatewaySpec} extension.
*

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 the original author or authors.
* Copyright 2016-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,6 +37,7 @@ import org.springframework.util.Assert;
* @param <S> the target {@link JmsMessageDrivenChannelAdapterSpec} implementation type.
*
* @author Artem Bilan
* @author Gary Russell
*
* @since 5.0
*/
@@ -78,6 +79,20 @@ public class JmsMessageDrivenChannelAdapterSpec<S extends JmsMessageDrivenChanne
return _this();
}
/**
* Set to false to prevent listener container shutdown when the endpoint is stopped.
* Then, if so configured, any cached consumer(s) in the container will remain.
* Otherwise the shared connection and will be closed and the listener invokers shut
* down; this behavior is new starting with version 5.1. Default: true.
* @param shutdown false to not shutdown.
* @return the spec.
* @since 5.1
*/
public S shutdownContainerOnStop(boolean shutdown) {
this.target.setShutdownContainerOnStop(shutdown);
return _this();
}
/**
*
* @param <S> the target {@link JmsListenerContainerSpec} implementation type.