Merge pull request #17848 from htztomic

* pr/17848:
  Polish "Support additional publisher confirm types"
  Support additional publisher confirm types

Closes gh-17848
pull/17968/head
Madhura Bhave 5 years ago
commit 86a9037721

@ -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)

@ -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;
}

@ -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) -> {

@ -182,7 +182,7 @@
<slf4j.version>1.7.26</slf4j.version>
<snakeyaml.version>1.24</snakeyaml.version>
<solr.version>8.2.0</solr.version>
<spring-amqp.version>2.2.0.M4</spring-amqp.version>
<spring-amqp.version>2.2.0.BUILD-SNAPSHOT</spring-amqp.version>
<spring-batch.version>4.2.0.BUILD-SNAPSHOT</spring-batch.version>
<spring-cloud-connectors.version>2.0.6.RELEASE</spring-cloud-connectors.version>
<spring-data-releasetrain.version>Moore-BUILD-SNAPSHOT</spring-data-releasetrain.version>

Loading…
Cancel
Save