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 2022/04/20 15:13:37 UTC

[james-project] branch master updated (895ec9ac72 -> 4f054e0285)

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

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


    from 895ec9ac72 [DOCUMENTATION] Document implemented standards for Distributed server
     new 8564a2ecf7 JAMES-3747 Reactive implementation for RabbitMQ channelPool
     new 6ad24d4da0 JAMES-3747 Metrics for RabbitMQ channelPool
     new 4fe69344f5 JAMES-3749 Shorten rabbitmq routing keys
     new f9069aff92 JAMES-3749 Allow disable durability, publish confirms
     new 3b25be1f65 JAMES-3747 Fix badly renamed minDelay methods
     new 4f054e0285 JAMES-3747 Fix a typo

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 backends-common/rabbitmq/pom.xml                   |  17 +-
 .../backends/rabbitmq/RabbitMQConfiguration.java   |  44 ++++-
 .../rabbitmq/ReactorRabbitMQChannelPool.java       | 208 ++++++++-------------
 .../backends/rabbitmq/ChannelPoolContract.java     |  10 +-
 .../james/backends/rabbitmq/RabbitMQExtension.java |   6 +-
 .../rabbitmq/ReactorRabbitMQChannelPoolTest.java   |   6 +-
 .../events/EventBusConcurrentTestContract.java     |  12 +-
 event-bus/distributed/pom.xml                      |   4 -
 .../org/apache/james/events/EventDispatcher.java   |  19 +-
 .../james/events/KeyRegistrationHandler.java       |  12 +-
 .../org/apache/james/events/RabbitMQEventBus.java  |  14 +-
 .../apache/james/events/RoutingKeyConverter.java   |   4 +-
 .../org/apache/james/events/NetworkErrorTest.java  |   6 +-
 .../apache/james/events/RabbitMQEventBusTest.java  |  19 +-
 .../james/events/RoutingKeyConverterTest.java      |  10 +-
 mailet/amqp/pom.xml                                |   4 +
 .../transport/mailets/AmqpForwardAttribute.java    |  12 +-
 .../mailets/AmqpForwardAttributeTest.java          |   3 +-
 .../rabbitmq/host/RabbitMQEventBusHostSystem.java  |   3 +-
 pom.xml                                            |   5 -
 .../modules/ROOT/pages/configure/rabbitmq.adoc     |  19 +-
 .../sample-configuration/rabbitmq.properties       |   6 +-
 .../apache/james/modules/DockerRabbitMQRule.java   |   2 +-
 .../sample-configuration/rabbitmq.properties       |   6 +-
 .../modules/queue/rabbitmq/RabbitMQModule.java     |   8 +-
 .../org/apache/james/queue/rabbitmq/Enqueuer.java  |  38 ++--
 .../queue/rabbitmq/RabbitMQMailQueueFactory.java   |   2 +-
 .../view/RabbitMQMailQueueConfiguration.java       |  26 ++-
 server/task/task-distributed/pom.xml               |   5 +
 src/site/xdoc/server/config-rabbitmq.xml           |  16 +-
 30 files changed, 308 insertions(+), 238 deletions(-)


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


[james-project] 03/06: JAMES-3749 Shorten rabbitmq routing keys

Posted by bt...@apache.org.
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 4fe69344f5fe0e45780bf409cabfceb3a0bce588
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu Apr 14 14:45:32 2022 +0700

    JAMES-3749 Shorten rabbitmq routing keys
---
 .../main/java/org/apache/james/events/RoutingKeyConverter.java |  4 ++--
 .../java/org/apache/james/events/RoutingKeyConverterTest.java  | 10 +++++-----
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/event-bus/distributed/src/main/java/org/apache/james/events/RoutingKeyConverter.java b/event-bus/distributed/src/main/java/org/apache/james/events/RoutingKeyConverter.java
index a8f9700ddd..d4886596b4 100644
--- a/event-bus/distributed/src/main/java/org/apache/james/events/RoutingKeyConverter.java
+++ b/event-bus/distributed/src/main/java/org/apache/james/events/RoutingKeyConverter.java
@@ -51,7 +51,7 @@ public class RoutingKeyConverter {
         }
 
         String asString() {
-            return registrationKey.map(key -> key.getClass().getName() + SEPARATOR + key.asString())
+            return registrationKey.map(key -> key.getClass().getSimpleName() + SEPARATOR + key.asString())
                 .orElse(EMPTY_ROUTING_KEY);
         }
     }
@@ -66,7 +66,7 @@ public class RoutingKeyConverter {
     @Inject
     public RoutingKeyConverter(Set<RegistrationKey.Factory> factories) {
         this.factories = factories.stream()
-            .collect(ImmutableMap.toImmutableMap(factory -> factory.forClass().getName(), f -> f));
+            .collect(ImmutableMap.toImmutableMap(factory -> factory.forClass().getSimpleName(), f -> f));
     }
 
     RegistrationKey toRegistrationKey(String routingKey) {
diff --git a/event-bus/distributed/src/test/java/org/apache/james/events/RoutingKeyConverterTest.java b/event-bus/distributed/src/test/java/org/apache/james/events/RoutingKeyConverterTest.java
index f41bfa3203..73e6cf49c1 100644
--- a/event-bus/distributed/src/test/java/org/apache/james/events/RoutingKeyConverterTest.java
+++ b/event-bus/distributed/src/test/java/org/apache/james/events/RoutingKeyConverterTest.java
@@ -70,7 +70,7 @@ class RoutingKeyConverterTest {
     }
 
     private static final RegistrationKey REGISTRATION_KEY_1 = new TestRegistrationKey("a");
-    private static final String ROUTING_KEY_1 = "org.apache.james.events.EventBusTestFixture$TestRegistrationKey:a";
+    private static final String ROUTING_KEY_1 = "TestRegistrationKey:a";
 
     private RoutingKeyConverter testee = RoutingKeyConverter.forFactories(
         new OtherTestRegistrationKey.Factory(),
@@ -91,24 +91,24 @@ class RoutingKeyConverterTest {
     @Test
     void toRoutingKeyShouldAcceptSeparator() {
         assertThat(RoutingKeyConverter.RoutingKey.of(new OtherTestRegistrationKey("a:b")).asString())
-            .isEqualTo("org.apache.james.events.RoutingKeyConverterTest$OtherTestRegistrationKey:a:b");
+            .isEqualTo("OtherTestRegistrationKey:a:b");
     }
 
     @Test
     void toRegistrationKeyShouldAcceptSeparator() {
-        assertThat(testee.toRegistrationKey("org.apache.james.events.RoutingKeyConverterTest$OtherTestRegistrationKey:a:b"))
+        assertThat(testee.toRegistrationKey("OtherTestRegistrationKey:a:b"))
             .isEqualTo(new OtherTestRegistrationKey("a:b"));
     }
 
     @Test
     void toRoutingKeyShouldAcceptEmptyValue() {
         assertThat(RoutingKeyConverter.RoutingKey.of(new OtherTestRegistrationKey("")).asString())
-            .isEqualTo("org.apache.james.events.RoutingKeyConverterTest$OtherTestRegistrationKey:");
+            .isEqualTo("OtherTestRegistrationKey:");
     }
 
     @Test
     void toRegistrationKeyShouldAcceptEmptyValue() {
-        assertThat(testee.toRegistrationKey("org.apache.james.events.RoutingKeyConverterTest$OtherTestRegistrationKey:"))
+        assertThat(testee.toRegistrationKey("OtherTestRegistrationKey:"))
             .isEqualTo(new OtherTestRegistrationKey(""));
     }
 


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


[james-project] 01/06: JAMES-3747 Reactive implementation for RabbitMQ channelPool

Posted by bt...@apache.org.
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 8564a2ecf72e0a7ef404fe491799fb8140dea1f6
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu Apr 14 11:29:33 2022 +0700

    JAMES-3747 Reactive implementation for RabbitMQ channelPool
---
 backends-common/rabbitmq/pom.xml                   |   8 +-
 .../rabbitmq/ReactorRabbitMQChannelPool.java       | 182 +++++++--------------
 .../backends/rabbitmq/ChannelPoolContract.java     |  10 +-
 .../rabbitmq/ReactorRabbitMQChannelPoolTest.java   |   2 +-
 event-bus/distributed/pom.xml                      |   4 -
 .../org/apache/james/events/NetworkErrorTest.java  |   6 +-
 pom.xml                                            |   5 -
 .../modules/ROOT/pages/configure/rabbitmq.adoc     |   6 +-
 .../sample-configuration/rabbitmq.properties       |   6 +-
 .../sample-configuration/rabbitmq.properties       |   6 +-
 src/site/xdoc/server/config-rabbitmq.xml           |   6 +-
 11 files changed, 88 insertions(+), 153 deletions(-)

diff --git a/backends-common/rabbitmq/pom.xml b/backends-common/rabbitmq/pom.xml
index 8325eb8dee..d65cb6f8a1 100644
--- a/backends-common/rabbitmq/pom.xml
+++ b/backends-common/rabbitmq/pom.xml
@@ -73,6 +73,10 @@
             <groupId>io.github.openfeign</groupId>
             <artifactId>feign-slf4j</artifactId>
         </dependency>
+        <dependency>
+            <groupId>io.projectreactor.addons</groupId>
+            <artifactId>reactor-pool</artifactId>
+        </dependency>
         <dependency>
             <groupId>io.projectreactor.rabbitmq</groupId>
             <artifactId>reactor-rabbitmq</artifactId>
@@ -89,10 +93,6 @@
             <groupId>org.apache.commons</groupId>
             <artifactId>commons-configuration2</artifactId>
         </dependency>
-        <dependency>
-            <groupId>org.apache.commons</groupId>
-            <artifactId>commons-pool2</artifactId>
-        </dependency>
         <dependency>
             <groupId>org.apache.httpcomponents</groupId>
             <artifactId>httpclient</artifactId>
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 a98d11fa91..6c33dc77f1 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
@@ -21,28 +21,24 @@ package org.apache.james.backends.rabbitmq;
 
 import java.io.IOException;
 import java.time.Duration;
-import java.util.Comparator;
 import java.util.Map;
+import java.util.NoSuchElementException;
 import java.util.Optional;
 import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ConcurrentSkipListSet;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.TimeoutException;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.function.BiConsumer;
 
 import javax.annotation.PreDestroy;
 
-import org.apache.commons.pool2.BasePooledObjectFactory;
-import org.apache.commons.pool2.PooledObject;
-import org.apache.commons.pool2.impl.DefaultPooledObject;
-import org.apache.commons.pool2.impl.GenericObjectPool;
-import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
 import org.apache.james.lifecycle.api.Startable;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.github.fge.lambdas.Throwing;
 import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
 import com.rabbitmq.client.AMQP;
 import com.rabbitmq.client.BuiltinExchangeType;
 import com.rabbitmq.client.CancelCallback;
@@ -65,6 +61,9 @@ import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
 import reactor.core.publisher.SignalType;
 import reactor.core.scheduler.Schedulers;
+import reactor.pool.InstrumentedPool;
+import reactor.pool.PoolBuilder;
+import reactor.pool.PooledRef;
 import reactor.rabbitmq.BindingSpecification;
 import reactor.rabbitmq.ChannelPool;
 import reactor.rabbitmq.QueueSpecification;
@@ -596,54 +595,6 @@ public class ReactorRabbitMQChannelPool implements ChannelPool, Startable {
         }
     }
 
-    private static class ChannelClosedException extends IOException {
-        ChannelClosedException(String message) {
-            super(message);
-        }
-    }
-
-    static class ChannelFactory extends BasePooledObjectFactory<Channel> {
-
-        private static final Logger LOGGER = LoggerFactory.getLogger(ChannelFactory.class);
-
-        private final Mono<Connection> connectionMono;
-        private final Configuration configuration;
-
-        ChannelFactory(Mono<Connection> connectionMono, Configuration configuration) {
-            this.connectionMono = connectionMono;
-            this.configuration = configuration;
-        }
-
-        @Override
-        public Channel create() {
-            return connectionMono
-                .flatMap(this::openChannel)
-                .block();
-        }
-
-        private Mono<? extends Channel> openChannel(Connection connection) {
-            return Mono.fromCallable(connection::openChannel)
-                .map(maybeChannel ->
-                    maybeChannel.orElseThrow(() -> new RuntimeException("RabbitMQ reached to maximum opened channels, cannot get more channels")))
-                .map(SelectOnceChannel::new)
-                .retryWhen(configuration.backoffSpec().scheduler(Schedulers.elastic()))
-                .doOnError(throwable -> LOGGER.error("error when creating new channel", throwable));
-        }
-
-        @Override
-        public PooledObject<Channel> wrap(Channel obj) {
-            return new DefaultPooledObject<>(obj);
-        }
-
-        @Override
-        public void destroyObject(PooledObject<Channel> pooledObject) throws Exception {
-            Channel channel = pooledObject.getObject();
-            if (channel.isOpen()) {
-                channel.close();
-            }
-        }
-    }
-
     public static class Configuration {
         @FunctionalInterface
         public interface RequiresRetries {
@@ -662,7 +613,7 @@ public class ReactorRabbitMQChannelPool implements ChannelPool, Startable {
 
         public static final Configuration DEFAULT = builder()
             .retries(MAX_BORROW_RETRIES)
-            .minBorrowDelay(MIN_BORROW_DELAY)
+            .minBorrowDelay(MAX_BORROW_DELAY)
             .maxChannel(MAX_CHANNELS_NUMBER);
 
         public static RequiresRetries builder() {
@@ -670,28 +621,28 @@ public class ReactorRabbitMQChannelPool implements ChannelPool, Startable {
         }
 
         public static Configuration from(org.apache.commons.configuration2.Configuration configuration) {
-            Duration minBorrowDelay = Optional.ofNullable(configuration.getLong("channel.pool.min.delay.ms", null))
+            Duration maxBorrowDelay = Optional.ofNullable(configuration.getLong("channel.pool.max.delay.ms", null))
                     .map(Duration::ofMillis)
-                    .orElse(MIN_BORROW_DELAY);
+                    .orElse(MAX_BORROW_DELAY);
 
             return builder()
                 .retries(configuration.getInt("channel.pool.retries", MAX_BORROW_RETRIES))
-                .minBorrowDelay(minBorrowDelay)
+                .minBorrowDelay(maxBorrowDelay)
                 .maxChannel(configuration.getInt("channel.pool.size", MAX_CHANNELS_NUMBER));
         }
 
-        private final Duration minBorrowDelay;
+        private final Duration maxBorrowDelay;
         private final int retries;
         private final int maxChannel;
 
-        public Configuration(Duration minBorrowDelay, int retries, int maxChannel) {
-            this.minBorrowDelay = minBorrowDelay;
+        public Configuration(Duration maxBorrowDelay, int retries, int maxChannel) {
+            this.maxBorrowDelay = maxBorrowDelay;
             this.retries = retries;
             this.maxChannel = maxChannel;
         }
 
         private RetryBackoffSpec backoffSpec() {
-            return Retry.backoff(retries, minBorrowDelay);
+            return Retry.backoff(retries, maxBorrowDelay);
         }
 
         public int getMaxChannel() {
@@ -700,26 +651,45 @@ public class ReactorRabbitMQChannelPool implements ChannelPool, Startable {
     }
 
     private static final Logger LOGGER = LoggerFactory.getLogger(ReactorRabbitMQChannelPool.class);
-    private static final long MAXIMUM_BORROW_TIMEOUT_IN_MS = Duration.ofSeconds(5).toMillis();
     private static final int MAX_CHANNELS_NUMBER = 3;
     private static final int MAX_BORROW_RETRIES = 3;
-    private static final Duration MIN_BORROW_DELAY = Duration.ofMillis(50);
+    private static final Duration MAX_BORROW_DELAY = Duration.ofSeconds(30);
 
+    private final ConcurrentHashMap<Integer, PooledRef<? extends Channel>> refs = new ConcurrentHashMap<>();
     private final Mono<Connection> connectionMono;
-    private final GenericObjectPool<Channel> pool;
-    private final ConcurrentSkipListSet<Channel> borrowedChannels;
     private final Configuration configuration;
+
+    private final InstrumentedPool<? extends Channel> newPool;
     private Sender sender;
 
     public ReactorRabbitMQChannelPool(Mono<Connection> connectionMono, Configuration configuration) {
         this.connectionMono = connectionMono;
         this.configuration = configuration;
-        ChannelFactory channelFactory = new ChannelFactory(connectionMono, configuration);
 
-        GenericObjectPoolConfig<Channel> config = new GenericObjectPoolConfig<>();
-        config.setMaxTotal(configuration.getMaxChannel());
-        this.pool = new GenericObjectPool<>(channelFactory, config);
-        this.borrowedChannels = new ConcurrentSkipListSet<>(Comparator.comparingInt(System::identityHashCode));
+        newPool = PoolBuilder.from(connectionMono
+            .flatMap(this::openChannel))
+            .sizeBetween(1, configuration.maxChannel)
+            .acquisitionScheduler(Schedulers.elastic())
+            .evictionPredicate((channel, metadata) -> {
+                if (!channel.isOpen()) {
+                    return true;
+                }
+                if (metadata.idleTime() > Duration.ofSeconds(30).toMillis()) {
+                    return true;
+                }
+                return false;
+            })
+            .destroyHandler(channel -> Mono.fromRunnable(Throwing.runnable(channel::close)))
+            .buildPool();
+    }
+
+    private Mono<? extends Channel> openChannel(Connection connection) {
+        return Mono.fromCallable(connection::openChannel)
+            .map(maybeChannel ->
+                maybeChannel.orElseThrow(() -> new RuntimeException("RabbitMQ reached to maximum opened channels, cannot get more channels")))
+            .map(SelectOnceChannel::new)
+            .retryWhen(configuration.backoffSpec().scheduler(Schedulers.elastic()))
+            .doOnError(throwable -> LOGGER.error("error when creating new channel", throwable));
     }
 
     public void start() {
@@ -739,46 +709,26 @@ public class ReactorRabbitMQChannelPool implements ChannelPool, Startable {
         return borrow();
     }
 
-    private Mono<Channel> borrow() {
-        return tryBorrowFromPool()
-            .doOnError(throwable -> LOGGER.warn("Cannot borrow channel", throwable))
-            .retryWhen(configuration.backoffSpec().scheduler(Schedulers.elastic()))
-            .onErrorMap(this::propagateException)
-            .subscribeOn(Schedulers.elastic())
-            .doOnNext(borrowedChannels::add);
-    }
-
-    private Mono<Channel> tryBorrowFromPool() {
-        return Mono.fromCallable(this::borrowFromPool);
-    }
-
-    private Throwable propagateException(Throwable throwable) {
-        if (throwable instanceof IllegalStateException
-            && throwable.getMessage().contains("Retries exhausted")) {
-            return throwable.getCause();
-        }
-
-        return throwable;
-    }
-
-    private Channel borrowFromPool() throws Exception {
-        Channel channel = pool.borrowObject(MAXIMUM_BORROW_TIMEOUT_IN_MS);
-        if (!channel.isOpen()) {
-            invalidateObject(channel);
-            throw new ChannelClosedException("borrowed channel is already closed");
-        }
-        return channel;
+    private Mono<? extends Channel> borrow() {
+        return newPool.acquire()
+            .timeout(configuration.maxBorrowDelay)
+            .doOnNext(ref -> refs.put(ref.poolable().getChannelNumber(), ref))
+            .map(PooledRef::poolable)
+            .onErrorMap(TimeoutException.class, e -> new NoSuchElementException("Timeout waiting for idle object"));
     }
 
     @Override
     public BiConsumer<SignalType, Channel> getChannelCloseHandler() {
         return (signalType, channel) -> {
-            borrowedChannels.remove(channel);
+            PooledRef<? extends Channel> pooledRef = refs.remove(channel.getChannelNumber());
+
             if (!channel.isOpen() || !executeWithoutError(signalType)) {
-                invalidateObject(channel);
+                pooledRef.invalidate()
+                    .block();
                 return;
             }
-            pool.returnObject(channel);
+            pooledRef.release()
+                .block();
         };
     }
 
@@ -836,24 +786,16 @@ public class ReactorRabbitMQChannelPool implements ChannelPool, Startable {
             .then();
     }
 
-    private void invalidateObject(Channel channel) {
-        try {
-            pool.invalidateObject(channel);
-            if (channel.isOpen()) {
-                channel.close();
-            }
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        }
-    }
-
     @PreDestroy
     @Override
     public void close() {
         sender.close();
-        borrowedChannels.forEach(channel -> getChannelCloseHandler().accept(SignalType.ON_NEXT, channel));
-        borrowedChannels.clear();
-        pool.close();
+        ImmutableList.copyOf(refs.values())
+            .stream()
+            .map(PooledRef::poolable)
+            .forEach(channel -> getChannelCloseHandler().accept(SignalType.ON_NEXT, channel));
+        refs.clear();
+        newPool.dispose();
     }
 
     public Mono<Boolean> tryChannel() {
@@ -861,8 +803,8 @@ public class ReactorRabbitMQChannelPool implements ChannelPool, Startable {
             channel -> Mono.just(channel.isOpen()),
             channel -> {
                 if (channel != null) {
-                    borrowedChannels.remove(channel);
-                    pool.returnObject(channel);
+                    PooledRef<? extends Channel> pooledRef = refs.remove(channel.getChannelNumber());
+                    return pooledRef.release();
                 }
                 return Mono.empty();
             })
diff --git a/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/ChannelPoolContract.java b/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/ChannelPoolContract.java
index 4fde3af687..195edb9892 100644
--- a/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/ChannelPoolContract.java
+++ b/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/ChannelPoolContract.java
@@ -31,6 +31,7 @@ import com.rabbitmq.client.Channel;
 
 import reactor.core.publisher.Mono;
 import reactor.core.publisher.SignalType;
+import reactor.core.scheduler.Schedulers;
 import reactor.rabbitmq.ChannelPool;
 
 interface ChannelPoolContract {
@@ -64,17 +65,16 @@ interface ChannelPoolContract {
     @Test
     default void channelPoolShouldWaitTillTheNextReleaseWhenAllChannelsAreTaken() {
         ChannelPool channelPool = getChannelPool(2);
-        channelPool.getChannelMono();
-        borrowChannel(channelPool);
+        Channel channel1 = borrowChannel(channelPool);
         Channel channel2 = borrowChannel(channelPool);
 
-        Mono.delay(Duration.ofSeconds(2))
-            .doOnSuccess(any -> returnToThePool(channelPool, channel2))
+        Mono.delay(Duration.ofSeconds(1))
+            .then(Mono.fromRunnable(() -> returnToThePool(channelPool, channel1)).subscribeOn(Schedulers.elastic()))
             .subscribe();
 
         Channel channelAfterReturned = borrowChannel(channelPool);
         assertThat(channelAfterReturned.getChannelNumber())
-            .isEqualTo(channel2.getChannelNumber());
+            .isEqualTo(channel1.getChannelNumber());
     }
 
     @Test
diff --git a/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/ReactorRabbitMQChannelPoolTest.java b/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/ReactorRabbitMQChannelPoolTest.java
index 0f259c340a..4744115517 100644
--- a/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/ReactorRabbitMQChannelPoolTest.java
+++ b/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/ReactorRabbitMQChannelPoolTest.java
@@ -71,7 +71,7 @@ class ReactorRabbitMQChannelPoolTest implements ChannelPoolContract {
             rabbitMQExtension.getConnectionPool().getResilientConnection(),
             ReactorRabbitMQChannelPool.Configuration.builder()
                 .retries(2)
-                .minBorrowDelay(Duration.ofMillis(5))
+                .minBorrowDelay(Duration.ofSeconds(2))
                 .maxChannel(poolSize));
         reactorRabbitMQChannelPool.start();
         return reactorRabbitMQChannelPool;
diff --git a/event-bus/distributed/pom.xml b/event-bus/distributed/pom.xml
index ab2af3aa3e..74fde0bdef 100644
--- a/event-bus/distributed/pom.xml
+++ b/event-bus/distributed/pom.xml
@@ -86,10 +86,6 @@
             <groupId>io.projectreactor.rabbitmq</groupId>
             <artifactId>reactor-rabbitmq</artifactId>
         </dependency>
-        <dependency>
-            <groupId>org.apache.commons</groupId>
-            <artifactId>commons-pool2</artifactId>
-        </dependency>
         <dependency>
             <groupId>org.awaitility</groupId>
             <artifactId>awaitility</artifactId>
diff --git a/event-bus/distributed/src/test/java/org/apache/james/events/NetworkErrorTest.java b/event-bus/distributed/src/test/java/org/apache/james/events/NetworkErrorTest.java
index 795fc12e60..58d4ddaf04 100644
--- a/event-bus/distributed/src/test/java/org/apache/james/events/NetworkErrorTest.java
+++ b/event-bus/distributed/src/test/java/org/apache/james/events/NetworkErrorTest.java
@@ -27,6 +27,8 @@ import static org.apache.james.events.EventBusTestFixture.newListener;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.mockito.Mockito.verify;
 
+import java.util.NoSuchElementException;
+
 import org.apache.james.backends.rabbitmq.RabbitMQExtension;
 import org.apache.james.backends.rabbitmq.RabbitMQFixture;
 import org.apache.james.events.EventBusTestFixture.TestEventSerializer;
@@ -72,8 +74,8 @@ class NetworkErrorTest {
         rabbitMQExtension.getRabbitMQ().pause();
 
         assertThatThrownBy(() -> eventBus.dispatch(EVENT, NO_KEYS).block())
-            .isInstanceOf(IllegalStateException.class)
-            .hasMessageContaining("Retries exhausted");
+            .isInstanceOf(NoSuchElementException.class)
+            .hasMessageContaining("Timeout waiting for idle object");
 
         rabbitMQExtension.getRabbitMQ().unpause();
 
diff --git a/pom.xml b/pom.xml
index f4e9085fde..30e177d2ef 100644
--- a/pom.xml
+++ b/pom.xml
@@ -2500,11 +2500,6 @@
                 <artifactId>commons-lang3</artifactId>
                 <version>3.12.0</version>
             </dependency>
-            <dependency>
-                <groupId>org.apache.commons</groupId>
-                <artifactId>commons-pool2</artifactId>
-                <version>2.11.1</version>
-            </dependency>
             <dependency>
                 <groupId>org.apache.commons</groupId>
                 <artifactId>commons-text</artifactId>
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 5b91a0d935..540d4b2173 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
@@ -38,9 +38,9 @@ Optional integer, defaults to 100
 | 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.max.delay.ms
+| Configure timeout duration (in ms) to obtain a rabbitmq channel. Defaults to 30 seconds.
+Optional integer, defaults to 30 seconds.
 
 | channel.pool.size
 | Configure the size of the channel pool.
diff --git a/server/apps/distributed-app/sample-configuration/rabbitmq.properties b/server/apps/distributed-app/sample-configuration/rabbitmq.properties
index b412d1d354..b63acd9d85 100644
--- a/server/apps/distributed-app/sample-configuration/rabbitmq.properties
+++ b/server/apps/distributed-app/sample-configuration/rabbitmq.properties
@@ -26,9 +26,9 @@ management.password=guest
 # 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 timeout duration (in ms) to obtain a rabbitmq channel. Defaults to 30 seconds.
+# Optional integer, defaults to 30 seconds.
+#channel.pool.max.delay.ms=30000
 # Configure the size of the channel pool.
 # Optional integer, defaults to 3
 #channel.pool.size=3
diff --git a/server/apps/distributed-pop3-app/sample-configuration/rabbitmq.properties b/server/apps/distributed-pop3-app/sample-configuration/rabbitmq.properties
index 4b7a2caab8..d587cb647e 100644
--- a/server/apps/distributed-pop3-app/sample-configuration/rabbitmq.properties
+++ b/server/apps/distributed-pop3-app/sample-configuration/rabbitmq.properties
@@ -26,9 +26,9 @@ management.password=guest
 # 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 timeout duration (in ms) to obtain a rabbitmq channel. Defaults to 30 seconds.
+# Optional integer, defaults to 30 seconds.
+#channel.pool.max.delay.ms=30000
 # Configure the size of the channel pool.
 # Optional integer, defaults to 3
 #channel.pool.size=3
diff --git a/src/site/xdoc/server/config-rabbitmq.xml b/src/site/xdoc/server/config-rabbitmq.xml
index 4aa279ae86..17d5781a88 100644
--- a/src/site/xdoc/server/config-rabbitmq.xml
+++ b/src/site/xdoc/server/config-rabbitmq.xml
@@ -70,9 +70,9 @@
           <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.max.delay.ms</strong></dt>
+          <dd>Configure timeout duration (in ms) to obtain a rabbitmq channel. Defaults to 30 seconds.
+              Optional integer, defaults to 30 seconds.</dd>
 
           <dt><strong>channel.pool.size</strong></dt>
           <dd>Configure the size of the channel pool.


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


[james-project] 02/06: JAMES-3747 Metrics for RabbitMQ channelPool

Posted by bt...@apache.org.
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 6ad24d4da098a94d739d376218b6c22b05fe5349
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed Apr 13 22:28:17 2022 +0700

    JAMES-3747 Metrics for RabbitMQ channelPool
    
     -> Time to acquire a channel
     -> Time to publish something (includes acquire)
     -> Time to bind/unbind exchanges (includes acquire)
---
 backends-common/rabbitmq/pom.xml                   |  9 ++++++++
 .../rabbitmq/ReactorRabbitMQChannelPool.java       | 26 +++++++++++++---------
 .../james/backends/rabbitmq/RabbitMQExtension.java |  4 +++-
 .../rabbitmq/ReactorRabbitMQChannelPoolTest.java   |  4 +++-
 .../james/events/KeyRegistrationHandler.java       |  9 +++++---
 .../org/apache/james/events/RabbitMQEventBus.java  | 10 +++++----
 mailet/amqp/pom.xml                                |  4 ++++
 .../transport/mailets/AmqpForwardAttribute.java    | 12 +++++++++-
 .../mailets/AmqpForwardAttributeTest.java          |  3 ++-
 .../rabbitmq/host/RabbitMQEventBusHostSystem.java  |  3 ++-
 .../modules/queue/rabbitmq/RabbitMQModule.java     |  8 +++++--
 server/task/task-distributed/pom.xml               |  5 +++++
 12 files changed, 73 insertions(+), 24 deletions(-)

diff --git a/backends-common/rabbitmq/pom.xml b/backends-common/rabbitmq/pom.xml
index d65cb6f8a1..9d2053ab74 100644
--- a/backends-common/rabbitmq/pom.xml
+++ b/backends-common/rabbitmq/pom.xml
@@ -48,6 +48,15 @@
             <groupId>${james.groupId}</groupId>
             <artifactId>james-server-util</artifactId>
         </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
+            <artifactId>metrics-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
+            <artifactId>metrics-tests</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>${james.groupId}</groupId>
             <artifactId>testing-base</artifactId>
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 6c33dc77f1..f5e14e7c42 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
@@ -33,6 +33,7 @@ import java.util.function.BiConsumer;
 import javax.annotation.PreDestroy;
 
 import org.apache.james.lifecycle.api.Startable;
+import org.apache.james.metrics.api.MetricFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -660,11 +661,13 @@ public class ReactorRabbitMQChannelPool implements ChannelPool, Startable {
     private final Configuration configuration;
 
     private final InstrumentedPool<? extends Channel> newPool;
+    private final MetricFactory metricFatcory;
     private Sender sender;
 
-    public ReactorRabbitMQChannelPool(Mono<Connection> connectionMono, Configuration configuration) {
+    public ReactorRabbitMQChannelPool(Mono<Connection> connectionMono, Configuration configuration, MetricFactory metricFatcory) {
         this.connectionMono = connectionMono;
         this.configuration = configuration;
+        this.metricFatcory = metricFatcory;
 
         newPool = PoolBuilder.from(connectionMono
             .flatMap(this::openChannel))
@@ -706,7 +709,7 @@ public class ReactorRabbitMQChannelPool implements ChannelPool, Startable {
 
     @Override
     public Mono<? extends Channel> getChannelMono() {
-        return borrow();
+        return Mono.from(metricFatcory.decoratePublisherWithTimerMetric("rabbit-acquire", borrow()));
     }
 
     private Mono<? extends Channel> borrow() {
@@ -720,15 +723,18 @@ public class ReactorRabbitMQChannelPool implements ChannelPool, Startable {
     @Override
     public BiConsumer<SignalType, Channel> getChannelCloseHandler() {
         return (signalType, channel) -> {
-            PooledRef<? extends Channel> pooledRef = refs.remove(channel.getChannelNumber());
+            metricFatcory.runPublishingTimerMetric("rabbit-release",
+                () -> {
+                    PooledRef<? extends Channel> pooledRef = refs.remove(channel.getChannelNumber());
 
-            if (!channel.isOpen() || !executeWithoutError(signalType)) {
-                pooledRef.invalidate()
-                    .block();
-                return;
-            }
-            pooledRef.release()
-                .block();
+                    if (!channel.isOpen() || !executeWithoutError(signalType)) {
+                        pooledRef.invalidate()
+                            .block();
+                        return;
+                    }
+                    pooledRef.release()
+                        .block();
+                });
         };
     }
 
diff --git a/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/RabbitMQExtension.java b/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/RabbitMQExtension.java
index 85fde71979..54b163b820 100644
--- a/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/RabbitMQExtension.java
+++ b/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/RabbitMQExtension.java
@@ -24,6 +24,7 @@ import java.net.URISyntaxException;
 import java.time.Duration;
 import java.util.function.Consumer;
 
+import org.apache.james.metrics.tests.RecordingMetricFactory;
 import org.junit.jupiter.api.extension.AfterAllCallback;
 import org.junit.jupiter.api.extension.AfterEachCallback;
 import org.junit.jupiter.api.extension.BeforeAllCallback;
@@ -147,7 +148,8 @@ public class RabbitMQExtension implements BeforeAllCallback, BeforeEachCallback,
             ReactorRabbitMQChannelPool.Configuration.builder()
                 .retries(2)
                 .minBorrowDelay(Duration.ofMillis(5))
-                .maxChannel(10));
+                .maxChannel(10),
+            new RecordingMetricFactory());
         channelPool.start();
     }
 
diff --git a/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/ReactorRabbitMQChannelPoolTest.java b/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/ReactorRabbitMQChannelPoolTest.java
index 4744115517..b97a361ba4 100644
--- a/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/ReactorRabbitMQChannelPoolTest.java
+++ b/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/ReactorRabbitMQChannelPoolTest.java
@@ -28,6 +28,7 @@ import java.util.List;
 import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.ExecutionException;
 
+import org.apache.james.metrics.tests.RecordingMetricFactory;
 import org.apache.james.util.concurrency.ConcurrentTestRunner;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
@@ -72,7 +73,8 @@ class ReactorRabbitMQChannelPoolTest implements ChannelPoolContract {
             ReactorRabbitMQChannelPool.Configuration.builder()
                 .retries(2)
                 .minBorrowDelay(Duration.ofSeconds(2))
-                .maxChannel(poolSize));
+                .maxChannel(poolSize),
+            new RecordingMetricFactory());
         reactorRabbitMQChannelPool.start();
         return reactorRabbitMQChannelPool;
     }
diff --git a/event-bus/distributed/src/main/java/org/apache/james/events/KeyRegistrationHandler.java b/event-bus/distributed/src/main/java/org/apache/james/events/KeyRegistrationHandler.java
index ca2d19b7e5..593cb9d9c1 100644
--- a/event-bus/distributed/src/main/java/org/apache/james/events/KeyRegistrationHandler.java
+++ b/event-bus/distributed/src/main/java/org/apache/james/events/KeyRegistrationHandler.java
@@ -31,6 +31,7 @@ import java.util.function.Predicate;
 
 import org.apache.james.backends.rabbitmq.RabbitMQConfiguration;
 import org.apache.james.backends.rabbitmq.ReceiverProvider;
+import org.apache.james.metrics.api.MetricFactory;
 import org.apache.james.util.MDCBuilder;
 import org.apache.james.util.MDCStructuredLogger;
 import org.apache.james.util.StructuredLogger;
@@ -70,12 +71,13 @@ class KeyRegistrationHandler {
     private final RabbitMQConfiguration configuration;
     private final ReceiverProvider receiverProvider;
     private Optional<Disposable> receiverSubscriber;
+    private final MetricFactory metricFactory;
     private Disposable newSubscription;
 
     KeyRegistrationHandler(NamingStrategy namingStrategy, EventBusId eventBusId, EventSerializer eventSerializer,
                            Sender sender, ReceiverProvider receiverProvider,
                            RoutingKeyConverter routingKeyConverter, LocalListenerRegistry localListenerRegistry,
-                           ListenerExecutor listenerExecutor, RetryBackoffConfiguration retryBackoff, RabbitMQConfiguration configuration) {
+                           ListenerExecutor listenerExecutor, RetryBackoffConfiguration retryBackoff, RabbitMQConfiguration configuration, MetricFactory metricFactory) {
         this.eventBusId = eventBusId;
         this.eventSerializer = eventSerializer;
         this.sender = sender;
@@ -85,6 +87,7 @@ class KeyRegistrationHandler {
         this.listenerExecutor = listenerExecutor;
         this.retryBackoff = retryBackoff;
         this.configuration = configuration;
+        this.metricFactory = metricFactory;
         this.registrationQueue = namingStrategy.queueName(eventBusId);
         this.registrationBinder = new RegistrationBinder(namingStrategy, sender, registrationQueue);
         this.receiverSubscriber = Optional.empty();
@@ -143,9 +146,9 @@ class KeyRegistrationHandler {
         return registerIfNeeded(key, registration)
             .thenReturn(new KeyRegistration(() -> {
                 if (registration.unregister().lastListenerRemoved()) {
-                    return registrationBinder.unbind(key)
+                    return Mono.from(metricFactory.decoratePublisherWithTimerMetric("rabbit-unregister", registrationBinder.unbind(key)
                         .timeout(TOPOLOGY_CHANGES_TIMEOUT)
-                        .retryWhen(Retry.backoff(retryBackoff.getMaxRetries(), retryBackoff.getFirstBackoff()).jitter(retryBackoff.getJitterFactor()).scheduler(Schedulers.elastic()));
+                        .retryWhen(Retry.backoff(retryBackoff.getMaxRetries(), retryBackoff.getFirstBackoff()).jitter(retryBackoff.getJitterFactor()).scheduler(Schedulers.elastic()))));
                 }
                 return Mono.empty();
             }));
diff --git a/event-bus/distributed/src/main/java/org/apache/james/events/RabbitMQEventBus.java b/event-bus/distributed/src/main/java/org/apache/james/events/RabbitMQEventBus.java
index 27440afbb7..b8c85c788f 100644
--- a/event-bus/distributed/src/main/java/org/apache/james/events/RabbitMQEventBus.java
+++ b/event-bus/distributed/src/main/java/org/apache/james/events/RabbitMQEventBus.java
@@ -54,6 +54,7 @@ public class RabbitMQEventBus implements EventBus, Startable {
     private final ReceiverProvider receiverProvider;
     private final ReactorRabbitMQChannelPool channelPool;
     private final RabbitMQConfiguration configuration;
+    private final MetricFactory metricFactory;
 
     private volatile boolean isRunning;
     private volatile boolean isStopping;
@@ -78,6 +79,7 @@ public class RabbitMQEventBus implements EventBus, Startable {
         this.retryBackoff = retryBackoff;
         this.eventDeadLetters = eventDeadLetters;
         this.configuration = configuration;
+        this.metricFactory = metricFactory;
         this.isRunning = false;
         this.isStopping = false;
     }
@@ -86,7 +88,7 @@ public class RabbitMQEventBus implements EventBus, Startable {
         if (!isRunning && !isStopping) {
 
             LocalListenerRegistry localListenerRegistry = new LocalListenerRegistry();
-            keyRegistrationHandler = new KeyRegistrationHandler(namingStrategy, eventBusId, eventSerializer, sender, receiverProvider, routingKeyConverter, localListenerRegistry, listenerExecutor, retryBackoff, configuration);
+            keyRegistrationHandler = new KeyRegistrationHandler(namingStrategy, eventBusId, eventSerializer, sender, receiverProvider, routingKeyConverter, localListenerRegistry, listenerExecutor, retryBackoff, configuration, metricFactory);
             groupRegistrationHandler = new GroupRegistrationHandler(namingStrategy, eventSerializer, channelPool, sender, receiverProvider, retryBackoff, eventDeadLetters, listenerExecutor, eventBusId, configuration);
             eventDispatcher = new EventDispatcher(namingStrategy, eventBusId, eventSerializer, sender, localListenerRegistry, listenerExecutor, eventDeadLetters);
 
@@ -106,7 +108,7 @@ public class RabbitMQEventBus implements EventBus, Startable {
         if (!isRunning && !isStopping) {
 
             LocalListenerRegistry localListenerRegistry = new LocalListenerRegistry();
-            keyRegistrationHandler = new KeyRegistrationHandler(namingStrategy, eventBusId, eventSerializer, sender, receiverProvider, routingKeyConverter, localListenerRegistry, listenerExecutor, retryBackoff, configuration);
+            keyRegistrationHandler = new KeyRegistrationHandler(namingStrategy, eventBusId, eventSerializer, sender, receiverProvider, routingKeyConverter, localListenerRegistry, listenerExecutor, retryBackoff, configuration, metricFactory);
             groupRegistrationHandler = new GroupRegistrationHandler(namingStrategy, eventSerializer, channelPool, sender, receiverProvider, retryBackoff, eventDeadLetters, listenerExecutor, eventBusId, configuration);
             eventDispatcher = new EventDispatcher(namingStrategy, eventBusId, eventSerializer, sender, localListenerRegistry, listenerExecutor, eventDeadLetters);
 
@@ -135,7 +137,7 @@ public class RabbitMQEventBus implements EventBus, Startable {
     @Override
     public Mono<Registration> register(EventListener.ReactiveEventListener listener, RegistrationKey key) {
         Preconditions.checkState(isRunning, NOT_RUNNING_ERROR_MESSAGE);
-        return keyRegistrationHandler.register(listener, key);
+        return Mono.from(metricFactory.decoratePublisherWithTimerMetric("rabbit-register", keyRegistrationHandler.register(listener, key)));
     }
 
     @Override
@@ -148,7 +150,7 @@ public class RabbitMQEventBus implements EventBus, Startable {
     public Mono<Void> dispatch(Event event, Set<RegistrationKey> key) {
         Preconditions.checkState(isRunning, NOT_RUNNING_ERROR_MESSAGE);
         if (!event.isNoop()) {
-            return eventDispatcher.dispatch(event, key);
+            return Mono.from(metricFactory.decoratePublisherWithTimerMetric("rabbit-dispatch", eventDispatcher.dispatch(event, key)));
         }
         return Mono.empty();
     }
diff --git a/mailet/amqp/pom.xml b/mailet/amqp/pom.xml
index 2e2e5db2e9..bb7698863a 100644
--- a/mailet/amqp/pom.xml
+++ b/mailet/amqp/pom.xml
@@ -58,6 +58,10 @@
             <groupId>${james.groupId}</groupId>
             <artifactId>james-server-util</artifactId>
         </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
+            <artifactId>metrics-tests</artifactId>
+        </dependency>
         <dependency>
             <groupId>${james.groupId}</groupId>
             <artifactId>testing-base</artifactId>
diff --git a/mailet/amqp/src/main/java/org/apache/james/transport/mailets/AmqpForwardAttribute.java b/mailet/amqp/src/main/java/org/apache/james/transport/mailets/AmqpForwardAttribute.java
index 8b297629b3..2cc268eef4 100644
--- a/mailet/amqp/src/main/java/org/apache/james/transport/mailets/AmqpForwardAttribute.java
+++ b/mailet/amqp/src/main/java/org/apache/james/transport/mailets/AmqpForwardAttribute.java
@@ -29,11 +29,13 @@ import java.util.Optional;
 import java.util.stream.Stream;
 
 import javax.annotation.PreDestroy;
+import javax.inject.Inject;
 
 import org.apache.james.backends.rabbitmq.RabbitMQConfiguration;
 import org.apache.james.backends.rabbitmq.RabbitMQConnectionFactory;
 import org.apache.james.backends.rabbitmq.ReactorRabbitMQChannelPool;
 import org.apache.james.backends.rabbitmq.SimpleConnectionPool;
+import org.apache.james.metrics.api.MetricFactory;
 import org.apache.mailet.Attribute;
 import org.apache.mailet.AttributeName;
 import org.apache.mailet.AttributeValue;
@@ -97,6 +99,8 @@ public class AmqpForwardAttribute extends GenericMailet {
 
     public static final String ROUTING_KEY_DEFAULT_VALUE = "";
 
+    private final MetricFactory metricFactory;
+
     private String exchange;
     private AttributeName attribute;
     private ConnectionFactory connectionFactory;
@@ -105,6 +109,11 @@ public class AmqpForwardAttribute extends GenericMailet {
     private ReactorRabbitMQChannelPool reactorRabbitMQChannelPool;
     private Sender sender;
 
+    @Inject
+    public AmqpForwardAttribute(MetricFactory metricFactory) {
+        this.metricFactory = metricFactory;
+    }
+
     @Override
     public void init() throws MailetException {
         MailetConfig mailetConfig = getMailetConfig();
@@ -128,7 +137,8 @@ public class AmqpForwardAttribute extends GenericMailet {
                 .retries(2)
                 .initialDelay(Duration.ofMillis(5)));
             reactorRabbitMQChannelPool = new ReactorRabbitMQChannelPool(connectionPool.getResilientConnection(),
-                ReactorRabbitMQChannelPool.Configuration.DEFAULT);
+                ReactorRabbitMQChannelPool.Configuration.DEFAULT,
+                metricFactory);
             reactorRabbitMQChannelPool.start();
             sender = reactorRabbitMQChannelPool.getSender();
             sender.declareExchange(ExchangeSpecification.exchange(exchange));
diff --git a/mailet/amqp/src/test/java/org/apache/james/transport/mailets/AmqpForwardAttributeTest.java b/mailet/amqp/src/test/java/org/apache/james/transport/mailets/AmqpForwardAttributeTest.java
index 28feea8ca3..de6c298f97 100644
--- a/mailet/amqp/src/test/java/org/apache/james/transport/mailets/AmqpForwardAttributeTest.java
+++ b/mailet/amqp/src/test/java/org/apache/james/transport/mailets/AmqpForwardAttributeTest.java
@@ -32,6 +32,7 @@ import java.util.Optional;
 import javax.mail.MessagingException;
 
 import org.apache.james.backends.rabbitmq.RabbitMQConfiguration.ManagementCredentials;
+import org.apache.james.metrics.tests.RecordingMetricFactory;
 import org.apache.mailet.Attribute;
 import org.apache.mailet.AttributeName;
 import org.apache.mailet.AttributeValue;
@@ -63,7 +64,7 @@ class AmqpForwardAttributeTest {
 
     @BeforeEach
     public void setUp() throws Exception {
-        mailet = new AmqpForwardAttribute();
+        mailet = new AmqpForwardAttribute(new RecordingMetricFactory());
         Logger logger = mock(Logger.class);
         mailetContext = FakeMailContext.builder()
                 .logger(logger)
diff --git a/mpt/impl/imap-mailbox/rabbitmq/src/test/java/org/apache/james/mpt/imapmailbox/rabbitmq/host/RabbitMQEventBusHostSystem.java b/mpt/impl/imap-mailbox/rabbitmq/src/test/java/org/apache/james/mpt/imapmailbox/rabbitmq/host/RabbitMQEventBusHostSystem.java
index 78c8748949..057cc3a96b 100644
--- a/mpt/impl/imap-mailbox/rabbitmq/src/test/java/org/apache/james/mpt/imapmailbox/rabbitmq/host/RabbitMQEventBusHostSystem.java
+++ b/mpt/impl/imap-mailbox/rabbitmq/src/test/java/org/apache/james/mpt/imapmailbox/rabbitmq/host/RabbitMQEventBusHostSystem.java
@@ -80,7 +80,8 @@ public class RabbitMQEventBusHostSystem extends JamesImapHostSystem {
                 .retries(2)
                 .initialDelay(Duration.ofMillis(5)));
         reactorRabbitMQChannelPool = new ReactorRabbitMQChannelPool(connectionPool.getResilientConnection(),
-            ReactorRabbitMQChannelPool.Configuration.DEFAULT);
+            ReactorRabbitMQChannelPool.Configuration.DEFAULT,
+            new DefaultMetricFactory());
         reactorRabbitMQChannelPool.start();
         eventBus = createEventBus();
         eventBus.start();
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 e8b2866426..5c4545da81 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
@@ -38,6 +38,7 @@ import org.apache.james.eventsourcing.Event;
 import org.apache.james.eventsourcing.eventstore.cassandra.dto.EventDTO;
 import org.apache.james.eventsourcing.eventstore.cassandra.dto.EventDTOModule;
 import org.apache.james.lifecycle.api.StartUpCheck;
+import org.apache.james.metrics.api.MetricFactory;
 import org.apache.james.queue.api.MailQueue;
 import org.apache.james.queue.api.MailQueueFactory;
 import org.apache.james.queue.api.ManageableMailQueue;
@@ -179,10 +180,13 @@ public class RabbitMQModule extends AbstractModule {
 
     @Provides
     @Singleton
-    ReactorRabbitMQChannelPool provideReactorRabbitMQChannelPool(SimpleConnectionPool simpleConnectionPool, ReactorRabbitMQChannelPool.Configuration configuration) {
+    ReactorRabbitMQChannelPool provideReactorRabbitMQChannelPool(SimpleConnectionPool simpleConnectionPool,
+                                                                 ReactorRabbitMQChannelPool.Configuration configuration,
+                                                                 MetricFactory metricFactory) {
         ReactorRabbitMQChannelPool channelPool = new ReactorRabbitMQChannelPool(
             simpleConnectionPool.getResilientConnection(),
-            configuration);
+            configuration,
+            metricFactory);
         channelPool.start();
         return channelPool;
     }
diff --git a/server/task/task-distributed/pom.xml b/server/task/task-distributed/pom.xml
index 2be26715a8..8967c34ac8 100644
--- a/server/task/task-distributed/pom.xml
+++ b/server/task/task-distributed/pom.xml
@@ -108,6 +108,11 @@
             <artifactId>james-server-testing</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
+            <artifactId>metrics-tests</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>${james.groupId}</groupId>
             <artifactId>testing-base</artifactId>


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


[james-project] 05/06: JAMES-3747 Fix badly renamed minDelay methods

Posted by bt...@apache.org.
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 3b25be1f651412d6d68bb201d726c85db101e676
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Apr 15 22:33:35 2022 +0700

    JAMES-3747 Fix badly renamed minDelay methods
    
    Also increase wait ties as this no longer is the shorter acquire backoff retry but the full acquiring duration.
---
 .../rabbitmq/ReactorRabbitMQChannelPool.java       | 36 ++++++++++------------
 .../james/backends/rabbitmq/RabbitMQExtension.java |  2 +-
 .../rabbitmq/ReactorRabbitMQChannelPoolTest.java   |  2 +-
 .../events/EventBusConcurrentTestContract.java     | 12 ++++----
 .../apache/james/events/RabbitMQEventBusTest.java  | 19 ++++++------
 .../apache/james/modules/DockerRabbitMQRule.java   |  2 +-
 6 files changed, 36 insertions(+), 37 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 f5e14e7c42..47bfd5b290 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
@@ -599,12 +599,12 @@ public class ReactorRabbitMQChannelPool implements ChannelPool, Startable {
     public static class Configuration {
         @FunctionalInterface
         public interface RequiresRetries {
-            RequiredMinBorrowDelay retries(int retries);
+            RequiredMaxBorrowDelay retries(int retries);
         }
 
         @FunctionalInterface
-        public interface RequiredMinBorrowDelay {
-            RequiredMaxChannel minBorrowDelay(Duration minBorrowDelay);
+        public interface RequiredMaxBorrowDelay {
+            RequiredMaxChannel maxBorrowDelay(Duration maxBorrowDelay);
         }
 
         @FunctionalInterface
@@ -614,11 +614,11 @@ public class ReactorRabbitMQChannelPool implements ChannelPool, Startable {
 
         public static final Configuration DEFAULT = builder()
             .retries(MAX_BORROW_RETRIES)
-            .minBorrowDelay(MAX_BORROW_DELAY)
+            .maxBorrowDelay(MAX_BORROW_DELAY)
             .maxChannel(MAX_CHANNELS_NUMBER);
 
         public static RequiresRetries builder() {
-            return retries -> minBorrowDelay -> maxChannel -> new Configuration(minBorrowDelay, retries, maxChannel);
+            return retries -> maxBorrowDelay -> maxChannel -> new Configuration(maxBorrowDelay, retries, maxChannel);
         }
 
         public static Configuration from(org.apache.commons.configuration2.Configuration configuration) {
@@ -628,7 +628,7 @@ public class ReactorRabbitMQChannelPool implements ChannelPool, Startable {
 
             return builder()
                 .retries(configuration.getInt("channel.pool.retries", MAX_BORROW_RETRIES))
-                .minBorrowDelay(maxBorrowDelay)
+                .maxBorrowDelay(maxBorrowDelay)
                 .maxChannel(configuration.getInt("channel.pool.size", MAX_CHANNELS_NUMBER));
         }
 
@@ -672,7 +672,7 @@ public class ReactorRabbitMQChannelPool implements ChannelPool, Startable {
         newPool = PoolBuilder.from(connectionMono
             .flatMap(this::openChannel))
             .sizeBetween(1, configuration.maxChannel)
-            .acquisitionScheduler(Schedulers.elastic())
+            .maxPendingAcquireUnbounded()
             .evictionPredicate((channel, metadata) -> {
                 if (!channel.isOpen()) {
                     return true;
@@ -722,20 +722,18 @@ public class ReactorRabbitMQChannelPool implements ChannelPool, Startable {
 
     @Override
     public BiConsumer<SignalType, Channel> getChannelCloseHandler() {
-        return (signalType, channel) -> {
-            metricFatcory.runPublishingTimerMetric("rabbit-release",
-                () -> {
-                    PooledRef<? extends Channel> pooledRef = refs.remove(channel.getChannelNumber());
+        return (signalType, channel) -> metricFatcory.runPublishingTimerMetric("rabbit-release",
+            () -> {
+                PooledRef<? extends Channel> pooledRef = refs.remove(channel.getChannelNumber());
 
-                    if (!channel.isOpen() || !executeWithoutError(signalType)) {
-                        pooledRef.invalidate()
-                            .block();
-                        return;
-                    }
-                    pooledRef.release()
+                if (!channel.isOpen() || !executeWithoutError(signalType)) {
+                    pooledRef.invalidate()
                         .block();
-                });
-        };
+                    return;
+                }
+                pooledRef.release()
+                    .block();
+            });
     }
 
     private boolean executeWithoutError(SignalType signalType) {
diff --git a/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/RabbitMQExtension.java b/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/RabbitMQExtension.java
index 54b163b820..c69e550334 100644
--- a/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/RabbitMQExtension.java
+++ b/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/RabbitMQExtension.java
@@ -147,7 +147,7 @@ public class RabbitMQExtension implements BeforeAllCallback, BeforeEachCallback,
         channelPool = new ReactorRabbitMQChannelPool(connectionPool.getResilientConnection(),
             ReactorRabbitMQChannelPool.Configuration.builder()
                 .retries(2)
-                .minBorrowDelay(Duration.ofMillis(5))
+                .maxBorrowDelay(Duration.ofSeconds(10))
                 .maxChannel(10),
             new RecordingMetricFactory());
         channelPool.start();
diff --git a/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/ReactorRabbitMQChannelPoolTest.java b/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/ReactorRabbitMQChannelPoolTest.java
index b97a361ba4..271283481a 100644
--- a/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/ReactorRabbitMQChannelPoolTest.java
+++ b/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/ReactorRabbitMQChannelPoolTest.java
@@ -72,7 +72,7 @@ class ReactorRabbitMQChannelPoolTest implements ChannelPoolContract {
             rabbitMQExtension.getConnectionPool().getResilientConnection(),
             ReactorRabbitMQChannelPool.Configuration.builder()
                 .retries(2)
-                .minBorrowDelay(Duration.ofSeconds(2))
+                .maxBorrowDelay(Duration.ofSeconds(2))
                 .maxChannel(poolSize),
             new RecordingMetricFactory());
         reactorRabbitMQChannelPool.start();
diff --git a/event-bus/api/src/test/java/org/apache/james/events/EventBusConcurrentTestContract.java b/event-bus/api/src/test/java/org/apache/james/events/EventBusConcurrentTestContract.java
index c5f6ed4dda..4daa0f9c15 100644
--- a/event-bus/api/src/test/java/org/apache/james/events/EventBusConcurrentTestContract.java
+++ b/event-bus/api/src/test/java/org/apache/james/events/EventBusConcurrentTestContract.java
@@ -78,7 +78,7 @@ public interface EventBusConcurrentTestContract {
             int totalGlobalRegistrations = 3; // GroupA + GroupB + GroupC
 
             ConcurrentTestRunner.builder()
-                .operation((threadNumber, operationNumber) -> eventBus().dispatch(EVENT, NO_KEYS).block())
+                .reactorOperation((threadNumber, operationNumber) -> eventBus().dispatch(EVENT, NO_KEYS))
                 .threadCount(THREAD_COUNT)
                 .operationCount(OPERATION_COUNT)
                 .runSuccessfullyWithin(FIVE_SECONDS);
@@ -101,7 +101,7 @@ public interface EventBusConcurrentTestContract {
             int totalEventBus = 1;
 
             ConcurrentTestRunner.builder()
-                .operation((threadNumber, operationNumber) -> eventBus().dispatch(EVENT, ALL_KEYS).block())
+                .reactorOperation((threadNumber, operationNumber) -> eventBus().dispatch(EVENT, ALL_KEYS))
                 .threadCount(THREAD_COUNT)
                 .operationCount(OPERATION_COUNT)
                 .runSuccessfullyWithin(FIVE_SECONDS);
@@ -131,7 +131,7 @@ public interface EventBusConcurrentTestContract {
             int totalEventDeliveredByKeys = totalKeyListenerRegistrations * TOTAL_DISPATCH_OPERATIONS;
 
             ConcurrentTestRunner.builder()
-                .operation((threadNumber, operationNumber) -> eventBus().dispatch(EVENT, ALL_KEYS).block())
+                .reactorOperation((threadNumber, operationNumber) -> eventBus().dispatch(EVENT, ALL_KEYS))
                 .threadCount(THREAD_COUNT)
                 .operationCount(OPERATION_COUNT)
                 .runSuccessfullyWithin(FIVE_SECONDS);
@@ -163,7 +163,7 @@ public interface EventBusConcurrentTestContract {
             int totalGlobalRegistrations = 3; // GroupA + GroupB + GroupC
 
             ConcurrentTestRunner.builder()
-                .operation((threadNumber, operationNumber) -> eventBus().dispatch(EVENT, NO_KEYS).block())
+                .reactorOperation((threadNumber, operationNumber) -> eventBus().dispatch(EVENT, NO_KEYS))
                 .threadCount(THREAD_COUNT)
                 .operationCount(OPERATION_COUNT)
                 .runSuccessfullyWithin(FIVE_SECONDS);
@@ -191,7 +191,7 @@ public interface EventBusConcurrentTestContract {
             int totalEventBus = 2; // eventBus1 + eventBus2
 
             ConcurrentTestRunner.builder()
-                .operation((threadNumber, operationNumber) -> eventBus().dispatch(EVENT, ALL_KEYS).block())
+                .reactorOperation((threadNumber, operationNumber) -> eventBus().dispatch(EVENT, ALL_KEYS))
                 .threadCount(THREAD_COUNT)
                 .operationCount(OPERATION_COUNT)
                 .runSuccessfullyWithin(FIVE_SECONDS);
@@ -227,7 +227,7 @@ public interface EventBusConcurrentTestContract {
             int totalEventDeliveredByKeys = totalKeyListenerRegistrations * totalEventBus * TOTAL_DISPATCH_OPERATIONS;
 
             ConcurrentTestRunner.builder()
-                .operation((threadNumber, operationNumber) -> eventBus().dispatch(EVENT, ALL_KEYS).block())
+                .reactorOperation((threadNumber, operationNumber) -> eventBus().dispatch(EVENT, ALL_KEYS))
                 .threadCount(THREAD_COUNT)
                 .operationCount(OPERATION_COUNT)
                 .runSuccessfullyWithin(FIVE_SECONDS);
diff --git a/event-bus/distributed/src/test/java/org/apache/james/events/RabbitMQEventBusTest.java b/event-bus/distributed/src/test/java/org/apache/james/events/RabbitMQEventBusTest.java
index 99c7e88cbe..a7f303e34b 100644
--- a/event-bus/distributed/src/test/java/org/apache/james/events/RabbitMQEventBusTest.java
+++ b/event-bus/distributed/src/test/java/org/apache/james/events/RabbitMQEventBusTest.java
@@ -52,6 +52,7 @@ import static org.mockito.Mockito.when;
 import java.io.Closeable;
 import java.nio.charset.StandardCharsets;
 import java.time.Duration;
+import java.util.NoSuchElementException;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.IntStream;
@@ -317,7 +318,7 @@ class RabbitMQEventBusTest implements GroupContract.SingleEventBusGroupContract,
             int totalDispatchOperations = threadCount * operationCount;
             eventBus = (RabbitMQEventBus) eventBus();
             ConcurrentTestRunner.builder()
-                .operation((threadNumber, operationNumber) -> eventBus.dispatch(EVENT, NO_KEYS).block())
+                .reactorOperation((threadNumber, operationNumber) -> eventBus.dispatch(EVENT, NO_KEYS))
                 .threadCount(threadCount)
                 .operationCount(operationCount)
                 .runSuccessfullyWithin(Duration.ofMinutes(3));
@@ -469,8 +470,8 @@ class RabbitMQEventBusTest implements GroupContract.SingleEventBusGroupContract,
                     rabbitMQNetWorkIssueExtension.getRabbitMQ().pause();
 
                     assertThatThrownBy(() -> rabbitMQEventBusWithNetWorkIssue.dispatch(EVENT, NO_KEYS).block())
-                        .isInstanceOf(IllegalStateException.class)
-                        .hasMessageContaining("Retries exhausted");
+                        .isInstanceOf(NoSuchElementException.class)
+                        .hasMessageContaining("Timeout waiting for idle object");
 
                     rabbitMQNetWorkIssueExtension.getRabbitMQ().unpause();
 
@@ -591,8 +592,8 @@ class RabbitMQEventBusTest implements GroupContract.SingleEventBusGroupContract,
                 rabbitMQExtension.getRabbitMQ().pause();
 
                 assertThatThrownBy(() -> eventBus.dispatch(EVENT, NO_KEYS).block())
-                    .isInstanceOf(IllegalStateException.class)
-                    .hasMessageContaining("Retries exhausted");
+                        .isInstanceOf(NoSuchElementException.class)
+                        .hasMessageContaining("Timeout waiting for idle object");
 
                 rabbitMQExtension.getRabbitMQ().unpause();
 
@@ -628,8 +629,8 @@ class RabbitMQEventBusTest implements GroupContract.SingleEventBusGroupContract,
                 rabbitMQExtension.getRabbitMQ().pause();
 
                 assertThatThrownBy(() -> eventBus.dispatch(EVENT, NO_KEYS).block())
-                    .isInstanceOf(IllegalStateException.class)
-                    .hasMessageContaining("Retries exhausted");
+                        .isInstanceOf(NoSuchElementException.class)
+                        .hasMessageContaining("Timeout waiting for idle object");
 
                 rabbitMQExtension.getRabbitMQ().unpause();
 
@@ -646,8 +647,8 @@ class RabbitMQEventBusTest implements GroupContract.SingleEventBusGroupContract,
                 rabbitMQExtension.getRabbitMQ().pause();
 
                 assertThatThrownBy(() -> eventBus.dispatch(EVENT, NO_KEYS).block())
-                    .isInstanceOf(IllegalStateException.class)
-                    .hasMessageContaining("Retries exhausted");
+                        .isInstanceOf(NoSuchElementException.class)
+                        .hasMessageContaining("Timeout waiting for idle object");
 
                 rabbitMQExtension.getRabbitMQ().unpause();
 
diff --git a/server/apps/distributed-app/src/test/java/org/apache/james/modules/DockerRabbitMQRule.java b/server/apps/distributed-app/src/test/java/org/apache/james/modules/DockerRabbitMQRule.java
index 4556b03eb5..ff772bf63a 100644
--- a/server/apps/distributed-app/src/test/java/org/apache/james/modules/DockerRabbitMQRule.java
+++ b/server/apps/distributed-app/src/test/java/org/apache/james/modules/DockerRabbitMQRule.java
@@ -62,7 +62,7 @@ public class DockerRabbitMQRule implements GuiceModuleTestRule {
             binder -> binder.bind(ReactorRabbitMQChannelPool.Configuration.class)
                 .toInstance(ReactorRabbitMQChannelPool.Configuration.builder()
                     .retries(2)
-                    .minBorrowDelay(java.time.Duration.ofMillis(5))
+                    .maxBorrowDelay(java.time.Duration.ofSeconds(5))
                     .maxChannel(3)),
             binder -> binder.bind(SimpleConnectionPool.Configuration.class)
                 .toInstance(SimpleConnectionPool.Configuration.builder()


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


[james-project] 04/06: JAMES-3749 Allow disable durability, publish confirms

Posted by bt...@apache.org.
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 f9069aff92c97e69f2fda48dd74560a72bbeabab
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Apr 15 12:39:21 2022 +0700

    JAMES-3749 Allow disable durability, publish confirms
    
    Doing so enable massive gains in throughtput thus some
    operators might be interested in it...
---
 .../backends/rabbitmq/RabbitMQConfiguration.java   | 44 ++++++++++++++++++++--
 .../org/apache/james/events/EventDispatcher.java   | 19 +++++++---
 .../james/events/KeyRegistrationHandler.java       |  3 +-
 .../org/apache/james/events/RabbitMQEventBus.java  |  4 +-
 .../modules/ROOT/pages/configure/rabbitmq.adoc     | 13 ++++++-
 .../org/apache/james/queue/rabbitmq/Enqueuer.java  | 38 ++++++++++++-------
 .../queue/rabbitmq/RabbitMQMailQueueFactory.java   |  2 +-
 .../view/RabbitMQMailQueueConfiguration.java       | 26 ++++++++++---
 src/site/xdoc/server/config-rabbitmq.xml           | 10 +++++
 9 files changed, 123 insertions(+), 36 deletions(-)

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 48588d478b..75f096fdec 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
@@ -304,6 +304,8 @@ public class RabbitMQConfiguration {
     private static final String SSL_KEY_STORE_PATH = "ssl.keystore";
     private static final String SSL_KEY_STORE_PASSWORD = "ssl.keystore.password";
     private static final String QUEUE_TTL = "notification.queue.ttl";
+    private static final String EVENT_BUS_NOTIFICATION_DURABILITY_ENABLED = "event.bus.notification.durability.enabled";
+    private static final String EVENT_BUS_PUBLISH_CONFIRM_ENABLED = "event.bus.publish.confirm.enabled";
 
     public static class ManagementCredentials {
 
@@ -398,6 +400,8 @@ public class RabbitMQConfiguration {
         private Optional<Integer> quorumQueueReplicationFactor;
         private Optional<SSLConfiguration> sslConfiguration;
         private Optional<Long> queueTTL;
+        private Optional<Boolean> eventBusPublishConfirmEnabled;
+        private Optional<Boolean> eventBusNotificationDurabilityEnabled;
 
         private Builder(URI amqpUri, URI managementUri, ManagementCredentials managementCredentials) {
             this.amqpUri = amqpUri;
@@ -417,6 +421,8 @@ public class RabbitMQConfiguration {
             this.quorumQueueReplicationFactor = Optional.empty();
             this.hosts = ImmutableList.builder();
             this.queueTTL = Optional.empty();
+            this.eventBusPublishConfirmEnabled = Optional.empty();
+            this.eventBusNotificationDurabilityEnabled = Optional.empty();
         }
 
         public Builder maxRetries(int maxRetries) {
@@ -471,6 +477,16 @@ public class RabbitMQConfiguration {
             return this;
         }
 
+        public Builder eventBusPublishConfirmEnabled(Boolean eventBusPublishConfirmEnabled) {
+            this.eventBusPublishConfirmEnabled = Optional.ofNullable(eventBusPublishConfirmEnabled);
+            return this;
+        }
+
+        public Builder eventBusNotificationDurabilityEnabled(Boolean eventBusNotificationDurabilityEnabled) {
+            this.eventBusNotificationDurabilityEnabled = Optional.ofNullable(eventBusNotificationDurabilityEnabled);
+            return this;
+        }
+
         public Builder useQuorumQueues(Boolean useQuorumQueues) {
             this.useQuorumQueues = Optional.ofNullable(useQuorumQueues);
             return this;
@@ -517,7 +533,9 @@ public class RabbitMQConfiguration {
                     useQuorumQueues.orElse(false),
                     quorumQueueReplicationFactor.orElse(DEFAULT_QUORUM_QUEUE_REPLICATION_FACTOR),
                     hostsDefaultingToUri(),
-                    queueTTL);
+                    queueTTL,
+                    eventBusPublishConfirmEnabled.orElse(true),
+                    eventBusNotificationDurabilityEnabled.orElse(true));
         }
 
         private List<Host> hostsDefaultingToUri() {
@@ -578,6 +596,8 @@ public class RabbitMQConfiguration {
             .quorumQueueReplicationFactor(quorumQueueReplicationFactor)
             .hosts(hosts)
             .queueTTL(queueTTL)
+            .eventBusNotificationDurabilityEnabled(configuration.getBoolean(EVENT_BUS_NOTIFICATION_DURABILITY_ENABLED, null))
+            .eventBusPublishConfirmEnabled(configuration.getBoolean(EVENT_BUS_PUBLISH_CONFIRM_ENABLED, null))
             .build();
     }
 
@@ -646,11 +666,14 @@ public class RabbitMQConfiguration {
     private final List<Host> hosts;
     private final ManagementCredentials managementCredentials;
     private final Optional<Long> queueTTL;
+    private final boolean eventBusPublishConfirmEnabled;
+    private final boolean eventBusNotificationDurabilityEnabled;
 
     private RabbitMQConfiguration(URI uri, URI managementUri, ManagementCredentials managementCredentials, int maxRetries, int minDelayInMs,
                                   int connectionTimeoutInMs, int channelRpcTimeoutInMs, int handshakeTimeoutInMs, int shutdownTimeoutInMs,
                                   int networkRecoveryIntervalInMs, Boolean useSsl, Boolean useSslManagement, SSLConfiguration sslConfiguration,
-                                  boolean useQuorumQueues, int quorumQueueReplicationFactor, List<Host> hosts, Optional<Long> queueTTL) {
+                                  boolean useQuorumQueues, int quorumQueueReplicationFactor, List<Host> hosts, Optional<Long> queueTTL,
+                                  boolean eventBusPublishConfirmEnabled, boolean eventBusNotificationDurabilityEnabled) {
         this.uri = uri;
         this.managementUri = managementUri;
         this.managementCredentials = managementCredentials;
@@ -668,6 +691,8 @@ public class RabbitMQConfiguration {
         this.quorumQueueReplicationFactor = quorumQueueReplicationFactor;
         this.hosts = hosts;
         this.queueTTL = queueTTL;
+        this.eventBusPublishConfirmEnabled = eventBusPublishConfirmEnabled;
+        this.eventBusNotificationDurabilityEnabled = eventBusNotificationDurabilityEnabled;
     }
 
     public URI getUri() {
@@ -739,6 +764,14 @@ public class RabbitMQConfiguration {
         return queueTTL;
     }
 
+    public boolean isEventBusPublishConfirmEnabled() {
+        return eventBusPublishConfirmEnabled;
+    }
+
+    public boolean isEventBusNotificationDurabilityEnabled() {
+        return eventBusNotificationDurabilityEnabled;
+    }
+
     @Override
     public final boolean equals(Object o) {
         if (o instanceof RabbitMQConfiguration) {
@@ -760,7 +793,9 @@ public class RabbitMQConfiguration {
                 && Objects.equals(this.useSslManagement, that.useSslManagement)
                 && Objects.equals(this.sslConfiguration, that.sslConfiguration)
                 && Objects.equals(this.hosts, that.hosts)
-                && Objects.equals(this.queueTTL, that.queueTTL);
+                && Objects.equals(this.queueTTL, that.queueTTL)
+                && Objects.equals(this.eventBusPublishConfirmEnabled, that.eventBusPublishConfirmEnabled)
+                && Objects.equals(this.eventBusNotificationDurabilityEnabled, that.eventBusNotificationDurabilityEnabled);
         }
         return false;
     }
@@ -768,6 +803,7 @@ public class RabbitMQConfiguration {
     @Override
     public final int hashCode() {
         return Objects.hash(uri, managementUri, maxRetries, minDelayInMs, connectionTimeoutInMs, quorumQueueReplicationFactor, useQuorumQueues, hosts,
-            channelRpcTimeoutInMs, handshakeTimeoutInMs, shutdownTimeoutInMs, networkRecoveryIntervalInMs, managementCredentials, useSsl, useSslManagement, sslConfiguration, queueTTL);
+            channelRpcTimeoutInMs, handshakeTimeoutInMs, shutdownTimeoutInMs, networkRecoveryIntervalInMs, managementCredentials, useSsl, useSslManagement,
+            sslConfiguration, queueTTL, eventBusPublishConfirmEnabled, eventBusNotificationDurabilityEnabled);
     }
 }
diff --git a/event-bus/distributed/src/main/java/org/apache/james/events/EventDispatcher.java b/event-bus/distributed/src/main/java/org/apache/james/events/EventDispatcher.java
index 6270c645ac..f598bf1a59 100644
--- a/event-bus/distributed/src/main/java/org/apache/james/events/EventDispatcher.java
+++ b/event-bus/distributed/src/main/java/org/apache/james/events/EventDispatcher.java
@@ -32,6 +32,7 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.Set;
 
+import org.apache.james.backends.rabbitmq.RabbitMQConfiguration;
 import org.apache.james.events.RoutingKeyConverter.RoutingKey;
 import org.apache.james.util.MDCBuilder;
 import org.apache.james.util.MDCStructuredLogger;
@@ -67,11 +68,12 @@ public class EventDispatcher {
     private final AMQP.BasicProperties basicProperties;
     private final ListenerExecutor listenerExecutor;
     private final EventDeadLetters deadLetters;
+    private final RabbitMQConfiguration configuration;
 
     EventDispatcher(NamingStrategy namingStrategy, EventBusId eventBusId, EventSerializer eventSerializer, Sender sender,
                     LocalListenerRegistry localListenerRegistry,
                     ListenerExecutor listenerExecutor,
-                    EventDeadLetters deadLetters) {
+                    EventDeadLetters deadLetters, RabbitMQConfiguration configuration) {
         this.namingStrategy = namingStrategy;
         this.eventSerializer = eventSerializer;
         this.sender = sender;
@@ -84,6 +86,7 @@ public class EventDispatcher {
             .build();
         this.listenerExecutor = listenerExecutor;
         this.deadLetters = deadLetters;
+        this.configuration = configuration;
     }
 
     void start() {
@@ -183,11 +186,15 @@ public class EventDispatcher {
         if (routingKeys.isEmpty()) {
             return Mono.empty();
         }
-        return sender.sendWithPublishConfirms(toMessages(serializedEvent, routingKeys))
-            .subscribeOn(Schedulers.elastic()) // channel.confirmSelect is synchronous
-            .filter(outboundMessageResult -> !outboundMessageResult.isAck())
-            .next()
-            .handle((result, sink) -> sink.error(new Exception("Publish was not acked")));
+        if (configuration.isEventBusPublishConfirmEnabled()) {
+            return sender.sendWithPublishConfirms(toMessages(serializedEvent, routingKeys))
+                .subscribeOn(Schedulers.elastic()) // channel.confirmSelect is synchronous
+                .filter(outboundMessageResult -> !outboundMessageResult.isAck())
+                .next()
+                .handle((result, sink) -> sink.error(new Exception("Publish was not acked")));
+        } else {
+            return sender.send(toMessages(serializedEvent, routingKeys));
+        }
     }
 
     private Flux<OutboundMessage> toMessages(byte[] serializedEvent, Collection<RoutingKey> routingKeys) {
diff --git a/event-bus/distributed/src/main/java/org/apache/james/events/KeyRegistrationHandler.java b/event-bus/distributed/src/main/java/org/apache/james/events/KeyRegistrationHandler.java
index 593cb9d9c1..0ab240adb8 100644
--- a/event-bus/distributed/src/main/java/org/apache/james/events/KeyRegistrationHandler.java
+++ b/event-bus/distributed/src/main/java/org/apache/james/events/KeyRegistrationHandler.java
@@ -20,7 +20,6 @@
 package org.apache.james.events;
 
 import static org.apache.james.backends.rabbitmq.Constants.AUTO_DELETE;
-import static org.apache.james.backends.rabbitmq.Constants.DURABLE;
 import static org.apache.james.backends.rabbitmq.Constants.EXCLUSIVE;
 import static org.apache.james.events.RabbitMQEventBus.EVENT_BUS_ID;
 
@@ -121,7 +120,7 @@ class KeyRegistrationHandler {
     private void declareQueue(Sender sender) {
         sender.declareQueue(
             QueueSpecification.queue(registrationQueue.asString())
-                .durable(DURABLE)
+                .durable(configuration.isEventBusNotificationDurabilityEnabled())
                 .exclusive(!EXCLUSIVE)
                 .autoDelete(AUTO_DELETE)
                 .arguments(configuration.workQueueArgumentsBuilder().build()))
diff --git a/event-bus/distributed/src/main/java/org/apache/james/events/RabbitMQEventBus.java b/event-bus/distributed/src/main/java/org/apache/james/events/RabbitMQEventBus.java
index b8c85c788f..8755320d83 100644
--- a/event-bus/distributed/src/main/java/org/apache/james/events/RabbitMQEventBus.java
+++ b/event-bus/distributed/src/main/java/org/apache/james/events/RabbitMQEventBus.java
@@ -90,7 +90,7 @@ public class RabbitMQEventBus implements EventBus, Startable {
             LocalListenerRegistry localListenerRegistry = new LocalListenerRegistry();
             keyRegistrationHandler = new KeyRegistrationHandler(namingStrategy, eventBusId, eventSerializer, sender, receiverProvider, routingKeyConverter, localListenerRegistry, listenerExecutor, retryBackoff, configuration, metricFactory);
             groupRegistrationHandler = new GroupRegistrationHandler(namingStrategy, eventSerializer, channelPool, sender, receiverProvider, retryBackoff, eventDeadLetters, listenerExecutor, eventBusId, configuration);
-            eventDispatcher = new EventDispatcher(namingStrategy, eventBusId, eventSerializer, sender, localListenerRegistry, listenerExecutor, eventDeadLetters);
+            eventDispatcher = new EventDispatcher(namingStrategy, eventBusId, eventSerializer, sender, localListenerRegistry, listenerExecutor, eventDeadLetters, configuration);
 
             eventDispatcher.start();
             keyRegistrationHandler.start();
@@ -110,7 +110,7 @@ public class RabbitMQEventBus implements EventBus, Startable {
             LocalListenerRegistry localListenerRegistry = new LocalListenerRegistry();
             keyRegistrationHandler = new KeyRegistrationHandler(namingStrategy, eventBusId, eventSerializer, sender, receiverProvider, routingKeyConverter, localListenerRegistry, listenerExecutor, retryBackoff, configuration, metricFactory);
             groupRegistrationHandler = new GroupRegistrationHandler(namingStrategy, eventSerializer, channelPool, sender, receiverProvider, retryBackoff, eventDeadLetters, listenerExecutor, eventBusId, configuration);
-            eventDispatcher = new EventDispatcher(namingStrategy, eventBusId, eventSerializer, sender, localListenerRegistry, listenerExecutor, eventDeadLetters);
+            eventDispatcher = new EventDispatcher(namingStrategy, eventBusId, eventSerializer, sender, localListenerRegistry, listenerExecutor, eventDeadLetters, configuration);
 
             keyRegistrationHandler.declareQueue();
 
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 540d4b2173..6b97764135 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
@@ -88,8 +88,17 @@ False (default value) results in the usage of classic queues.
 
 | hosts
 | Optional, default to the host specified as part of the URI.
-| Allow creating cluster aware connections.
-| A coma separated list of hosts, example: hosts=ip1:5672,ip2:5672
+Allow creating cluster aware connections.
+A coma separated list of hosts, example: hosts=ip1:5672,ip2:5672
+
+| mailqueue.publish.confirm.enabled
+| Whether or not to enable publish confirms for the mail queue. Optional boolean, defaults to true.
+
+| event.bus.publish.confirm.enabled
+| Whether or not to enable publish confirms for the event bus. Optional boolean, defaults to true.
+
+| event.bus.notification.durability.enabled
+| Whether or not the queue backing notifications should be durable. Optional boolean, defaults to true.
 |===
 
 == RabbitMQ MailQueue Configuration
diff --git a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/Enqueuer.java b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/Enqueuer.java
index b72139c942..e7ad613971 100644
--- a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/Enqueuer.java
+++ b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/Enqueuer.java
@@ -34,6 +34,7 @@ import org.apache.james.blob.mail.MimeMessagePartsId;
 import org.apache.james.metrics.api.Metric;
 import org.apache.james.metrics.api.MetricFactory;
 import org.apache.james.queue.api.MailQueue;
+import org.apache.james.queue.rabbitmq.view.RabbitMQMailQueueConfiguration;
 import org.apache.james.queue.rabbitmq.view.api.MailQueueView;
 import org.apache.james.queue.rabbitmq.view.cassandra.CassandraMailQueueBrowser;
 import org.apache.mailet.Mail;
@@ -56,16 +57,18 @@ class Enqueuer {
     private final MailReferenceSerializer mailReferenceSerializer;
     private final Metric enqueueMetric;
     private final MailQueueView mailQueueView;
+    private final RabbitMQMailQueueConfiguration configuration;
     private final Clock clock;
 
     Enqueuer(MailQueueName name, Sender sender, Store<MimeMessage, MimeMessagePartsId> mimeMessageStore,
              MailReferenceSerializer serializer, MetricFactory metricFactory,
-             MailQueueView mailQueueView, Clock clock) {
+             MailQueueView mailQueueView, RabbitMQMailQueueConfiguration configuration, Clock clock) {
         this.name = name;
         this.sender = sender;
         this.mimeMessageStore = mimeMessageStore;
         this.mailReferenceSerializer = serializer;
         this.mailQueueView = mailQueueView;
+        this.configuration = configuration;
         this.clock = clock;
         this.enqueueMetric = metricFactory.generate(ENQUEUED_METRIC_NAME_PREFIX + name.asString());
     }
@@ -112,19 +115,26 @@ class Enqueuer {
             EMPTY_ROUTING_KEY,
             basicProperties,
             getMailReferenceBytes(mailReference));
-        return sender.sendWithPublishConfirms(Mono.just(data))
-            .subscribeOn(Schedulers.elastic()) // channel.confirmSelect is synchronous
-            .next()
-            .handle((result, sink) -> {
-                if (!result.isAck()) {
-                    sink.error(new MailQueue.MailQueueException("Publish was not acked"));
-                } else {
-                    sink.complete();
-                }
-            })
-            // AutoRecoveringConnection blocks this forever
-            .timeout(Duration.ofSeconds(10), Mono.error(() -> new MailQueue.MailQueueException("Timeout enqueueing " + mailReference.getMail().getName())))
-            .then();
+
+        if (configuration.isMailQueuePublishConfirmEnabled()) {
+            return sender.sendWithPublishConfirms(Mono.just(data))
+                .subscribeOn(Schedulers.elastic()) // channel.confirmSelect is synchronous
+                .next()
+                .handle((result, sink) -> {
+                    if (!result.isAck()) {
+                        sink.error(new MailQueue.MailQueueException("Publish was not acked"));
+                    } else {
+                        sink.complete();
+                    }
+                })
+                // AutoRecoveringConnection blocks this forever
+                .timeout(Duration.ofSeconds(10), Mono.error(() -> new MailQueue.MailQueueException("Timeout enqueueing " + mailReference.getMail().getName())))
+                .then();
+        } else {
+            return sender.send(Mono.just(data))
+                // AutoRecoveringConnection blocks this forever
+                .timeout(Duration.ofSeconds(10), Mono.error(() -> new MailQueue.MailQueueException("Timeout enqueueing " + mailReference.getMail().getName())));
+        }
     }
 
     private EnqueuedItem toEnqueuedItems(MailReference mailReference) {
diff --git a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueFactory.java b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueFactory.java
index ac8ae2490c..14e355c8c4 100644
--- a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueFactory.java
+++ b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueFactory.java
@@ -100,7 +100,7 @@ public class RabbitMQMailQueueFactory implements MailQueueFactory<RabbitMQMailQu
                 metricFactory,
                 mailQueueName,
                 new Enqueuer(mailQueueName, sender, mimeMessageStore, mailReferenceSerializer,
-                    metricFactory, mailQueueView, clock),
+                    metricFactory, mailQueueView, configuration, clock),
                 new Dequeuer(mailQueueName, receiverProvider, mailLoader, mailReferenceSerializer,
                     metricFactory, mailQueueView, prefetchCount),
                 mailQueueView,
diff --git a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/RabbitMQMailQueueConfiguration.java b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/RabbitMQMailQueueConfiguration.java
index 01455170b0..d0c1edb649 100644
--- a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/RabbitMQMailQueueConfiguration.java
+++ b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/RabbitMQMailQueueConfiguration.java
@@ -28,7 +28,8 @@ public class RabbitMQMailQueueConfiguration {
     private static final boolean DEFAULT_SIZE_METRICS_DISABLED = false;
 
     public static class Builder {
-        private Optional<Boolean> sizeMetricsEnabled;
+        private Optional<Boolean> sizeMetricsEnabled = Optional.empty();
+        private Optional<Boolean> mailQueuePublishConfirmEnabled = Optional.empty();
 
         public Builder sizeMetricsEnabled(boolean sizeMetricsEnabled) {
             this.sizeMetricsEnabled = Optional.of(sizeMetricsEnabled);
@@ -40,12 +41,19 @@ public class RabbitMQMailQueueConfiguration {
             return this;
         }
 
+        public Builder mailQueuePublishConfirmEnabled(Boolean mailQueuePublishConfirmEnabled) {
+            this.mailQueuePublishConfirmEnabled = Optional.ofNullable(mailQueuePublishConfirmEnabled);
+            return this;
+        }
+
         public RabbitMQMailQueueConfiguration build() {
-            return new RabbitMQMailQueueConfiguration(sizeMetricsEnabled.orElse(DEFAULT_SIZE_METRICS_DISABLED));
+            return new RabbitMQMailQueueConfiguration(sizeMetricsEnabled.orElse(DEFAULT_SIZE_METRICS_DISABLED),
+                mailQueuePublishConfirmEnabled.orElse(true));
         }
     }
 
     public static final String SIZE_METRICS_ENABLED_PROPERTY = "mailqueue.size.metricsEnabled";
+    private static final String MAIL_QUEUE_PUBLISH_CONFIRM_ENABLED = "mailqueue.publish.confirm.enabled";
 
     public static Builder builder() {
         return new Builder();
@@ -54,6 +62,7 @@ public class RabbitMQMailQueueConfiguration {
     public static RabbitMQMailQueueConfiguration from(Configuration configuration) {
         return builder()
             .sizeMetricsEnabled(Optional.ofNullable(configuration.getBoolean(SIZE_METRICS_ENABLED_PROPERTY, null)))
+            .mailQueuePublishConfirmEnabled(configuration.getBoolean(MAIL_QUEUE_PUBLISH_CONFIRM_ENABLED, null))
             .build();
     }
 
@@ -70,9 +79,15 @@ public class RabbitMQMailQueueConfiguration {
     }
 
     private final boolean sizeMetricsEnabled;
+    private final boolean mailQueuePublishConfirmEnabled;
 
-    private RabbitMQMailQueueConfiguration(boolean sizeMetricsEnabled) {
+    private RabbitMQMailQueueConfiguration(boolean sizeMetricsEnabled, boolean mailQueuePublishConfirmEnabled) {
         this.sizeMetricsEnabled = sizeMetricsEnabled;
+        this.mailQueuePublishConfirmEnabled = mailQueuePublishConfirmEnabled;
+    }
+
+    public boolean isMailQueuePublishConfirmEnabled() {
+        return mailQueuePublishConfirmEnabled;
     }
 
     public boolean isSizeMetricsEnabled() {
@@ -84,13 +99,14 @@ public class RabbitMQMailQueueConfiguration {
         if (o instanceof RabbitMQMailQueueConfiguration) {
             RabbitMQMailQueueConfiguration that = (RabbitMQMailQueueConfiguration) o;
 
-            return Objects.equals(this.sizeMetricsEnabled, that.sizeMetricsEnabled);
+            return Objects.equals(this.sizeMetricsEnabled, that.sizeMetricsEnabled)
+                && Objects.equals(this.mailQueuePublishConfirmEnabled, that.mailQueuePublishConfirmEnabled);
         }
         return false;
     }
 
     @Override
     public final int hashCode() {
-        return Objects.hash(sizeMetricsEnabled);
+        return Objects.hash(sizeMetricsEnabled, mailQueuePublishConfirmEnabled);
     }
 }
diff --git a/src/site/xdoc/server/config-rabbitmq.xml b/src/site/xdoc/server/config-rabbitmq.xml
index 17d5781a88..bbb47fbd9a 100644
--- a/src/site/xdoc/server/config-rabbitmq.xml
+++ b/src/site/xdoc/server/config-rabbitmq.xml
@@ -128,6 +128,16 @@
           <dd>Optional integer, defaults is 3600000.
               This is used only on queues used to share notification patterns, are exclusive to a node. If omitted, it will not add the TTL configure when declaring queues.
               Configure queue ttl (in ms). References: https://www.rabbitmq.com/ttl.html#queue-ttl.</dd>
+
+          <dt><strong>mailqueue.publish.confirm.enabled</strong></dt>
+          <dd>Whether or not to enable publish confirms for the mail queue. Optional boolean, defaults to true.</dd>
+
+          <dt><strong>event.bus.publish.confirm.enabled</strong></dt>
+          <dd>Whether or not to enable publish confirms for the event bus. Optional boolean, defaults to true.</dd>
+
+          <dt><strong>event.bus.notification.durability.enabled</strong></dt>
+          <dd>Whether or not the queue backing notifications should be durable. Optional boolean, defaults to true.</dd>
+
       </dl>
   </section>
 


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


[james-project] 06/06: JAMES-3747 Fix a typo

Posted by bt...@apache.org.
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 4f054e02850950db5438f0e91065d2852a3421ea
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Mon Apr 18 14:43:54 2022 +0700

    JAMES-3747 Fix a typo
---
 .../james/backends/rabbitmq/ReactorRabbitMQChannelPool.java    | 10 +++++-----
 1 file changed, 5 insertions(+), 5 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 47bfd5b290..be7f0950a9 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
@@ -661,13 +661,13 @@ public class ReactorRabbitMQChannelPool implements ChannelPool, Startable {
     private final Configuration configuration;
 
     private final InstrumentedPool<? extends Channel> newPool;
-    private final MetricFactory metricFatcory;
+    private final MetricFactory metricFactory;
     private Sender sender;
 
-    public ReactorRabbitMQChannelPool(Mono<Connection> connectionMono, Configuration configuration, MetricFactory metricFatcory) {
+    public ReactorRabbitMQChannelPool(Mono<Connection> connectionMono, Configuration configuration, MetricFactory metricFactory) {
         this.connectionMono = connectionMono;
         this.configuration = configuration;
-        this.metricFatcory = metricFatcory;
+        this.metricFactory = metricFactory;
 
         newPool = PoolBuilder.from(connectionMono
             .flatMap(this::openChannel))
@@ -709,7 +709,7 @@ public class ReactorRabbitMQChannelPool implements ChannelPool, Startable {
 
     @Override
     public Mono<? extends Channel> getChannelMono() {
-        return Mono.from(metricFatcory.decoratePublisherWithTimerMetric("rabbit-acquire", borrow()));
+        return Mono.from(metricFactory.decoratePublisherWithTimerMetric("rabbit-acquire", borrow()));
     }
 
     private Mono<? extends Channel> borrow() {
@@ -722,7 +722,7 @@ public class ReactorRabbitMQChannelPool implements ChannelPool, Startable {
 
     @Override
     public BiConsumer<SignalType, Channel> getChannelCloseHandler() {
-        return (signalType, channel) -> metricFatcory.runPublishingTimerMetric("rabbit-release",
+        return (signalType, channel) -> metricFactory.runPublishingTimerMetric("rabbit-release",
             () -> {
                 PooledRef<? extends Channel> pooledRef = refs.remove(channel.getChannelNumber());
 


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