11 changed files with 212 additions and 137 deletions
@ -1,4 +1,4 @@
@@ -1,4 +1,4 @@
|
||||
package org.springframework.netflix.turbine.amqp; |
||||
package org.springframework.cloud.netflix.turbine.amqp; |
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper; |
||||
|
@ -1,4 +1,4 @@
@@ -1,4 +1,4 @@
|
||||
package org.springframework.netflix.turbine.amqp; |
||||
package org.springframework.cloud.netflix.turbine.amqp; |
||||
|
||||
import org.springframework.context.annotation.Import; |
||||
|
@ -0,0 +1,92 @@
@@ -0,0 +1,92 @@
|
||||
package org.springframework.cloud.netflix.turbine.amqp; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
import javax.annotation.PostConstruct; |
||||
|
||||
import org.springframework.amqp.core.AmqpTemplate; |
||||
import org.springframework.amqp.core.Binding; |
||||
import org.springframework.amqp.core.BindingBuilder; |
||||
import org.springframework.amqp.core.DirectExchange; |
||||
import org.springframework.amqp.core.Queue; |
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory; |
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate; |
||||
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; |
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; |
||||
import org.springframework.cloud.netflix.Constants; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.integration.dsl.IntegrationFlow; |
||||
import org.springframework.integration.dsl.IntegrationFlows; |
||||
import org.springframework.integration.dsl.amqp.Amqp; |
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper; |
||||
|
||||
/** |
||||
* @author Spencer Gibb |
||||
*/ |
||||
@Configuration |
||||
@ConditionalOnClass(AmqpTemplate.class) |
||||
@ConditionalOnExpression("${turbine.amqp.enabled:true}") |
||||
public class TurbineAmqpAutoConfiguration { |
||||
|
||||
@Autowired |
||||
private ConnectionFactory connectionFactory; |
||||
|
||||
@Autowired |
||||
private RabbitTemplate amqpTemplate; |
||||
|
||||
@Autowired(required = false) |
||||
private ObjectMapper objectMapper; |
||||
|
||||
@PostConstruct |
||||
public void init() { |
||||
Jackson2JsonMessageConverter converter = messageConverter(); |
||||
amqpTemplate.setMessageConverter(converter); |
||||
} |
||||
|
||||
@Bean |
||||
public DirectExchange hystrixStreamExchange() { |
||||
DirectExchange exchange = new DirectExchange(Constants.HYSTRIX_STREAM_NAME); |
||||
return exchange; |
||||
} |
||||
|
||||
@Bean |
||||
protected Binding localTurbineAmqpQueueBinding() { |
||||
return BindingBuilder.bind(hystrixStreamQueue()).to(hystrixStreamExchange()) |
||||
.with(""); |
||||
} |
||||
|
||||
@Bean |
||||
public Queue hystrixStreamQueue() { |
||||
Map<String, Object> args = new HashMap<>(); |
||||
args.put("x-message-ttl", 60000); // TODO: configure TTL
|
||||
Queue queue = new Queue(Constants.HYSTRIX_STREAM_NAME, false, false, false, args); |
||||
return queue; |
||||
} |
||||
|
||||
@Bean |
||||
public IntegrationFlow hystrixStreamAggregatorInboundFlow() { |
||||
return IntegrationFlows |
||||
.from(Amqp.inboundAdapter(connectionFactory, hystrixStreamQueue()) |
||||
.messageConverter(messageConverter())) |
||||
.channel("hystrixStreamAggregator").get(); |
||||
} |
||||
|
||||
@Bean |
||||
public Aggregator hystrixStreamAggregator() { |
||||
return new Aggregator(); |
||||
} |
||||
|
||||
private Jackson2JsonMessageConverter messageConverter() { |
||||
Jackson2JsonMessageConverter converter = new Jackson2JsonMessageConverter(); |
||||
if (objectMapper != null) { |
||||
converter.setJsonObjectMapper(objectMapper); |
||||
} |
||||
return converter; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,16 @@
@@ -0,0 +1,16 @@
|
||||
package org.springframework.cloud.netflix.turbine.amqp; |
||||
|
||||
import lombok.Data; |
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties; |
||||
|
||||
/** |
||||
* @author Dave Syer |
||||
*/ |
||||
@ConfigurationProperties("turbine.amqp") |
||||
@Data |
||||
public class TurbineAmqpProperties { |
||||
|
||||
private int port = 8989; |
||||
|
||||
} |
@ -1,70 +0,0 @@
@@ -1,70 +0,0 @@
|
||||
package org.springframework.netflix.turbine.amqp; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
import org.springframework.amqp.core.AmqpTemplate; |
||||
import org.springframework.amqp.core.Binding; |
||||
import org.springframework.amqp.core.BindingBuilder; |
||||
import org.springframework.amqp.core.DirectExchange; |
||||
import org.springframework.amqp.core.Queue; |
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; |
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; |
||||
import org.springframework.cloud.netflix.Constants; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.integration.dsl.IntegrationFlow; |
||||
import org.springframework.integration.dsl.IntegrationFlows; |
||||
import org.springframework.integration.dsl.amqp.Amqp; |
||||
|
||||
/** |
||||
* @author Spencer Gibb |
||||
*/ |
||||
@Configuration |
||||
@ConditionalOnClass(AmqpTemplate.class) |
||||
public class TurbineAmqpAutoConfiguration { |
||||
|
||||
@Configuration |
||||
@ConditionalOnExpression("${turbine.amqp.enabled:true}") |
||||
protected static class HystrixStreamAggregatorAutoConfiguration { |
||||
|
||||
@Autowired |
||||
private ConnectionFactory connectionFactory; |
||||
|
||||
//TODO: how to fail gracefully if no rabbit?
|
||||
@Bean |
||||
public DirectExchange hystrixStreamExchange() { |
||||
DirectExchange exchange = new DirectExchange(Constants.HYSTRIX_STREAM_NAME); |
||||
return exchange; |
||||
} |
||||
|
||||
@Bean |
||||
protected Binding localTurbineAmqpQueueBinding() { |
||||
return BindingBuilder.bind(hystrixStreamQueue()).to(hystrixStreamExchange()).with(""); |
||||
} |
||||
|
||||
@Bean |
||||
public Queue hystrixStreamQueue() { |
||||
Map<String, Object> args = new HashMap<>(); |
||||
args.put("x-message-ttl", 60000); //TODO: configure TTL
|
||||
Queue queue = new Queue(Constants.HYSTRIX_STREAM_NAME, false, false, false, args); |
||||
return queue; |
||||
} |
||||
|
||||
@Bean |
||||
public IntegrationFlow hystrixStreamAggregatorInboundFlow() { |
||||
return IntegrationFlows.from(Amqp.inboundAdapter(connectionFactory, hystrixStreamQueue())) |
||||
.channel("hystrixStreamAggregator") |
||||
.get(); |
||||
} |
||||
|
||||
@Bean |
||||
public Aggregator hystrixStreamAggregator() { |
||||
return new Aggregator(); |
||||
} |
||||
} |
||||
|
||||
|
||||
} |
@ -1,2 +1,2 @@
@@ -1,2 +1,2 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ |
||||
org.springframework.netflix.turbine.amqp.TurbineAmqpAutoConfiguration |
||||
org.springframework.cloud.netflix.turbine.amqp.TurbineAmqpAutoConfiguration |
||||
|
Loading…
Reference in new issue