From fd9b380727e9219c6ec9d911d00bdd3ac08a6814 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Fri, 31 Oct 2014 14:33:17 -0400 Subject: [PATCH 1/2] Upgraded Spring AMQP to 1.3.6 Creating Rabbit ConnectionFactory by passing the URI from AmqpServiceInfo. --- build.gradle | 2 +- .../RabbitConnectionFactoryCreator.java | 17 +++++------------ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/build.gradle b/build.gradle index 2598d51..06e471b 100644 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ ext { springVersion = "3.1.4.RELEASE" tomcatVersion = "7.0.53" - springAmqpVersion = "1.0.0.RELEASE" + springAmqpVersion = "1.3.6.RELEASE" springDataRedisVersion = "1.1.1.RELEASE" springDataMongoVersion = "1.2.4.RELEASE" diff --git a/spring-cloud-spring-service-connector/src/main/java/org/springframework/cloud/service/messaging/RabbitConnectionFactoryCreator.java b/spring-cloud-spring-service-connector/src/main/java/org/springframework/cloud/service/messaging/RabbitConnectionFactoryCreator.java index 7ca878c..a32db74 100644 --- a/spring-cloud-spring-service-connector/src/main/java/org/springframework/cloud/service/messaging/RabbitConnectionFactoryCreator.java +++ b/spring-cloud-spring-service-connector/src/main/java/org/springframework/cloud/service/messaging/RabbitConnectionFactoryCreator.java @@ -19,19 +19,12 @@ public class RabbitConnectionFactoryCreator extends AbstractServiceConnectorCrea @Override public ConnectionFactory create(AmqpServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfiguration) { com.rabbitmq.client.ConnectionFactory connectionFactory = new com.rabbitmq.client.ConnectionFactory(); - connectionFactory.setHost(serviceInfo.getHost()); - connectionFactory.setVirtualHost(serviceInfo.getVirtualHost()); - connectionFactory.setUsername(serviceInfo.getUserName()); - connectionFactory.setPassword(serviceInfo.getPassword()); - if ("amqps".equals(serviceInfo.getScheme())) { - try { - connectionFactory.useSslProtocol(); - } - catch (Exception e) { - throw new IllegalStateException("failed to configure SSL protocol", e); - } + try { + connectionFactory.setUri(serviceInfo.getUri()); + } + catch (Exception e) { + throw new IllegalArgumentException("failed to create ConnectionFactory", e); } - connectionFactory.setPort(serviceInfo.getPort()); CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(connectionFactory); if (serviceConnectorConfiguration != null) { cachingConnectionFactory.setChannelCacheSize(((RabbitConnectionFactoryConfig)serviceConnectorConfiguration).getChannelCacheSize()); From 786f48aa9df6d1811da503e59b553b71cb91d2cf Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Fri, 31 Oct 2014 14:54:33 -0400 Subject: [PATCH 2/2] Removed port defaulting behavior --- .../cloud/service/common/AmqpServiceInfo.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/AmqpServiceInfo.java b/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/AmqpServiceInfo.java index 23982c2..231ab9e 100644 --- a/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/AmqpServiceInfo.java +++ b/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/AmqpServiceInfo.java @@ -39,11 +39,6 @@ public class AmqpServiceInfo extends UriBasedServiceInfo { throw new IllegalArgumentException("missing authority in amqp URI: " + uriInfo); } - int port = uriInfo.getPort(); - if (port == -1) { - port = 5672; - } - String userName = uriInfo.getUserName(); String password = uriInfo.getPassword(); @@ -62,6 +57,6 @@ public class AmqpServiceInfo extends UriBasedServiceInfo { throw new IllegalArgumentException("multiple segments in path of amqp URI: " + uriInfo); } } - return new UriInfo(uriInfo.getScheme(), uriInfo.getHost(), port, uriInfo.getUserName(), uriInfo.getPassword(), path); + return new UriInfo(uriInfo.getScheme(), uriInfo.getHost(), uriInfo.getPort(), uriInfo.getUserName(), uriInfo.getPassword(), path); } }