diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java
index 9258e9052a..44e02746c3 100644
--- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java
+++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java
@@ -99,8 +99,8 @@ public class RabbitAutoConfiguration {
CachingConnectionFactory factory = new CachingConnectionFactory(
getRabbitConnectionFactoryBean(properties).getObject());
map.from(properties::determineAddresses).to(factory::setAddresses);
- map.from(properties::isPublisherConfirms).to(factory::setPublisherConfirms);
map.from(properties::isPublisherReturns).to(factory::setPublisherReturns);
+ map.from(properties::getPublisherConfirmType).whenNonNull().to(factory::setPublisherConfirmType);
RabbitProperties.Cache.Channel channel = properties.getCache().getChannel();
map.from(channel::getSize).whenNonNull().to(factory::setChannelCacheSize);
map.from(channel::getCheckoutTimeout).whenNonNull().as(Duration::toMillis)
diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java
index 6443dface3..615ef47158 100644
--- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java
+++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java
@@ -23,6 +23,7 @@ import java.util.List;
import org.springframework.amqp.core.AcknowledgeMode;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory.CacheMode;
+import org.springframework.amqp.rabbit.connection.CachingConnectionFactory.ConfirmType;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
import org.springframework.boot.convert.DurationUnit;
@@ -87,14 +88,14 @@ public class RabbitProperties {
private Duration requestedHeartbeat;
/**
- * Whether to enable publisher confirms.
+ * Whether to enable publisher returns.
*/
- private boolean publisherConfirms;
+ private boolean publisherReturns;
/**
- * Whether to enable publisher returns.
+ * Type of publisher confirms to use.
*/
- private boolean publisherReturns;
+ private ConfirmType publisherConfirmType;
/**
* Connection timeout. Set it to zero to wait forever.
@@ -274,12 +275,15 @@ public class RabbitProperties {
this.requestedHeartbeat = requestedHeartbeat;
}
+ @DeprecatedConfigurationProperty(reason = "replaced to support additional confirm types",
+ replacement = "spring.rabbitmq.publisher-confirm-type")
public boolean isPublisherConfirms() {
- return this.publisherConfirms;
+ return this.publisherConfirmType.equals(ConfirmType.CORRELATED);
}
+ @Deprecated
public void setPublisherConfirms(boolean publisherConfirms) {
- this.publisherConfirms = publisherConfirms;
+ this.publisherConfirmType = (publisherConfirms) ? ConfirmType.CORRELATED : ConfirmType.NONE;
}
public boolean isPublisherReturns() {
@@ -294,6 +298,14 @@ public class RabbitProperties {
return this.connectionTimeout;
}
+ public void setPublisherConfirmType(ConfirmType publisherConfirmType) {
+ this.publisherConfirmType = publisherConfirmType;
+ }
+
+ public ConfirmType getPublisherConfirmType() {
+ return this.publisherConfirmType;
+ }
+
public void setConnectionTimeout(Duration connectionTimeout) {
this.connectionTimeout = connectionTimeout;
}
diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java
index 46fe91e038..874219d115 100644
--- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java
+++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java
@@ -80,6 +80,7 @@ import static org.mockito.Mockito.verify;
* @author Greg Turnquist
* @author Stephane Nicoll
* @author Gary Russell
+ * @author HaiTao Zhang
*/
class RabbitAutoConfigurationTests {
@@ -210,6 +211,34 @@ class RabbitAutoConfigurationTests {
});
}
+ @Test
+ void testConnectionFactorPublisherSettingsUsingConfirmType() {
+ this.contextRunner.withUserConfiguration(TestConfiguration.class)
+ .withPropertyValues("spring.rabbitmq.publisher-confirm-type=correlated",
+ "spring.rabbitmq.publisher-returns=true")
+ .run((context) -> {
+ CachingConnectionFactory connectionFactory = context.getBean(CachingConnectionFactory.class);
+ RabbitTemplate rabbitTemplate = context.getBean(RabbitTemplate.class);
+ assertThat(connectionFactory.isPublisherConfirms()).isTrue();
+ assertThat(connectionFactory.isPublisherReturns()).isTrue();
+ assertThat(getMandatory(rabbitTemplate)).isTrue();
+ });
+ }
+
+ @Test
+ void testConnectionFactorySimplePublisherSettingsUsingConfirmType() {
+ this.contextRunner.withUserConfiguration(TestConfiguration.class)
+ .withPropertyValues("spring.rabbitmq.publisher-confirm-type=simple",
+ "spring.rabbitmq.publisher-returns=true")
+ .run((context) -> {
+ CachingConnectionFactory connectionFactory = context.getBean(CachingConnectionFactory.class);
+ RabbitTemplate rabbitTemplate = context.getBean(RabbitTemplate.class);
+ assertThat(connectionFactory.isSimplePublisherConfirms()).isTrue();
+ assertThat(connectionFactory.isPublisherReturns()).isTrue();
+ assertThat(getMandatory(rabbitTemplate)).isTrue();
+ });
+ }
+
@Test
void testRabbitTemplateMessageConverters() {
this.contextRunner.withUserConfiguration(MessageConvertersConfiguration.class).run((context) -> {
diff --git a/spring-boot-project/spring-boot-dependencies/pom.xml b/spring-boot-project/spring-boot-dependencies/pom.xml
index 0803414005..516a2c8869 100644
--- a/spring-boot-project/spring-boot-dependencies/pom.xml
+++ b/spring-boot-project/spring-boot-dependencies/pom.xml
@@ -182,7 +182,7 @@
1.7.26
1.24
8.2.0
- 2.2.0.M4
+ 2.2.0.BUILD-SNAPSHOT
4.2.0.BUILD-SNAPSHOT
2.0.6.RELEASE
Moore-BUILD-SNAPSHOT