GH-182 Updated extended properties merge logic

Updated extended properties merge logic based on corresponding core updates (see GH-1503)
Resolves #182

polishing
This commit is contained in:
Oleg Zhurakousky
2018-10-13 20:05:38 -04:00
committed by Soby Chacko
parent f9eec404c3
commit d4fbad5672
4 changed files with 49 additions and 60 deletions

View File

@@ -19,7 +19,6 @@ package org.springframework.cloud.stream.binder.rabbit.properties;
import org.hibernate.validator.constraints.Range;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.cloud.stream.config.MergableProperties;
/**
* @author Gary Russell
@@ -27,7 +26,7 @@ import org.springframework.cloud.stream.config.MergableProperties;
* @since 1.2
*
*/
public abstract class RabbitCommonProperties implements MergableProperties {
public abstract class RabbitCommonProperties {
public static final String DEAD_LETTER_EXCHANGE = "DLX";

View File

@@ -16,12 +16,9 @@
package org.springframework.cloud.stream.binder.rabbit.properties;
import java.util.HashMap;
import java.util.Map;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.stream.binder.AbstractExtendedBindingProperties;
import org.springframework.cloud.stream.binder.BinderSpecificPropertiesProvider;
import org.springframework.cloud.stream.binder.ExtendedBindingProperties;
/**
* @author Marius Bogoevici
@@ -30,62 +27,11 @@ import org.springframework.cloud.stream.binder.ExtendedBindingProperties;
* @author Soby Chacko
*/
@ConfigurationProperties("spring.cloud.stream.rabbit")
public class RabbitExtendedBindingProperties implements ExtendedBindingProperties<RabbitConsumerProperties, RabbitProducerProperties> {
public class RabbitExtendedBindingProperties
extends AbstractExtendedBindingProperties<RabbitConsumerProperties, RabbitProducerProperties, RabbitBindingProperties> {
private static final String DEFAULTS_PREFIX = "spring.cloud.stream.rabbit.default";
private Map<String, RabbitBindingProperties> bindings = new HashMap<>();
public Map<String, RabbitBindingProperties> getBindings() {
return bindings;
}
public void setBindings(Map<String, RabbitBindingProperties> bindings) {
this.bindings = bindings;
}
@Override
public synchronized RabbitConsumerProperties getExtendedConsumerProperties(String channelName) {
RabbitConsumerProperties properties;
if (bindings.containsKey(channelName)) {
if (bindings.get(channelName).getConsumer() != null) {
properties = bindings.get(channelName).getConsumer();
}
else {
properties = new RabbitConsumerProperties();
this.bindings.get(channelName).setConsumer(properties);
}
}
else {
properties = new RabbitConsumerProperties();
RabbitBindingProperties rbp = new RabbitBindingProperties();
rbp.setConsumer(properties);
bindings.put(channelName, rbp);
}
return properties;
}
@Override
public synchronized RabbitProducerProperties getExtendedProducerProperties(String channelName) {
RabbitProducerProperties properties;
if (bindings.containsKey(channelName)) {
if (bindings.get(channelName).getProducer() != null) {
properties = bindings.get(channelName).getProducer();
}
else {
properties = new RabbitProducerProperties();
this.bindings.get(channelName).setProducer(properties);
}
}
else {
properties = new RabbitProducerProperties();
RabbitBindingProperties rbp = new RabbitBindingProperties();
rbp.setProducer(properties);
bindings.put(channelName, rbp);
}
return properties;
}
@Override
public String getDefaultsPrefix() {
return DEFAULTS_PREFIX;
@@ -95,5 +41,4 @@ public class RabbitExtendedBindingProperties implements ExtendedBindingPropertie
public Class<? extends BinderSpecificPropertiesProvider> getExtendedPropertiesEntryClass() {
return RabbitBindingProperties.class;
}
}

View File

@@ -0,0 +1,44 @@
/*
* Copyright 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.stream.binder.rabbit.config;
import java.util.HashMap;
import java.util.Map;
import org.springframework.boot.context.properties.source.ConfigurationPropertyName;
import org.springframework.cloud.stream.config.BindingHandlerAdvise.MappingsProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
*
* @author Oleg Zhurakousky
*
*/
@Configuration
public class ExtendedBindingHandlerMappingsProviderConfiguration {
@Bean
public MappingsProvider rabbitExtendedPropertiesDefaultMappingsProvider() {
return () -> {
Map<ConfigurationPropertyName, ConfigurationPropertyName> mappings = new HashMap<>();
mappings.put(ConfigurationPropertyName.of("spring.cloud.stream.rabbit.bindings"),
ConfigurationPropertyName.of("spring.cloud.stream.rabbit.default"));
return mappings;
};
}
}

View File

@@ -0,0 +1 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=org.springframework.cloud.stream.binder.rabbit.config.ExtendedBindingHandlerMappingsProviderConfiguration