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 8867963964da0bfbc087d9b3900b989065cb44d3 Author: Benoit TELLIER <[email protected]> AuthorDate: Wed Jan 7 15:50:21 2026 +0100 JAMES-4159 RabbitMQEventBus: Have a factory to ease instanciation It allows to rely the best we can on injects for the boiler plate --- .../apache/james/events/GroupConsumerRetry.java | 1 - .../org/apache/james/events/RabbitMQEventBus.java | 22 ++++++++++++++++++++++ .../event/ContentDeletionEventBusModule.java | 15 ++------------- .../james/modules/event/JMAPEventBusModule.java | 16 +++------------- .../james/modules/event/MailboxEventBusModule.java | 18 +++++------------- 5 files changed, 32 insertions(+), 40 deletions(-) diff --git a/event-bus/distributed/src/main/java/org/apache/james/events/GroupConsumerRetry.java b/event-bus/distributed/src/main/java/org/apache/james/events/GroupConsumerRetry.java index bcdedced35..545fbe3fe3 100644 --- a/event-bus/distributed/src/main/java/org/apache/james/events/GroupConsumerRetry.java +++ b/event-bus/distributed/src/main/java/org/apache/james/events/GroupConsumerRetry.java @@ -25,7 +25,6 @@ import static org.apache.james.backends.rabbitmq.Constants.DURABLE; import static org.apache.james.backends.rabbitmq.Constants.EMPTY_ROUTING_KEY; import static org.apache.james.events.GroupRegistration.RETRY_COUNT; -import org.apache.james.backends.rabbitmq.RabbitMQConfiguration; import org.apache.james.util.MDCStructuredLogger; import org.apache.james.util.StructuredLogger; import org.slf4j.Logger; 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 009613683e..481844e565 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 @@ -23,6 +23,7 @@ import java.util.Collection; import java.util.Set; import jakarta.annotation.PreDestroy; +import jakarta.inject.Inject; import org.apache.james.backends.rabbitmq.RabbitMQConfiguration; import org.apache.james.backends.rabbitmq.ReactorRabbitMQChannelPool; @@ -39,6 +40,27 @@ import reactor.core.publisher.Mono; import reactor.rabbitmq.Sender; public class RabbitMQEventBus implements EventBus, Startable { + public static class Factory { + private final EventDeadLetters eventDeadLetters; + private final Sender sender; + private final ReceiverProvider receiverProvider; + private final ReactorRabbitMQChannelPool channelPool; + private final MetricFactory metricFactory; + + @Inject + public Factory(EventDeadLetters eventDeadLetters, Sender sender, ReceiverProvider receiverProvider, ReactorRabbitMQChannelPool channelPool, MetricFactory metricFactory) { + this.eventDeadLetters = eventDeadLetters; + this.sender = sender; + this.receiverProvider = receiverProvider; + this.channelPool = channelPool; + this.metricFactory = metricFactory; + } + + public RabbitMQEventBus create(EventBusId eventBusId, NamingStrategy namingStrategy, RoutingKeyConverter routingKeyConverter, EventSerializer eventSerializer, Configurations configurations) { + return new RabbitMQEventBus(namingStrategy, sender, receiverProvider, eventSerializer, routingKeyConverter, eventDeadLetters, metricFactory, channelPool, eventBusId, configurations); + } + } + private static final Set<RegistrationKey> NO_KEY = ImmutableSet.of(); private static final String NOT_RUNNING_ERROR_MESSAGE = "Event Bus is not running"; static final String EVENT_BUS_ID = "eventBusId"; diff --git a/server/container/guice/distributed/src/main/java/org/apache/james/modules/event/ContentDeletionEventBusModule.java b/server/container/guice/distributed/src/main/java/org/apache/james/modules/event/ContentDeletionEventBusModule.java index a5ae0f6018..02c2a4baf1 100644 --- a/server/container/guice/distributed/src/main/java/org/apache/james/modules/event/ContentDeletionEventBusModule.java +++ b/server/container/guice/distributed/src/main/java/org/apache/james/modules/event/ContentDeletionEventBusModule.java @@ -26,15 +26,12 @@ import java.util.Set; import jakarta.inject.Named; import org.apache.james.backends.rabbitmq.RabbitMQConfiguration; -import org.apache.james.backends.rabbitmq.ReactorRabbitMQChannelPool; -import org.apache.james.backends.rabbitmq.ReceiverProvider; import org.apache.james.backends.rabbitmq.SimpleConnectionPool; import org.apache.james.core.healthcheck.HealthCheck; import org.apache.james.event.json.MailboxEventSerializer; import org.apache.james.events.EventBus; import org.apache.james.events.EventBusId; import org.apache.james.events.EventBusReconnectionHandler; -import org.apache.james.events.EventDeadLetters; import org.apache.james.events.EventListener; import org.apache.james.events.GroupRegistrationHandler; import org.apache.james.events.KeyReconnectionHandler; @@ -45,7 +42,6 @@ import org.apache.james.events.RetryBackoffConfiguration; import org.apache.james.events.RoutingKeyConverter; import org.apache.james.jmap.change.Factory; import org.apache.james.mailbox.cassandra.DeleteMessageListener; -import org.apache.james.metrics.api.MetricFactory; import org.apache.james.utils.InitializationOperation; import org.apache.james.utils.InitilizationOperationBuilder; @@ -57,8 +53,6 @@ import com.google.inject.multibindings.Multibinder; import com.google.inject.multibindings.ProvidesIntoSet; import com.google.inject.name.Names; -import reactor.rabbitmq.Sender; - public class ContentDeletionEventBusModule extends AbstractModule { public static final String CONTENT_DELETION = "contentDeletion"; @@ -105,17 +99,12 @@ public class ContentDeletionEventBusModule extends AbstractModule { @Provides @Singleton @Named(CONTENT_DELETION) - RabbitMQEventBus provideContentDeletionEventBus(Sender sender, ReceiverProvider receiverProvider, + RabbitMQEventBus provideContentDeletionEventBus(RabbitMQEventBus.Factory eventBusFactory, MailboxEventSerializer eventSerializer, RetryBackoffConfiguration retryBackoffConfiguration, - EventDeadLetters eventDeadLetters, - MetricFactory metricFactory, ReactorRabbitMQChannelPool channelPool, @Named(CONTENT_DELETION) EventBusId eventBusId, RabbitMQConfiguration configuration) { - return new RabbitMQEventBus( - CONTENT_DELETION_NAMING_STRATEGY, - sender, receiverProvider, eventSerializer, new RoutingKeyConverter(ImmutableSet.of(new Factory())), - eventDeadLetters, metricFactory, channelPool, eventBusId, new RabbitMQEventBus.Configurations(configuration, retryBackoffConfiguration)); + return eventBusFactory.create(eventBusId, CONTENT_DELETION_NAMING_STRATEGY, new RoutingKeyConverter(ImmutableSet.of(new Factory())), eventSerializer, new RabbitMQEventBus.Configurations(configuration, retryBackoffConfiguration)); } @Provides diff --git a/server/container/guice/distributed/src/main/java/org/apache/james/modules/event/JMAPEventBusModule.java b/server/container/guice/distributed/src/main/java/org/apache/james/modules/event/JMAPEventBusModule.java index 14a83f7e11..a4e24239b0 100644 --- a/server/container/guice/distributed/src/main/java/org/apache/james/modules/event/JMAPEventBusModule.java +++ b/server/container/guice/distributed/src/main/java/org/apache/james/modules/event/JMAPEventBusModule.java @@ -24,14 +24,11 @@ import static org.apache.james.events.NamingStrategy.JMAP_NAMING_STRATEGY; import jakarta.inject.Named; import org.apache.james.backends.rabbitmq.RabbitMQConfiguration; -import org.apache.james.backends.rabbitmq.ReactorRabbitMQChannelPool; -import org.apache.james.backends.rabbitmq.ReceiverProvider; import org.apache.james.backends.rabbitmq.SimpleConnectionPool; import org.apache.james.core.healthcheck.HealthCheck; import org.apache.james.events.EventBus; import org.apache.james.events.EventBusId; import org.apache.james.events.EventBusReconnectionHandler; -import org.apache.james.events.EventDeadLetters; import org.apache.james.events.EventSerializer; import org.apache.james.events.GroupRegistrationHandler; import org.apache.james.events.KeyReconnectionHandler; @@ -44,7 +41,6 @@ import org.apache.james.jmap.InjectionKeys; import org.apache.james.jmap.change.Factory; import org.apache.james.jmap.change.JmapEventSerializer; import org.apache.james.jmap.pushsubscription.PushListener; -import org.apache.james.metrics.api.MetricFactory; import org.apache.james.utils.InitializationOperation; import org.apache.james.utils.InitilizationOperationBuilder; @@ -55,8 +51,6 @@ import com.google.inject.Singleton; import com.google.inject.multibindings.ProvidesIntoSet; import com.google.inject.name.Names; -import reactor.rabbitmq.Sender; - public class JMAPEventBusModule extends AbstractModule { @Override @@ -99,17 +93,13 @@ public class JMAPEventBusModule extends AbstractModule { @Provides @Singleton @Named(InjectionKeys.JMAP) - RabbitMQEventBus provideJmapEventBus(Sender sender, ReceiverProvider receiverProvider, + RabbitMQEventBus provideJmapEventBus(RabbitMQEventBus.Factory eventBusFactory, JmapEventSerializer eventSerializer, RetryBackoffConfiguration retryBackoffConfiguration, - EventDeadLetters eventDeadLetters, - MetricFactory metricFactory, ReactorRabbitMQChannelPool channelPool, @Named(InjectionKeys.JMAP) EventBusId eventBusId, RabbitMQConfiguration configuration) { - return new RabbitMQEventBus( - JMAP_NAMING_STRATEGY, - sender, receiverProvider, eventSerializer, new RoutingKeyConverter(ImmutableSet.of(new Factory())), eventDeadLetters, - metricFactory, channelPool, eventBusId, new RabbitMQEventBus.Configurations(configuration, retryBackoffConfiguration)); + return eventBusFactory.create(eventBusId, + JMAP_NAMING_STRATEGY, new RoutingKeyConverter(ImmutableSet.of(new Factory())), eventSerializer, new RabbitMQEventBus.Configurations(configuration, retryBackoffConfiguration)); } @Provides diff --git a/server/container/guice/distributed/src/main/java/org/apache/james/modules/event/MailboxEventBusModule.java b/server/container/guice/distributed/src/main/java/org/apache/james/modules/event/MailboxEventBusModule.java index b186463484..d98720cd86 100644 --- a/server/container/guice/distributed/src/main/java/org/apache/james/modules/event/MailboxEventBusModule.java +++ b/server/container/guice/distributed/src/main/java/org/apache/james/modules/event/MailboxEventBusModule.java @@ -22,15 +22,12 @@ package org.apache.james.modules.event; import static org.apache.james.events.NamingStrategy.MAILBOX_EVENT_NAMING_STRATEGY; import org.apache.james.backends.rabbitmq.RabbitMQConfiguration; -import org.apache.james.backends.rabbitmq.ReactorRabbitMQChannelPool; -import org.apache.james.backends.rabbitmq.ReceiverProvider; import org.apache.james.backends.rabbitmq.SimpleConnectionPool; import org.apache.james.core.healthcheck.HealthCheck; import org.apache.james.event.json.MailboxEventSerializer; import org.apache.james.events.EventBus; import org.apache.james.events.EventBusId; import org.apache.james.events.EventBusReconnectionHandler; -import org.apache.james.events.EventDeadLetters; import org.apache.james.events.GroupRegistrationHandler; import org.apache.james.events.KeyReconnectionHandler; import org.apache.james.events.NamingStrategy; @@ -41,7 +38,6 @@ import org.apache.james.events.RegistrationKey; import org.apache.james.events.RetryBackoffConfiguration; import org.apache.james.events.RoutingKeyConverter; import org.apache.james.mailbox.events.MailboxIdRegistrationKey; -import org.apache.james.metrics.api.MetricFactory; import org.apache.james.utils.InitializationOperation; import org.apache.james.utils.InitilizationOperationBuilder; @@ -51,8 +47,6 @@ import com.google.inject.Singleton; import com.google.inject.multibindings.Multibinder; import com.google.inject.multibindings.ProvidesIntoSet; -import reactor.rabbitmq.Sender; - public class MailboxEventBusModule extends AbstractModule { @Override @@ -95,13 +89,11 @@ public class MailboxEventBusModule extends AbstractModule { @Provides @Singleton - RabbitMQEventBus provideRabbitMQEventBus(NamingStrategy namingStrategy, Sender sender, ReceiverProvider receiverProvider, MailboxEventSerializer eventSerializer, - RetryBackoffConfiguration retryBackoff, - RoutingKeyConverter routingKeyConverter, - EventDeadLetters eventDeadLetters, MetricFactory metricFactory, ReactorRabbitMQChannelPool channelPool, - EventBusId eventBusId, RabbitMQConfiguration configuration) { - return new RabbitMQEventBus(namingStrategy, sender, receiverProvider, eventSerializer, routingKeyConverter, - eventDeadLetters, metricFactory, channelPool, eventBusId, new RabbitMQEventBus.Configurations(configuration, retryBackoff)); + RabbitMQEventBus provideRabbitMQEventBus(RabbitMQEventBus.Factory eventBusFactory, NamingStrategy namingStrategy, + MailboxEventSerializer eventSerializer, RetryBackoffConfiguration retryBackoff, + RoutingKeyConverter routingKeyConverter, EventBusId eventBusId, + RabbitMQConfiguration configuration) { + return eventBusFactory.create(eventBusId, namingStrategy, routingKeyConverter, eventSerializer, new RabbitMQEventBus.Configurations(configuration, retryBackoff)); } @Provides --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
