You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2020/11/23 08:20:16 UTC

[james-project] 17/19: JAMES-3139 Expose RabbitMQ channel & connection configuration

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

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 47c03b06a1c900f47f099e230ad85ac9a191496d
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Sun Nov 22 15:37:14 2020 +0700

    JAMES-3139 Expose RabbitMQ channel & connection configuration
    
    Easier to adapt:
     - to various needs
     - in case of inappropriate value
---
 .../rabbitmq/ReactorRabbitMQChannelPool.java         | 12 ++++++++++++
 .../backends/rabbitmq/SimpleConnectionPool.java      |  6 ++++++
 .../destination/conf/rabbitmq.properties             | 16 ++++++++++++++++
 .../destination/conf/rabbitmq.properties             | 16 ++++++++++++++++
 .../pages/distributed/configure/rabbitmq.adoc        | 20 ++++++++++++++++++++
 .../org/apache/james/modules/DockerRabbitMQRule.java | 12 ++++++++++++
 .../james/modules/queue/rabbitmq/RabbitMQModule.java | 19 +++++++++++++++----
 .../RabbitMQEventDeadLettersIntegrationTest.java     |  7 +------
 src/site/xdoc/server/config-rabbitmq.xml             | 20 ++++++++++++++++++++
 9 files changed, 118 insertions(+), 10 deletions(-)

diff --git a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/ReactorRabbitMQChannelPool.java b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/ReactorRabbitMQChannelPool.java
index 1de99d3..4e74850 100644
--- a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/ReactorRabbitMQChannelPool.java
+++ b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/ReactorRabbitMQChannelPool.java
@@ -22,6 +22,7 @@ package org.apache.james.backends.rabbitmq;
 import java.io.IOException;
 import java.time.Duration;
 import java.util.Comparator;
+import java.util.Optional;
 import java.util.concurrent.ConcurrentSkipListSet;
 import java.util.function.BiConsumer;
 
@@ -131,6 +132,17 @@ public class ReactorRabbitMQChannelPool implements ChannelPool, Startable {
             return retries -> minBorrowDelay -> maxChannel -> new Configuration(minBorrowDelay, retries, maxChannel);
         }
 
+        public static Configuration from(org.apache.commons.configuration2.Configuration configuration) {
+            Duration minBorrowDelay = Optional.ofNullable(configuration.getLong("channel.pool.min.delay.ms", null))
+                    .map(Duration::ofMillis)
+                    .orElse(MIN_BORROW_DELAY);
+
+            return builder()
+                .retries(configuration.getInt("channel.pool.retries", MAX_BORROW_RETRIES))
+                .minBorrowDelay(minBorrowDelay)
+                .maxChannel(configuration.getInt("channel.pool.size", MAX_CHANNELS_NUMBER));
+        }
+
         private final Duration minBorrowDelay;
         private final int retries;
         private final int maxChannel;
diff --git a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/SimpleConnectionPool.java b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/SimpleConnectionPool.java
index 6941009..635aaa8 100644
--- a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/SimpleConnectionPool.java
+++ b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/SimpleConnectionPool.java
@@ -57,6 +57,12 @@ public class SimpleConnectionPool implements AutoCloseable {
             return retries -> initialDelay -> new Configuration(retries, initialDelay);
         }
 
+        public static Configuration from(org.apache.commons.configuration2.Configuration configuration) {
+            return builder()
+                .retries(configuration.getInt("connection.pool.retries", 10))
+                .initialDelay(Duration.ofMillis(configuration.getLong("connection.pool.min.delay.ms", 100)));
+        }
+
         private final int numRetries;
         private final Duration initialDelay;
 
diff --git a/dockerfiles/run/guice/cassandra-rabbitmq-ldap/destination/conf/rabbitmq.properties b/dockerfiles/run/guice/cassandra-rabbitmq-ldap/destination/conf/rabbitmq.properties
index 05712ed..f8b443d 100644
--- a/dockerfiles/run/guice/cassandra-rabbitmq-ldap/destination/conf/rabbitmq.properties
+++ b/dockerfiles/run/guice/cassandra-rabbitmq-ldap/destination/conf/rabbitmq.properties
@@ -13,6 +13,22 @@ management.user=guest
 # Mandatory
 management.password=guest
 
+# Configure retries count to retrieve a connection. Exponential backoff is performed between each retries.
+# Optional integer, defaults to 10
+#connection.pool.retries=10
+# Configure initial duration (in ms) between two connection retries. Exponential backoff is performed between each retries.
+# Optional integer, defaults to 100
+#connection.pool.min.delay.ms=100
+# Configure retries count to retrieve a channel. Exponential backoff is performed between each retries.
+# Optional integer, defaults to 3
+#channel.pool.retries=3
+# Configure initial duration (in ms) between two channel retries. Exponential backoff is performed between each retries.
+# Optional integer, defaults to 50
+#channel.pool.min.delay.ms=50
+# Configure the size of the channel pool.
+# Optional integer, defaults to 3
+#channel.pool.size=3
+
 # Parameters for the Cassandra administrative view
 
 # Period of the window. Too large values will lead to wide rows while too little values might lead to many queries.
diff --git a/dockerfiles/run/guice/cassandra-rabbitmq/destination/conf/rabbitmq.properties b/dockerfiles/run/guice/cassandra-rabbitmq/destination/conf/rabbitmq.properties
index c2052b2..83c4019 100644
--- a/dockerfiles/run/guice/cassandra-rabbitmq/destination/conf/rabbitmq.properties
+++ b/dockerfiles/run/guice/cassandra-rabbitmq/destination/conf/rabbitmq.properties
@@ -13,6 +13,22 @@ management.user=guest
 # Mandatory
 management.password=guest
 
+# Configure retries count to retrieve a connection. Exponential backoff is performed between each retries.
+# Optional integer, defaults to 10
+#connection.pool.retries=10
+# Configure initial duration (in ms) between two connection retries. Exponential backoff is performed between each retries.
+# Optional integer, defaults to 100
+#connection.pool.min.delay.ms=100
+# Configure retries count to retrieve a channel. Exponential backoff is performed between each retries.
+# Optional integer, defaults to 3
+#channel.pool.retries=3
+# Configure initial duration (in ms) between two channel retries. Exponential backoff is performed between each retries.
+# Optional integer, defaults to 50
+#channel.pool.min.delay.ms=50
+# Configure the size of the channel pool.
+# Optional integer, defaults to 3
+#channel.pool.size=3
+
 # Parameters for the Cassandra administrative view
 
 # Period of the window. Too large values will lead to wide rows while too little values might lead to many queries.
diff --git a/docs/modules/servers/pages/distributed/configure/rabbitmq.adoc b/docs/modules/servers/pages/distributed/configure/rabbitmq.adoc
index fdd6572..589460b 100644
--- a/docs/modules/servers/pages/distributed/configure/rabbitmq.adoc
+++ b/docs/modules/servers/pages/distributed/configure/rabbitmq.adoc
@@ -26,6 +26,26 @@ Details about URI format is in https://www.rabbitmq.com/management.html#usage-ui
 | management.password
 | password used to access management service
 
+| connection.pool.retries
+| Configure retries count to retrieve a connection. Exponential backoff is performed between each retries.
+Optional integer, defaults to 10
+
+| connection.pool.min.delay.ms
+| Configure initial duration (in ms) between two connection retries. Exponential backoff is performed between each retries.
+Optional integer, defaults to 100
+
+| channel.pool.retries
+| Configure retries count to retrieve a channel. Exponential backoff is performed between each retries.
+Optional integer, defaults to 3
+
+| channel.pool.min.delay.ms
+| Configure initial duration (in ms) between two channel retries. Exponential backoff is performed between each retries.
+Optional integer, defaults to 50
+
+| channel.pool.size
+| Configure the size of the channel pool.
+Optional integer, defaults to 3
+
 |===
 
 == RabbitMQ MailQueue Configuration
diff --git a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/DockerRabbitMQRule.java b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/DockerRabbitMQRule.java
index 08889b8..4556b03 100644
--- a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/DockerRabbitMQRule.java
+++ b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/DockerRabbitMQRule.java
@@ -22,12 +22,15 @@ package org.apache.james.modules;
 import static org.apache.james.backends.rabbitmq.RabbitMQFixture.DEFAULT_MANAGEMENT_CREDENTIAL;
 
 import java.net.URISyntaxException;
+import java.time.Duration;
 
 import org.apache.james.CleanupTasksPerformer;
 import org.apache.james.GuiceModuleTestRule;
 import org.apache.james.backends.rabbitmq.DockerRabbitMQ;
 import org.apache.james.backends.rabbitmq.DockerRabbitMQSingleton;
 import org.apache.james.backends.rabbitmq.RabbitMQConfiguration;
+import org.apache.james.backends.rabbitmq.ReactorRabbitMQChannelPool;
+import org.apache.james.backends.rabbitmq.SimpleConnectionPool;
 import org.junit.runner.Description;
 import org.junit.runners.model.Statement;
 
@@ -56,6 +59,15 @@ public class DockerRabbitMQRule implements GuiceModuleTestRule {
                     throw new RuntimeException(e);
                 }
             },
+            binder -> binder.bind(ReactorRabbitMQChannelPool.Configuration.class)
+                .toInstance(ReactorRabbitMQChannelPool.Configuration.builder()
+                    .retries(2)
+                    .minBorrowDelay(java.time.Duration.ofMillis(5))
+                    .maxChannel(3)),
+            binder -> binder.bind(SimpleConnectionPool.Configuration.class)
+                .toInstance(SimpleConnectionPool.Configuration.builder()
+                    .retries(2)
+                    .initialDelay(Duration.ofMillis(5))),
             binder -> Multibinder.newSetBinder(binder, CleanupTasksPerformer.CleanupTask.class)
                 .addBinding()
                 .to(TestRabbitMQModule.QueueCleanUp.class));
diff --git a/server/container/guice/queue/rabbitmq/src/main/java/org/apache/james/modules/queue/rabbitmq/RabbitMQModule.java b/server/container/guice/queue/rabbitmq/src/main/java/org/apache/james/modules/queue/rabbitmq/RabbitMQModule.java
index 18ae72e..2e58ce2 100644
--- a/server/container/guice/queue/rabbitmq/src/main/java/org/apache/james/modules/queue/rabbitmq/RabbitMQModule.java
+++ b/server/container/guice/queue/rabbitmq/src/main/java/org/apache/james/modules/queue/rabbitmq/RabbitMQModule.java
@@ -21,6 +21,7 @@ package org.apache.james.modules.queue.rabbitmq;
 import java.io.FileNotFoundException;
 
 import javax.inject.Named;
+import javax.inject.Provider;
 import javax.inject.Singleton;
 
 import org.apache.commons.configuration2.ex.ConfigurationException;
@@ -178,13 +179,23 @@ public class RabbitMQModule extends AbstractModule {
 
     @Provides
     @Singleton
-    public SimpleConnectionPool.Configuration provideConnectionPoolConfiguration() {
-        return SimpleConnectionPool.Configuration.DEFAULT;
+    public SimpleConnectionPool.Configuration provideConnectionPoolConfiguration(@Named(RABBITMQ_CONFIGURATION_NAME) Provider<org.apache.commons.configuration2.Configuration> configuration) {
+        try {
+            return SimpleConnectionPool.Configuration.from(configuration.get());
+        } catch (Exception e) {
+            LOGGER.info("Error while retrieving SimpleConnectionPool.Configuration, falling back to defaults.", e);
+            return SimpleConnectionPool.Configuration.DEFAULT;
+        }
     }
 
     @Provides
     @Singleton
-    public ReactorRabbitMQChannelPool.Configuration provideChannelPoolConfiguration() {
-        return ReactorRabbitMQChannelPool.Configuration.DEFAULT;
+    public ReactorRabbitMQChannelPool.Configuration provideChannelPoolConfiguration(@Named(RABBITMQ_CONFIGURATION_NAME) Provider<org.apache.commons.configuration2.Configuration> configuration) {
+        try {
+            return ReactorRabbitMQChannelPool.Configuration.from(configuration.get());
+        } catch (Exception e) {
+            LOGGER.info("Error while retrieving ReactorRabbitMQChannelPool.Configuration, falling back to defaults.", e);
+            return ReactorRabbitMQChannelPool.Configuration.DEFAULT;
+        }
     }
 }
diff --git a/server/protocols/webadmin-integration-test/distributed-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/rabbitmq/RabbitMQEventDeadLettersIntegrationTest.java b/server/protocols/webadmin-integration-test/distributed-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/rabbitmq/RabbitMQEventDeadLettersIntegrationTest.java
index 840f226..6fd1454 100644
--- a/server/protocols/webadmin-integration-test/distributed-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/rabbitmq/RabbitMQEventDeadLettersIntegrationTest.java
+++ b/server/protocols/webadmin-integration-test/distributed-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/rabbitmq/RabbitMQEventDeadLettersIntegrationTest.java
@@ -224,12 +224,7 @@ class RabbitMQEventDeadLettersIntegrationTest {
                     .maxRetries(MAX_RETRIES)
                     .firstBackoff(java.time.Duration.ofMillis(10))
                     .jitterFactor(0.2)
-                    .build()))
-            .overrideWith(binder -> binder.bind(ReactorRabbitMQChannelPool.Configuration.class)
-                .toInstance(ReactorRabbitMQChannelPool.Configuration.builder()
-                    .retries(2)
-                    .minBorrowDelay(java.time.Duration.ofMillis(5))
-                    .maxChannel(3))))
+                    .build())))
         .build();
 
     private static final String DOMAIN = "domain.tld";
diff --git a/src/site/xdoc/server/config-rabbitmq.xml b/src/site/xdoc/server/config-rabbitmq.xml
index bb998b2..b0b7e7a 100644
--- a/src/site/xdoc/server/config-rabbitmq.xml
+++ b/src/site/xdoc/server/config-rabbitmq.xml
@@ -57,6 +57,26 @@
 
           <dt><strong>management.password</strong></dt>
           <dd>password used to access management service</dd>
+
+          <dt><strong>connection.pool.retries</strong></dt>
+          <dd>Configure retries count to retrieve a connection. Exponential backoff is performed between each retries.
+              Optional integer, defaults to 10</dd>
+
+          <dt><strong>connection.pool.min.delay.ms</strong></dt>
+          <dd>Configure initial duration (in ms) between two connection retries. Exponential backoff is performed between each retries.
+              Optional integer, defaults to 100</dd>
+
+          <dt><strong>channel.pool.retries</strong></dt>
+          <dd>Configure retries count to retrieve a channel. Exponential backoff is performed between each retries.
+              Optional integer, defaults to 3</dd>
+
+          <dt><strong>channel.pool.min.delay.ms</strong></dt>
+          <dd>Configure initial duration (in ms) between two channel retries. Exponential backoff is performed between each retries.
+              Optional integer, defaults to 50</dd>
+
+          <dt><strong>channel.pool.size</strong></dt>
+          <dd>Configure the size of the channel pool.
+              Optional integer, defaults to 3</dd>
       </dl>
   </section>
 


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org