Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RabbitMQ container forceStop property #36539

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ protected void configure(T factory, ConnectionFactory connectionFactory,
}
factory.setMissingQueuesFatal(configuration.isMissingQueuesFatal());
factory.setDeBatchingEnabled(configuration.isDeBatchingEnabled());
factory.setForceStop(configuration.isForceStop());
ListenerRetry retryConfig = configuration.getRetry();
if (retryConfig.isEnabled()) {
RetryInterceptorBuilder<?, ?> builder = (retryConfig.isStateless()) ? RetryInterceptorBuilder.stateless()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,12 @@ public abstract static class AmqpContainer extends BaseContainer {
*/
private boolean deBatchingEnabled = true;

/**
* Whether the container (when stopped) should stop immediately after processing
* the current message or stop after processing all pre-fetched messages.
*/
private boolean forceStop;

/**
* Optional properties for a retry interceptor.
*/
Expand Down Expand Up @@ -781,6 +787,14 @@ public void setDeBatchingEnabled(boolean deBatchingEnabled) {
this.deBatchingEnabled = deBatchingEnabled;
}

public boolean isForceStop() {
return this.forceStop;
}

public void setForceStop(boolean forceStop) {
this.forceStop = forceStop;
}

public ListenerRetry getRetry() {
return this.retry;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,8 @@ void testSimpleRabbitListenerContainerFactoryWithCustomSettings() {
"spring.rabbitmq.listener.simple.defaultRequeueRejected:false",
"spring.rabbitmq.listener.simple.idleEventInterval:5",
"spring.rabbitmq.listener.simple.batchSize:20",
"spring.rabbitmq.listener.simple.missingQueuesFatal:false")
"spring.rabbitmq.listener.simple.missingQueuesFatal:false",
"spring.rabbitmq.listener.simple.force-stop:true")
.run((context) -> {
SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory = context
.getBean("rabbitListenerContainerFactory", SimpleRabbitListenerContainerFactory.class);
Expand All @@ -531,6 +532,17 @@ void testSimpleRabbitListenerContainerFactoryWithCustomSettings() {
});
}

@Test
void testSimpleRabbitListenerContainerFactoryWithDefaultForceStop() {
this.contextRunner
.withUserConfiguration(MessageConvertersConfiguration.class, MessageRecoverersConfiguration.class)
.run((context) -> {
SimpleRabbitListenerContainerFactory containerFactory = context
.getBean("rabbitListenerContainerFactory", SimpleRabbitListenerContainerFactory.class);
assertThat(containerFactory).hasFieldOrPropertyWithValue("forceStop", false);
});
}

@Test
void testDirectRabbitListenerContainerFactoryWithCustomSettings() {
this.contextRunner
Expand All @@ -547,7 +559,8 @@ void testDirectRabbitListenerContainerFactoryWithCustomSettings() {
"spring.rabbitmq.listener.direct.prefetch:40",
"spring.rabbitmq.listener.direct.defaultRequeueRejected:false",
"spring.rabbitmq.listener.direct.idleEventInterval:5",
"spring.rabbitmq.listener.direct.missingQueuesFatal:true")
"spring.rabbitmq.listener.direct.missingQueuesFatal:true",
"spring.rabbitmq.listener.direct.force-stop:true")
.run((context) -> {
DirectRabbitListenerContainerFactory rabbitListenerContainerFactory = context
.getBean("rabbitListenerContainerFactory", DirectRabbitListenerContainerFactory.class);
Expand All @@ -557,6 +570,18 @@ void testDirectRabbitListenerContainerFactoryWithCustomSettings() {
});
}

@Test
void testDirectRabbitListenerContainerFactoryWithDefaultForceStop() {
this.contextRunner
.withUserConfiguration(MessageConvertersConfiguration.class, MessageRecoverersConfiguration.class)
.withPropertyValues("spring.rabbitmq.listener.type:direct")
.run((context) -> {
DirectRabbitListenerContainerFactory containerFactory = context
.getBean("rabbitListenerContainerFactory", DirectRabbitListenerContainerFactory.class);
assertThat(containerFactory).hasFieldOrPropertyWithValue("forceStop", false);
});
}

@Test
void testSimpleRabbitListenerContainerFactoryRetryWithCustomizer() {
this.contextRunner.withUserConfiguration(RabbitRetryTemplateCustomizerConfiguration.class)
Expand Down Expand Up @@ -662,6 +687,7 @@ private void checkCommonProps(AssertableApplicationContext context,
context.getBean("myMessageConverter"));
assertThat(containerFactory).hasFieldOrPropertyWithValue("defaultRequeueRejected", Boolean.FALSE);
assertThat(containerFactory).hasFieldOrPropertyWithValue("idleEventInterval", 5L);
assertThat(containerFactory).hasFieldOrPropertyWithValue("forceStop", true);
Advice[] adviceChain = containerFactory.getAdviceChain();
assertThat(adviceChain).isNotNull();
assertThat(adviceChain).hasSize(1);
Expand Down
2 changes: 1 addition & 1 deletion spring-boot-project/spring-boot-dependencies/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,7 @@ bom {
]
}
}
library("Spring AMQP", "3.0.6") {
library("Spring AMQP", "3.0.7") {
group("org.springframework.amqp") {
imports = [
"spring-amqp-bom"
Expand Down