You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by rc...@apache.org on 2024/04/22 02:26:06 UTC

(james-project) 08/10: JAMES-4027 RabbitMQConnection: reduce the default wait time before reconnecting

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

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

commit 47c4f25a8bbd9eab986d954bdd98c4c8e0ccc906
Author: Quan Tran <hq...@linagora.com>
AuthorDate: Thu Apr 11 15:06:24 2024 +0700

    JAMES-4027 RabbitMQConnection: reduce the default wait time before reconnecting
    
    * @param networkRecoveryInterval how long will automatic recovery wait before attempting to reconnect, in ms
    
    It helps James recover quicker when connected RabbitMQ node (in a cluster) is down.
---
 .../james/backends/rabbitmq/RabbitMQConfiguration.java      | 13 ++++++++++++-
 .../docs/modules/ROOT/pages/configure/rabbitmq.adoc         |  3 +++
 .../sample-configuration/rabbitmq.properties                |  5 +++++
 .../sample-configuration/rabbitmq.properties                |  5 +++++
 src/site/xdoc/server/config-rabbitmq.xml                    |  5 +++++
 5 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java
index 8416e76d08..150b7fd838 100644
--- a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java
+++ b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java
@@ -297,6 +297,7 @@ public class RabbitMQConfiguration {
     private static final String HOSTS = "hosts";
     private static final String USE_QUORUM_QUEUES = "quorum.queues.enable";
     private static final String QUORUM_QUEUES_REPLICATION_FACTOR = "quorum.queues.replication.factor";
+    private static final String NETWORK_RECOVERY_INTERVAL = "driver.network.recovery.interval";
     private static final String USE_SSL_MANAGEMENT = "ssl.management.enabled";
 
     private static final String SSL_TRUST_STORE_PATH = "ssl.truststore";
@@ -386,7 +387,7 @@ public class RabbitMQConfiguration {
         static final int DEFAULT_CHANNEL_RPC_TIMEOUT = 60_000;
         static final int DEFAULT_HANDSHAKE_TIMEOUT = 10_000;
         static final int DEFAULT_SHUTDOWN_TIMEOUT = 10_000;
-        static final int DEFAULT_NETWORK_RECOVERY_INTERVAL = 5_000;
+        static final int DEFAULT_NETWORK_RECOVERY_INTERVAL = 100;
         static final int DEFAULT_PORT = 5672;
         static final Duration DEFAULT_TASK_QUEUE_CONSUMER_TIMEOUT = Duration.ofDays(1);
 
@@ -492,10 +493,17 @@ public class RabbitMQConfiguration {
         }
 
         public Builder networkRecoveryIntervalInMs(int networkRecoveryInterval) {
+            Preconditions.checkArgument(networkRecoveryInterval >= 0, "'networkRecoveryInterval' must be non-negative");
             this.networkRecoveryIntervalInMs = Optional.of(networkRecoveryInterval);
             return this;
         }
 
+        public Builder networkRecoveryIntervalInMs(Optional<Integer> networkRecoveryInterval) {
+            return networkRecoveryInterval
+                .map(this::networkRecoveryIntervalInMs)
+                .orElse(this);
+        }
+
         public Builder useSsl(Boolean useSsl) {
             this.useSsl = Optional.ofNullable(useSsl);
             return this;
@@ -613,6 +621,8 @@ public class RabbitMQConfiguration {
         Boolean useQuorumQueues = configuration.getBoolean(USE_QUORUM_QUEUES, null);
         Optional<Integer> quorumQueueReplicationFactor = Optional.ofNullable(configuration.getInteger(QUORUM_QUEUES_REPLICATION_FACTOR, null));
 
+        Optional<Integer> networkRecoveryInterval = Optional.ofNullable(configuration.getInteger(NETWORK_RECOVERY_INTERVAL, null));
+
         List<Host> hosts = Optional.ofNullable(configuration.getList(String.class, HOSTS))
             .map(hostList -> hostList.stream()
                 .map(string -> Host.parseConfString(string, DEFAULT_PORT))
@@ -639,6 +649,7 @@ public class RabbitMQConfiguration {
             .useQuorumQueues(useQuorumQueues)
             .quorumQueueReplicationFactor(quorumQueueReplicationFactor)
             .quorumQueueDeliveryLimit(quorumQueueDeliveryLimit)
+            .networkRecoveryIntervalInMs(networkRecoveryInterval)
             .hosts(hosts)
             .queueTTL(queueTTL)
             .eventBusNotificationDurabilityEnabled(configuration.getBoolean(EVENT_BUS_NOTIFICATION_DURABILITY_ENABLED, null))
diff --git a/server/apps/distributed-app/docs/modules/ROOT/pages/configure/rabbitmq.adoc b/server/apps/distributed-app/docs/modules/ROOT/pages/configure/rabbitmq.adoc
index c4089e29c8..30d5d17dd4 100644
--- a/server/apps/distributed-app/docs/modules/ROOT/pages/configure/rabbitmq.adoc
+++ b/server/apps/distributed-app/docs/modules/ROOT/pages/configure/rabbitmq.adoc
@@ -47,6 +47,9 @@ Optional integer, defaults to 30 seconds.
 | Configure the size of the channel pool.
 Optional integer, defaults to 3
 
+| driver.network.recovery.interval
+| Optional, non-negative integer, default to 100ms. The interval (in ms) that RabbitMQ driver will automatic recovery wait before attempting to reconnect. See https://www.rabbitmq.com/client-libraries/java-api-guide#connection-recovery
+
 | ssl.enabled
 | Is using ssl enabled
 Optional boolean, defaults to false
diff --git a/server/apps/distributed-app/sample-configuration/rabbitmq.properties b/server/apps/distributed-app/sample-configuration/rabbitmq.properties
index 75a562af60..6aa949cd92 100644
--- a/server/apps/distributed-app/sample-configuration/rabbitmq.properties
+++ b/server/apps/distributed-app/sample-configuration/rabbitmq.properties
@@ -39,6 +39,11 @@ management.password=guest
 # Optional integer, defaults to 3
 #channel.pool.size=3
 
+# Optional, non-negative integer, default to 100ms.
+# The interval (in ms) that RabbitMQ driver will automatic recovery wait before attempting to reconnect.
+# See https://www.rabbitmq.com/client-libraries/java-api-guide#connection-recovery
+#driver.network.recovery.interval=100
+
 # Boolean. Whether to activate Quorum queue usage for use cases that benefits from it (work queue).
 # Quorum queues enables high availability.
 # False (default value) results in the usage of classic queues.
diff --git a/server/apps/distributed-pop3-app/sample-configuration/rabbitmq.properties b/server/apps/distributed-pop3-app/sample-configuration/rabbitmq.properties
index 68d4cf743d..ef66b202e7 100644
--- a/server/apps/distributed-pop3-app/sample-configuration/rabbitmq.properties
+++ b/server/apps/distributed-pop3-app/sample-configuration/rabbitmq.properties
@@ -39,6 +39,11 @@ management.password=guest
 # Optional integer, defaults to 3
 #channel.pool.size=3
 
+# Optional, non-negative integer, default to 100ms.
+# The interval (in ms) that RabbitMQ driver will automatic recovery wait before attempting to reconnect.
+# See https://www.rabbitmq.com/client-libraries/java-api-guide#connection-recovery
+#driver.network.recovery.interval=100
+
 # Boolean. Whether to activate Quorum queue usage for use cases that benefits from it (work queue).
 # Quorum queues enables high availability.
 # False (default value) results in the usage of classic queues.
diff --git a/src/site/xdoc/server/config-rabbitmq.xml b/src/site/xdoc/server/config-rabbitmq.xml
index cc651d1ef7..920040d67d 100644
--- a/src/site/xdoc/server/config-rabbitmq.xml
+++ b/src/site/xdoc/server/config-rabbitmq.xml
@@ -79,6 +79,11 @@
           <dd>Configure the size of the channel pool.
               Optional integer, defaults to 3</dd>
 
+          <dt><strong>driver.network.recovery.interval</strong></dt>
+          <dd>Optional, non-negative integer, default to 100ms.
+              The interval (in ms) that RabbitMQ driver will automatic recovery wait before attempting to reconnect.
+              See https://www.rabbitmq.com/client-libraries/java-api-guide#connection-recovery</dd>
+
           <dt><strong>ssl.enabled</strong></dt>
           <dd>Is using ssl enabled
               Optional boolean, defaults to false</dd>


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