camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject git commit: CAMEL-6868 Added addresses option to support clustered brokers
Date Mon, 16 Dec 2013 07:13:36 GMT
Updated Branches:
  refs/heads/camel-2.12.x 66cbc0d36 -> df567f9c2


CAMEL-6868 Added addresses option to support clustered brokers


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/df567f9c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/df567f9c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/df567f9c

Branch: refs/heads/camel-2.12.x
Commit: df567f9c210c353d910a5bf11fad557eb0173826
Parents: 66cbc0d
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Mon Dec 16 14:53:43 2013 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Mon Dec 16 15:13:12 2013 +0800

----------------------------------------------------------------------
 .../component/rabbitmq/RabbitMQEndpoint.java     | 19 ++++++++++++++++++-
 .../component/rabbitmq/RabbitMQEndpointTest.java | 10 ++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/df567f9c/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQEndpoint.java
b/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQEndpoint.java
index f54f41f..338c1c5 100644
--- a/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQEndpoint.java
+++ b/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQEndpoint.java
@@ -24,6 +24,7 @@ import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
 import com.rabbitmq.client.AMQP;
+import com.rabbitmq.client.Address;
 import com.rabbitmq.client.Connection;
 import com.rabbitmq.client.ConnectionFactory;
 import com.rabbitmq.client.Envelope;
@@ -54,6 +55,7 @@ public class RabbitMQEndpoint extends DefaultEndpoint {
     private String exchangeName;
     private String exchangeType = "direct";
     private String routingKey;
+    private Address[] addresses;
     
     public RabbitMQEndpoint() {
     }
@@ -107,7 +109,11 @@ public class RabbitMQEndpoint extends DefaultEndpoint {
         }
         factory.setHost(getHostname());
         factory.setPort(getPortNumber());
-        return factory.newConnection(executor);
+        if (getAddresses() == null) {
+            return factory.newConnection(executor);
+        } else {
+            return factory.newConnection(executor, getAddresses());
+        }
     }
 
     @Override
@@ -239,4 +245,15 @@ public class RabbitMQEndpoint extends DefaultEndpoint {
     public boolean isBridgeEndpoint() {
         return bridgeEndpoint;
     }
+    
+    public void setAddresses(String addresses) {
+        Address[] addressArray = Address.parseAddresses(addresses);
+        if (addressArray.length > 0) {
+            this.addresses = addressArray;
+        }
+    }
+    
+    public Address[] getAddresses() {
+        return addresses;
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/df567f9c/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitMQEndpointTest.java
----------------------------------------------------------------------
diff --git a/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitMQEndpointTest.java
b/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitMQEndpointTest.java
index 2f30177..9f22e92 100644
--- a/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitMQEndpointTest.java
+++ b/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitMQEndpointTest.java
@@ -24,6 +24,7 @@ import java.util.UUID;
 import java.util.concurrent.ThreadPoolExecutor;
 
 import com.rabbitmq.client.AMQP;
+import com.rabbitmq.client.Address;
 import com.rabbitmq.client.Envelope;
 import com.rabbitmq.client.impl.LongStringHelper;
 import org.apache.camel.Exchange;
@@ -111,4 +112,13 @@ public class RabbitMQEndpointTest extends CamelTestSupport {
 
         assertTrue(endpoint.isSingleton());
     }
+    
+    @Test
+    public void brokerEndpointAddressesSettings() throws Exception {
+        RabbitMQEndpoint endpoint = context.getEndpoint("rabbitmq:localhost/exchange?addresses=server1:12345,server2:12345",
RabbitMQEndpoint.class);
+        assertEquals("Wrong size of endpoint addresses.", 2, endpoint.getAddresses().length);
+        assertEquals("Get a wrong endpoint address.", new Address("server1", 12345), endpoint.getAddresses()[0]);
+        assertEquals("Get a wrong endpoint address.", new Address("server2", 12345), endpoint.getAddresses()[1]);
+        
+    }
 }


Mime
View raw message