Commit 0d92cb08 by Spencer Gibb

allow defaults for spring-cloud-stream bindings

parent 639a87bf
...@@ -16,6 +16,11 @@ ...@@ -16,6 +16,11 @@
package org.springframework.cloud.netflix.hystrix.stream; package org.springframework.cloud.netflix.hystrix.stream;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
...@@ -28,10 +33,6 @@ import org.springframework.scheduling.annotation.EnableScheduling; ...@@ -28,10 +33,6 @@ import org.springframework.scheduling.annotation.EnableScheduling;
import com.netflix.hystrix.HystrixCircuitBreaker; import com.netflix.hystrix.HystrixCircuitBreaker;
import javax.annotation.PostConstruct;
import java.util.Collections;
import java.util.HashMap;
/** /**
* Autoconfiguration for a Spring Cloud Hystrix on AMQP. Enabled by default if * Autoconfiguration for a Spring Cloud Hystrix on AMQP. Enabled by default if
* spring-rabbit is on the classpath, and can be switched off with * spring-rabbit is on the classpath, and can be switched off with
...@@ -59,11 +60,21 @@ public class HystrixStreamAutoConfiguration { ...@@ -59,11 +60,21 @@ public class HystrixStreamAutoConfiguration {
@Autowired @Autowired
private ChannelBindingProperties bindings; private ChannelBindingProperties bindings;
@Autowired
private HystrixStreamProperties properties;
@PostConstruct @PostConstruct
public void init() { public void init() {
this.bindings.getBindings().put(HystrixStreamClient.OUTPUT, Object outputBinding = this.bindings.getBindings().get(HystrixStreamClient.OUTPUT);
new HashMap<>(Collections.singletonMap("destination", if (outputBinding == null || outputBinding instanceof String) {
HystrixStreamClient.HYSTRIX_STREAM_DESTINATION))); this.bindings.getBindings().put(HystrixStreamClient.OUTPUT,
new HashMap<String, Object>());
}
@SuppressWarnings("unchecked")
Map<String, Object> output = (Map<String, Object>) this.bindings.getBindings().get(HystrixStreamClient.OUTPUT);
if (!output.containsKey("destination") || HystrixStreamClient.OUTPUT.equals(outputBinding)) {
output.put("destination", this.properties.getDestination());
}
} }
@Bean @Bean
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
package org.springframework.cloud.netflix.hystrix.stream; package org.springframework.cloud.netflix.hystrix.stream;
import org.springframework.cloud.netflix.hystrix.HystrixConstants;
import org.springframework.cloud.stream.annotation.Output; import org.springframework.cloud.stream.annotation.Output;
import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageChannel;
...@@ -24,7 +23,7 @@ import org.springframework.messaging.MessageChannel; ...@@ -24,7 +23,7 @@ import org.springframework.messaging.MessageChannel;
* @author Dave Syer * @author Dave Syer
* *
*/ */
public interface HystrixStreamClient extends HystrixConstants { public interface HystrixStreamClient {
String OUTPUT = "hystrixStreamOutput"; String OUTPUT = "hystrixStreamOutput";
......
...@@ -19,6 +19,7 @@ package org.springframework.cloud.netflix.hystrix.stream; ...@@ -19,6 +19,7 @@ package org.springframework.cloud.netflix.hystrix.stream;
import lombok.Data; import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.netflix.hystrix.HystrixConstants;
/** /**
* @author Spencer Gibb * @author Spencer Gibb
...@@ -33,4 +34,6 @@ public class HystrixStreamProperties { ...@@ -33,4 +34,6 @@ public class HystrixStreamProperties {
private boolean sendId = true; private boolean sendId = true;
private String destination = HystrixConstants.HYSTRIX_STREAM_DESTINATION;
} }
...@@ -16,6 +16,11 @@ ...@@ -16,6 +16,11 @@
package org.springframework.cloud.netflix.turbine.stream; package org.springframework.cloud.netflix.turbine.stream;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
...@@ -24,10 +29,6 @@ import org.springframework.cloud.stream.config.ChannelBindingProperties; ...@@ -24,10 +29,6 @@ import org.springframework.cloud.stream.config.ChannelBindingProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;
import java.util.Collections;
import java.util.HashMap;
/** /**
* Autoconfiguration for a Spring Cloud Turbine using Spring Cloud Stream. * Autoconfiguration for a Spring Cloud Turbine using Spring Cloud Stream.
* Enabled by default if spring-cloud-stream is on the classpath, and can be * Enabled by default if spring-cloud-stream is on the classpath, and can be
...@@ -55,11 +56,21 @@ public class TurbineStreamAutoConfiguration { ...@@ -55,11 +56,21 @@ public class TurbineStreamAutoConfiguration {
@Autowired @Autowired
private ChannelBindingProperties bindings; private ChannelBindingProperties bindings;
@Autowired
private TurbineStreamProperties properties;
@PostConstruct @PostConstruct
public void init() { public void init() {
this.bindings.getBindings().put(TurbineStreamClient.INPUT, Object inputBinding = this.bindings.getBindings().get(TurbineStreamClient.INPUT);
new HashMap<>(Collections.singletonMap("destination", if (inputBinding == null || inputBinding instanceof String) {
TurbineStreamClient.HYSTRIX_STREAM_DESTINATION))); this.bindings.getBindings().put(TurbineStreamClient.INPUT,
new HashMap<String, Object>());
}
@SuppressWarnings("unchecked")
Map<String, Object> input = (Map<String, Object>) this.bindings.getBindings().get(TurbineStreamClient.INPUT);
if (!input.containsKey("destination") || TurbineStreamClient.INPUT.equals(inputBinding)) {
input.put("destination", properties.getDestination());
}
} }
@Bean @Bean
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
package org.springframework.cloud.netflix.turbine.stream; package org.springframework.cloud.netflix.turbine.stream;
import org.springframework.cloud.netflix.hystrix.HystrixConstants;
import org.springframework.cloud.stream.annotation.Input; import org.springframework.cloud.stream.annotation.Input;
import org.springframework.messaging.SubscribableChannel; import org.springframework.messaging.SubscribableChannel;
...@@ -24,7 +23,7 @@ import org.springframework.messaging.SubscribableChannel; ...@@ -24,7 +23,7 @@ import org.springframework.messaging.SubscribableChannel;
* @author Dave Syer * @author Dave Syer
* *
*/ */
public interface TurbineStreamClient extends HystrixConstants { public interface TurbineStreamClient {
String INPUT = "turbineStreamInput"; String INPUT = "turbineStreamInput";
......
...@@ -20,6 +20,7 @@ import lombok.Data; ...@@ -20,6 +20,7 @@ import lombok.Data;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.netflix.hystrix.HystrixConstants;
/** /**
* @author Dave Syer * @author Dave Syer
...@@ -31,4 +32,5 @@ public class TurbineStreamProperties { ...@@ -31,4 +32,5 @@ public class TurbineStreamProperties {
@Value("${server.port:8989}") @Value("${server.port:8989}")
private int port = 8989; private int port = 8989;
private String destination = HystrixConstants.HYSTRIX_STREAM_DESTINATION;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment