From cc2159f77bd8fb88fb6190b480a252486a8032d8 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Mon, 16 Mar 2015 14:57:19 +0000 Subject: [PATCH] Use separate RabbitAdmin to declare queues and exchanges Fixes gh-259 --- spring-cloud-netflix-hystrix-amqp/pom.xml | 6 ------ .../hystrix/amqp/HystrixStreamAutoConfiguration.java | 6 +++++- spring-cloud-netflix-turbine-amqp/pom.xml | 9 --------- .../turbine/amqp/TurbineAmqpAutoConfiguration.java | 6 ++++++ 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/spring-cloud-netflix-hystrix-amqp/pom.xml b/spring-cloud-netflix-hystrix-amqp/pom.xml index 0e757429..c663f47c 100644 --- a/spring-cloud-netflix-hystrix-amqp/pom.xml +++ b/spring-cloud-netflix-hystrix-amqp/pom.xml @@ -28,10 +28,6 @@ org.springframework.boot spring-boot-starter-amqp - - org.springframework.boot - spring-boot-starter-integration - org.springframework.cloud spring-cloud-netflix-core @@ -39,12 +35,10 @@ org.springframework.integration spring-integration-amqp - true org.springframework.integration spring-integration-java-dsl - true com.fasterxml.jackson.core diff --git a/spring-cloud-netflix-hystrix-amqp/src/main/java/org/springframework/cloud/netflix/hystrix/amqp/HystrixStreamAutoConfiguration.java b/spring-cloud-netflix-hystrix-amqp/src/main/java/org/springframework/cloud/netflix/hystrix/amqp/HystrixStreamAutoConfiguration.java index 46126e92..32e39f58 100644 --- a/spring-cloud-netflix-hystrix-amqp/src/main/java/org/springframework/cloud/netflix/hystrix/amqp/HystrixStreamAutoConfiguration.java +++ b/spring-cloud-netflix-hystrix-amqp/src/main/java/org/springframework/cloud/netflix/hystrix/amqp/HystrixStreamAutoConfiguration.java @@ -18,6 +18,7 @@ package org.springframework.cloud.netflix.hystrix.amqp; import org.springframework.amqp.core.DirectExchange; import org.springframework.amqp.rabbit.connection.ConnectionFactory; +import org.springframework.amqp.rabbit.core.RabbitAdmin; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; import org.springframework.beans.factory.annotation.Autowired; @@ -111,7 +112,7 @@ public class HystrixStreamAutoConfiguration { // TODO: set content type /* * .enrichHeaders(new ComponentConfigurer() { - * + * * @Override public void configure(HeaderEnricherSpec spec) { * spec.header("content-type", "application/json", true); } }) */ @@ -121,6 +122,9 @@ public class HystrixStreamAutoConfiguration { private ConnectionFactory connectionFactory() { if (this.hystrixConnectionFactory != null) { + RabbitAdmin amqpAdmin = new RabbitAdmin(this.hystrixConnectionFactory); + hystrixStreamExchange().setAdminsThatShouldDeclare(amqpAdmin); + amqpAdmin.afterPropertiesSet(); return this.hystrixConnectionFactory; } return this.primaryConnectionFactory; diff --git a/spring-cloud-netflix-turbine-amqp/pom.xml b/spring-cloud-netflix-turbine-amqp/pom.xml index 09a56cfe..e8903688 100644 --- a/spring-cloud-netflix-turbine-amqp/pom.xml +++ b/spring-cloud-netflix-turbine-amqp/pom.xml @@ -62,34 +62,25 @@ org.springframework.boot spring-boot-starter-amqp - - org.springframework.boot - spring-boot-starter-integration - org.springframework.integration spring-integration-amqp - true org.springframework.integration spring-integration-java-dsl - true com.fasterxml.jackson.core jackson-databind - true com.netflix.turbine turbine-core - true io.reactivex rxjava - true org.projectlombok diff --git a/spring-cloud-netflix-turbine-amqp/src/main/java/org/springframework/cloud/netflix/turbine/amqp/TurbineAmqpAutoConfiguration.java b/spring-cloud-netflix-turbine-amqp/src/main/java/org/springframework/cloud/netflix/turbine/amqp/TurbineAmqpAutoConfiguration.java index 32757554..d672736d 100644 --- a/spring-cloud-netflix-turbine-amqp/src/main/java/org/springframework/cloud/netflix/turbine/amqp/TurbineAmqpAutoConfiguration.java +++ b/spring-cloud-netflix-turbine-amqp/src/main/java/org/springframework/cloud/netflix/turbine/amqp/TurbineAmqpAutoConfiguration.java @@ -25,6 +25,7 @@ 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.RabbitAdmin; import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -105,6 +106,11 @@ public class TurbineAmqpAutoConfiguration { private ConnectionFactory connectionFactory() { if (this.turbineConnectionFactory != null) { + RabbitAdmin amqpAdmin = new RabbitAdmin(this.turbineConnectionFactory); + hystrixStreamExchange().setAdminsThatShouldDeclare(amqpAdmin); + localTurbineAmqpQueueBinding().setAdminsThatShouldDeclare(amqpAdmin); + hystrixStreamQueue().setAdminsThatShouldDeclare(amqpAdmin); + amqpAdmin.afterPropertiesSet(); return this.turbineConnectionFactory; } return this.primaryConnectionFactory;