You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2019/08/22 06:15:30 UTC

[camel] 04/07: CAMEL-13870: Fast property configuration of Camel endpoints. Work in progress.

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch CAMEL-13870
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 7f09a79b3f501d1eb95355f1d3f9d31320c6386f
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Aug 22 06:44:58 2019 +0200

    CAMEL-13870: Fast property configuration of Camel endpoints. Work in progress.
---
 .../src/main/docs/rabbitmq-component.adoc          |  2 +-
 .../component/rabbitmq/RabbitMQComponent.java      | 16 +-------
 .../camel/component/rabbitmq/RabbitMQEndpoint.java | 26 +++++-------
 .../component/rabbitmq/RabbitMQEndpointTest.java   |  6 +--
 .../dsl/RabbitMQEndpointBuilderFactory.java        | 48 ++--------------------
 5 files changed, 20 insertions(+), 78 deletions(-)

diff --git a/components/camel-rabbitmq/src/main/docs/rabbitmq-component.adoc b/components/camel-rabbitmq/src/main/docs/rabbitmq-component.adoc
index 36f18ff..d5a5310 100644
--- a/components/camel-rabbitmq/src/main/docs/rabbitmq-component.adoc
+++ b/components/camel-rabbitmq/src/main/docs/rabbitmq-component.adoc
@@ -133,7 +133,7 @@ with the following path and query parameters:
 [width="100%",cols="2,5,^1,2",options="header"]
 |===
 | Name | Description | Default | Type
-| *addresses* (common) | If this option is set, camel-rabbitmq will try to create connection based on the setting of option addresses. The addresses value is a string which looks like server1:12345, server2:12345 |  | Address[]
+| *addresses* (common) | If this option is set, camel-rabbitmq will try to create connection based on the setting of option addresses. The addresses value is a string which looks like server1:12345, server2:12345 |  | String
 | *autoDelete* (common) | If it is true, the exchange will be deleted when it is no longer in use | true | boolean
 | *automaticRecoveryEnabled* (common) | Enables connection automatic recovery (uses connection implementation that performs automatic recovery when existing connection has failures) | true | Boolean
 | *connectionFactory* (common) | To use a custom RabbitMQ connection factory. When this option is set, all connection options (connectionTimeout, requestedChannelMax...) set on URI are not used |  | ConnectionFactory
diff --git a/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQComponent.java b/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQComponent.java
index ea40551..e0da35a 100644
--- a/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQComponent.java
+++ b/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQComponent.java
@@ -49,7 +49,7 @@ public class RabbitMQComponent extends DefaultComponent {
     @Metadata(label = "common", defaultValue = ConnectionFactory.DEFAULT_VHOST)
     private String vhost = ConnectionFactory.DEFAULT_VHOST;
     @Metadata(label = "common")
-    private Address[] addresses;
+    private String addresses;
     @Metadata(label = "common")
     private ConnectionFactory connectionFactory;
     @Metadata(label = "consumer", defaultValue = "true")
@@ -324,22 +324,10 @@ public class RabbitMQComponent extends DefaultComponent {
      * looks like "server1:12345, server2:12345"
      */
     public void setAddresses(String addresses) {
-        Address[] addressArray = Address.parseAddresses(addresses);
-        if (addressArray.length > 0) {
-            this.addresses = addressArray;
-        }
-    }
-
-    /**
-     * If this option is set, camel-rabbitmq will try to create connection based
-     * on the setting of option addresses. The addresses value is a string which
-     * looks like "server1:12345, server2:12345"
-     */
-    public void setAddresses(Address[] addresses) {
         this.addresses = addresses;
     }
 
-    public Address[] getAddresses() {
+    public String getAddresses() {
         return addresses;
     }
 
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 56c01f9..58db20a 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
@@ -101,7 +101,7 @@ public class RabbitMQEndpoint extends DefaultEndpoint implements AsyncEndpoint {
     @UriParam(label = "common")
     private boolean skipExchangeDeclare;
     @UriParam(label = "common")
-    private Address[] addresses;
+    private String addresses;
     @UriParam(label = "common", defaultValue = "true")
     private Boolean automaticRecoveryEnabled = Boolean.TRUE;
     @UriParam(label = "advanced", defaultValue = "" + ConnectionFactory.DEFAULT_CONNECTION_TIMEOUT)
@@ -220,7 +220,7 @@ public class RabbitMQEndpoint extends DefaultEndpoint implements AsyncEndpoint {
         if (getAddresses() == null) {
             return getOrCreateConnectionFactory().newConnection(executor);
         } else {
-            return getOrCreateConnectionFactory().newConnection(executor, getAddresses());
+            return getOrCreateConnectionFactory().newConnection(executor, parseAddresses());
         }
     }
 
@@ -452,25 +452,21 @@ public class RabbitMQEndpoint extends DefaultEndpoint implements AsyncEndpoint {
      * looks like "server1:12345, server2:12345"
      */
     public void setAddresses(String addresses) {
-        Address[] addressArray = Address.parseAddresses(addresses);
-        if (addressArray.length > 0) {
-            this.addresses = addressArray;
-        }
-    }
-
-    /**
-     * If this option is set, camel-rabbitmq will try to create connection based
-     * on the setting of option addresses. The addresses value is a string which
-     * looks like "server1:12345, server2:12345"
-     */
-    public void setAddresses(Address[] addresses) {
         this.addresses = addresses;
     }
 
-    public Address[] getAddresses() {
+    public String getAddresses() {
         return addresses;
     }
 
+    public Address[] parseAddresses() {
+        if (addresses != null) {
+            return Address.parseAddresses(getAddresses());
+        } else {
+            return null;
+        }
+    }
+
     public int getConnectionTimeout() {
         return connectionTimeout;
     }
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 ba20ac5..0b5dcee 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
@@ -178,9 +178,9 @@ public class RabbitMQEndpointTest extends CamelTestSupport {
     @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]);
+        assertEquals("Wrong size of endpoint addresses.", 2, endpoint.parseAddresses().length);
+        assertEquals("Get a wrong endpoint address.", new Address("server1", 12345), endpoint.parseAddresses()[0]);
+        assertEquals("Get a wrong endpoint address.", new Address("server2", 12345), endpoint.parseAddresses()[1]);
     }
 
     private ConnectionFactory createConnectionFactory(String uri) throws TimeoutException {
diff --git a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/RabbitMQEndpointBuilderFactory.java b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/RabbitMQEndpointBuilderFactory.java
index 2007b1f..f5cb6ae 100644
--- a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/RabbitMQEndpointBuilderFactory.java
+++ b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/RabbitMQEndpointBuilderFactory.java
@@ -48,21 +48,7 @@ public interface RabbitMQEndpointBuilderFactory {
          * based on the setting of option addresses. The addresses value is a
          * string which looks like server1:12345, server2:12345.
          * 
-         * The option is a: <code>com.rabbitmq.client.Address[]</code> type.
-         * 
-         * Group: common
-         */
-        default RabbitMQEndpointConsumerBuilder addresses(Object[] addresses) {
-            setProperty("addresses", addresses);
-            return this;
-        }
-        /**
-         * If this option is set, camel-rabbitmq will try to create connection
-         * based on the setting of option addresses. The addresses value is a
-         * string which looks like server1:12345, server2:12345.
-         * 
-         * The option will be converted to a
-         * <code>com.rabbitmq.client.Address[]</code> type.
+         * The option is a: <code>java.lang.String</code> type.
          * 
          * Group: common
          */
@@ -1187,21 +1173,7 @@ public interface RabbitMQEndpointBuilderFactory {
          * based on the setting of option addresses. The addresses value is a
          * string which looks like server1:12345, server2:12345.
          * 
-         * The option is a: <code>com.rabbitmq.client.Address[]</code> type.
-         * 
-         * Group: common
-         */
-        default RabbitMQEndpointProducerBuilder addresses(Object[] addresses) {
-            setProperty("addresses", addresses);
-            return this;
-        }
-        /**
-         * If this option is set, camel-rabbitmq will try to create connection
-         * based on the setting of option addresses. The addresses value is a
-         * string which looks like server1:12345, server2:12345.
-         * 
-         * The option will be converted to a
-         * <code>com.rabbitmq.client.Address[]</code> type.
+         * The option is a: <code>java.lang.String</code> type.
          * 
          * Group: common
          */
@@ -2306,21 +2278,7 @@ public interface RabbitMQEndpointBuilderFactory {
          * based on the setting of option addresses. The addresses value is a
          * string which looks like server1:12345, server2:12345.
          * 
-         * The option is a: <code>com.rabbitmq.client.Address[]</code> type.
-         * 
-         * Group: common
-         */
-        default RabbitMQEndpointBuilder addresses(Object[] addresses) {
-            setProperty("addresses", addresses);
-            return this;
-        }
-        /**
-         * If this option is set, camel-rabbitmq will try to create connection
-         * based on the setting of option addresses. The addresses value is a
-         * string which looks like server1:12345, server2:12345.
-         * 
-         * The option will be converted to a
-         * <code>com.rabbitmq.client.Address[]</code> type.
+         * The option is a: <code>java.lang.String</code> type.
          * 
          * Group: common
          */