Commit 0d92cb08 by Spencer Gibb

allow defaults for spring-cloud-stream bindings

parent 639a87bf
......@@ -16,6 +16,11 @@
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.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
......@@ -28,10 +33,6 @@ import org.springframework.scheduling.annotation.EnableScheduling;
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
* spring-rabbit is on the classpath, and can be switched off with
......@@ -59,11 +60,21 @@ public class HystrixStreamAutoConfiguration {
@Autowired
private ChannelBindingProperties bindings;
@Autowired
private HystrixStreamProperties properties;
@PostConstruct
public void init() {
this.bindings.getBindings().put(HystrixStreamClient.OUTPUT,
new HashMap<>(Collections.singletonMap("destination",
HystrixStreamClient.HYSTRIX_STREAM_DESTINATION)));
Object outputBinding = this.bindings.getBindings().get(HystrixStreamClient.OUTPUT);
if (outputBinding == null || outputBinding instanceof String) {
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
......
......@@ -16,7 +16,6 @@
package org.springframework.cloud.netflix.hystrix.stream;
import org.springframework.cloud.netflix.hystrix.HystrixConstants;
import org.springframework.cloud.stream.annotation.Output;
import org.springframework.messaging.MessageChannel;
......@@ -24,7 +23,7 @@ import org.springframework.messaging.MessageChannel;
* @author Dave Syer
*
*/
public interface HystrixStreamClient extends HystrixConstants {
public interface HystrixStreamClient {
String OUTPUT = "hystrixStreamOutput";
......
......@@ -19,6 +19,7 @@ package org.springframework.cloud.netflix.hystrix.stream;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.netflix.hystrix.HystrixConstants;
/**
* @author Spencer Gibb
......@@ -33,4 +34,6 @@ public class HystrixStreamProperties {
private boolean sendId = true;
private String destination = HystrixConstants.HYSTRIX_STREAM_DESTINATION;
}
......@@ -16,6 +16,11 @@
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.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
......@@ -24,10 +29,6 @@ import org.springframework.cloud.stream.config.ChannelBindingProperties;
import org.springframework.context.annotation.Bean;
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.
* Enabled by default if spring-cloud-stream is on the classpath, and can be
......@@ -55,11 +56,21 @@ public class TurbineStreamAutoConfiguration {
@Autowired
private ChannelBindingProperties bindings;
@Autowired
private TurbineStreamProperties properties;
@PostConstruct
public void init() {
this.bindings.getBindings().put(TurbineStreamClient.INPUT,
new HashMap<>(Collections.singletonMap("destination",
TurbineStreamClient.HYSTRIX_STREAM_DESTINATION)));
Object inputBinding = this.bindings.getBindings().get(TurbineStreamClient.INPUT);
if (inputBinding == null || inputBinding instanceof String) {
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
......
......@@ -16,7 +16,6 @@
package org.springframework.cloud.netflix.turbine.stream;
import org.springframework.cloud.netflix.hystrix.HystrixConstants;
import org.springframework.cloud.stream.annotation.Input;
import org.springframework.messaging.SubscribableChannel;
......@@ -24,7 +23,7 @@ import org.springframework.messaging.SubscribableChannel;
* @author Dave Syer
*
*/
public interface TurbineStreamClient extends HystrixConstants {
public interface TurbineStreamClient {
String INPUT = "turbineStreamInput";
......
......@@ -20,6 +20,7 @@ import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.netflix.hystrix.HystrixConstants;
/**
* @author Dave Syer
......@@ -31,4 +32,5 @@ public class TurbineStreamProperties {
@Value("${server.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