You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ro...@apache.org on 2019/09/03 15:30:25 UTC

[james-project] branch master updated (7c97471 -> 0b7669b)

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

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


    from 7c97471  JAMES-2867 Centralize jib and copy-rename-maven-plugin versions to master pom
     new 5cafcf0  JAMES-2813 Inject TerminationSubscriber into EventSourcingTaskManager
     new 5ff6326  JAMES-2813 Add RabbitMQTerminationSubscriber
     new 0b7669b  JAMES-2813 Introduce ReactorRabbitMQChannelPool.createSender

The 3 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:
 .../rabbitmq/ReactorRabbitMQChannelPool.java       |  15 +++
 .../james/mailbox/events/RabbitMQEventBus.java     |  11 +-
 .../apache/james/DistributedTaskManagerModule.java |   4 +
 .../distributed/RabbitMQTerminationSubscriber.java | 140 ++++++++++++++++++++
 .../distributed/RabbitMQWorkQueue.java             |   9 +-
 .../distributed/DistributedTaskManagerTest.java    |  14 +-
 .../RabbitMQTerminationSubscriberTest.java         |  73 +++++++++++
 .../eventsourcing/EventSourcingTaskManager.scala   |   6 +-
 .../apache/james/task/eventsourcing/Events.scala   |   8 +-
 ...eSupplier.scala => TerminationSubscriber.scala} |  31 ++++-
 .../EventSourcingTaskManagerTest.java              |   2 +-
 ...t.java => MemoryTerminationSubscriberTest.java} |  10 +-
 .../TerminationSubscriberContract.java             | 144 +++++++++++++++++++++
 13 files changed, 427 insertions(+), 40 deletions(-)
 create mode 100644 server/task-distributed/src/main/java/org/apache/james/task/eventsourcing/distributed/RabbitMQTerminationSubscriber.java
 create mode 100644 server/task-distributed/src/test/java/org/apache/james/task/eventsourcing/distributed/RabbitMQTerminationSubscriberTest.java
 copy server/task/src/main/scala/org/apache/james/task/eventsourcing/{WorkQueueSupplier.scala => TerminationSubscriber.scala} (59%)
 copy server/task/src/test/java/org/apache/james/task/eventsourcing/{MemoryTaskExecutionDetailsProjectionTest.java => MemoryTerminationSubscriberTest.java} (84%)
 create mode 100644 server/task/src/test/java/org/apache/james/task/eventsourcing/TerminationSubscriberContract.java


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


[james-project] 01/03: JAMES-2813 Inject TerminationSubscriber into EventSourcingTaskManager

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 5cafcf00056a659e371586990761bd6ba61494ba
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Tue Aug 27 11:01:11 2019 +0200

    JAMES-2813 Inject TerminationSubscriber into EventSourcingTaskManager
---
 .../apache/james/DistributedTaskManagerModule.java |   4 +
 .../distributed/DistributedTaskManagerTest.java    |   3 +-
 .../eventsourcing/EventSourcingTaskManager.scala   |   6 +-
 .../apache/james/task/eventsourcing/Events.scala   |   8 +-
 .../task/eventsourcing/TerminationSubscriber.scala |  46 +++++++
 .../EventSourcingTaskManagerTest.java              |   2 +-
 .../MemoryTerminationSubscriberTest.java           |  27 ++++
 .../TerminationSubscriberContract.java             | 144 +++++++++++++++++++++
 8 files changed, 233 insertions(+), 7 deletions(-)

diff --git a/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/DistributedTaskManagerModule.java b/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/DistributedTaskManagerModule.java
index 4d2b2ab..7dd21ef 100644
--- a/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/DistributedTaskManagerModule.java
+++ b/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/DistributedTaskManagerModule.java
@@ -23,7 +23,9 @@ package org.apache.james;
 import org.apache.james.modules.server.HostnameModule;
 import org.apache.james.task.TaskManager;
 import org.apache.james.task.eventsourcing.EventSourcingTaskManager;
+import org.apache.james.task.eventsourcing.MemoryTerminationSubscriber;
 import org.apache.james.task.eventsourcing.TaskExecutionDetailsProjection;
+import org.apache.james.task.eventsourcing.TerminationSubscriber;
 import org.apache.james.task.eventsourcing.WorkQueueSupplier;
 import org.apache.james.task.eventsourcing.cassandra.CassandraTaskExecutionDetailsProjection;
 import org.apache.james.task.eventsourcing.distributed.RabbitMQWorkQueueSupplier;
@@ -40,6 +42,8 @@ public class DistributedTaskManagerModule extends AbstractModule {
         bind(TaskManager.class).in(Scopes.SINGLETON);
         bind(WorkQueueSupplier.class).in(Scopes.SINGLETON);
         bind(TaskExecutionDetailsProjection.class).to(CassandraTaskExecutionDetailsProjection.class);
+        bind(TerminationSubscriber.class).in(Scopes.SINGLETON);
+        bind(TerminationSubscriber.class).toInstance(new MemoryTerminationSubscriber());
         bind(TaskManager.class).to(EventSourcingTaskManager.class);
         bind(WorkQueueSupplier.class).to(RabbitMQWorkQueueSupplier.class);
     }
diff --git a/server/task-distributed/src/test/java/org/apache/james/task/eventsourcing/distributed/DistributedTaskManagerTest.java b/server/task-distributed/src/test/java/org/apache/james/task/eventsourcing/distributed/DistributedTaskManagerTest.java
index ca70292..ced6652 100644
--- a/server/task-distributed/src/test/java/org/apache/james/task/eventsourcing/distributed/DistributedTaskManagerTest.java
+++ b/server/task-distributed/src/test/java/org/apache/james/task/eventsourcing/distributed/DistributedTaskManagerTest.java
@@ -48,6 +48,7 @@ import org.apache.james.task.TaskManager;
 import org.apache.james.task.TaskManagerContract;
 import org.apache.james.task.eventsourcing.EventSourcingTaskManager;
 import org.apache.james.task.eventsourcing.Hostname;
+import org.apache.james.task.eventsourcing.MemoryTerminationSubscriber;
 import org.apache.james.task.eventsourcing.TaskExecutionDetailsProjection;
 import org.apache.james.task.eventsourcing.WorkQueueSupplier;
 import org.apache.james.task.eventsourcing.cassandra.CassandraTaskExecutionDetailsProjection;
@@ -107,7 +108,7 @@ class DistributedTaskManagerTest implements TaskManagerContract {
     }
 
     private EventSourcingTaskManager taskManager(Hostname hostname) {
-        return new EventSourcingTaskManager(workQueueSupplier, eventStore, executionDetailsProjection, hostname);
+        return new EventSourcingTaskManager(workQueueSupplier, eventStore, executionDetailsProjection, hostname, new MemoryTerminationSubscriber());
     }
 
     @Test
diff --git a/server/task/src/main/scala/org/apache/james/task/eventsourcing/EventSourcingTaskManager.scala b/server/task/src/main/scala/org/apache/james/task/eventsourcing/EventSourcingTaskManager.scala
index f57c947..93b8302 100644
--- a/server/task/src/main/scala/org/apache/james/task/eventsourcing/EventSourcingTaskManager.scala
+++ b/server/task/src/main/scala/org/apache/james/task/eventsourcing/EventSourcingTaskManager.scala
@@ -34,7 +34,8 @@ class EventSourcingTaskManager @Inject @VisibleForTesting private[eventsourcing]
                                                                                   workQueueSupplier: WorkQueueSupplier,
                                                                                   val eventStore: EventStore,
                                                                                   val executionDetailsProjection: TaskExecutionDetailsProjection,
-                                                                                  val hostname: Hostname) extends TaskManager with Closeable {
+                                                                                  val hostname: Hostname,
+                                                                                  val terminationSubscriber: TerminationSubscriber) extends TaskManager with Closeable {
 
   private val delayBetweenPollingInMs = 500
 
@@ -60,7 +61,8 @@ class EventSourcingTaskManager @Inject @VisibleForTesting private[eventsourcing]
       new FailCommandHandler(loadHistory)),
     subscribers = Set(
       executionDetailsProjection.asSubscriber(hostname),
-      workDispatcher),
+      workDispatcher,
+      terminationSubscriber),
     eventStore = eventStore)
 
   private val workQueue: WorkQueue = workQueueSupplier(eventSourcingSystem)
diff --git a/server/task/src/main/scala/org/apache/james/task/eventsourcing/Events.scala b/server/task/src/main/scala/org/apache/james/task/eventsourcing/Events.scala
index 6d9c7ba..68730bd 100644
--- a/server/task/src/main/scala/org/apache/james/task/eventsourcing/Events.scala
+++ b/server/task/src/main/scala/org/apache/james/task/eventsourcing/Events.scala
@@ -28,6 +28,8 @@ sealed abstract class TaskEvent(aggregateId: TaskAggregateId, val eventId: Event
   override def getAggregateId: TaskAggregateId = aggregateId
 }
 
+sealed abstract class TerminalTaskEvent(aggregateId: TaskAggregateId, override val eventId: EventId) extends TaskEvent(aggregateId, eventId)
+
 case class Hostname(private val value: String) {
   def asString: String = value
 }
@@ -50,8 +52,8 @@ case class Started(aggregateId: TaskAggregateId, override val eventId: EventId,
 
 case class CancelRequested(aggregateId: TaskAggregateId, override val eventId: EventId, hostname: Hostname) extends TaskEvent(aggregateId, eventId)
 
-case class Completed(aggregateId: TaskAggregateId, override val eventId: EventId, result: Result) extends TaskEvent(aggregateId, eventId)
+case class Completed(aggregateId: TaskAggregateId, override val eventId: EventId, result: Result) extends TerminalTaskEvent(aggregateId, eventId)
 
-case class Failed(aggregateId: TaskAggregateId, override val eventId: EventId) extends TaskEvent(aggregateId, eventId)
+case class Failed(aggregateId: TaskAggregateId, override val eventId: EventId) extends TerminalTaskEvent(aggregateId, eventId)
 
-case class Cancelled(aggregateId: TaskAggregateId, override val eventId: EventId) extends TaskEvent(aggregateId, eventId)
+case class Cancelled(aggregateId: TaskAggregateId, override val eventId: EventId) extends TerminalTaskEvent(aggregateId, eventId)
diff --git a/server/task/src/main/scala/org/apache/james/task/eventsourcing/TerminationSubscriber.scala b/server/task/src/main/scala/org/apache/james/task/eventsourcing/TerminationSubscriber.scala
new file mode 100644
index 0000000..af23af4
--- /dev/null
+++ b/server/task/src/main/scala/org/apache/james/task/eventsourcing/TerminationSubscriber.scala
@@ -0,0 +1,46 @@
+/** **************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0                   *
+ * *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ * ***************************************************************/
+
+package org.apache.james.task.eventsourcing
+
+import org.apache.james.eventsourcing.{Event, Subscriber}
+import org.reactivestreams.Publisher
+
+import reactor.core.publisher.DirectProcessor
+
+trait TerminationSubscriber extends Subscriber {
+  override def handle(event: Event): Unit = event match {
+    case event: TerminalTaskEvent => addEvent(event)
+    case _ =>
+  }
+
+  def addEvent(event: Event): Unit
+
+  def listenEvents: Publisher[Event]
+}
+
+class MemoryTerminationSubscriber extends TerminationSubscriber {
+  private val events = DirectProcessor.create[Event]()
+
+  override def addEvent(event: Event): Unit =
+    events.onNext(event)
+
+  override def listenEvents: Publisher[Event] =
+    events.share()
+}
\ No newline at end of file
diff --git a/server/task/src/test/java/org/apache/james/task/eventsourcing/EventSourcingTaskManagerTest.java b/server/task/src/test/java/org/apache/james/task/eventsourcing/EventSourcingTaskManagerTest.java
index 281e217..cb5f19a 100644
--- a/server/task/src/test/java/org/apache/james/task/eventsourcing/EventSourcingTaskManagerTest.java
+++ b/server/task/src/test/java/org/apache/james/task/eventsourcing/EventSourcingTaskManagerTest.java
@@ -61,7 +61,7 @@ class EventSourcingTaskManagerTest implements TaskManagerContract {
             TaskManagerWorker worker = new SerialTaskManagerWorker(listener);
             return new MemoryWorkQueue(worker);
         };
-        taskManager = new EventSourcingTaskManager(workQueueSupplier, eventStore, executionDetailsProjection, HOSTNAME);
+        taskManager = new EventSourcingTaskManager(workQueueSupplier, eventStore, executionDetailsProjection, HOSTNAME, new MemoryTerminationSubscriber());
     }
 
     @AfterEach
diff --git a/server/task/src/test/java/org/apache/james/task/eventsourcing/MemoryTerminationSubscriberTest.java b/server/task/src/test/java/org/apache/james/task/eventsourcing/MemoryTerminationSubscriberTest.java
new file mode 100644
index 0000000..b8d2707
--- /dev/null
+++ b/server/task/src/test/java/org/apache/james/task/eventsourcing/MemoryTerminationSubscriberTest.java
@@ -0,0 +1,27 @@
+/**
+ * *************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ * http://www.apache.org/licenses/LICENSE-2.0                   *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ***************************************************************/
+
+package org.apache.james.task.eventsourcing;
+
+class MemoryTerminationSubscriberTest implements TerminationSubscriberContract {
+    public TerminationSubscriber subscriber() {
+        return new MemoryTerminationSubscriber();
+    }
+}
diff --git a/server/task/src/test/java/org/apache/james/task/eventsourcing/TerminationSubscriberContract.java b/server/task/src/test/java/org/apache/james/task/eventsourcing/TerminationSubscriberContract.java
new file mode 100644
index 0000000..5b0f5ff
--- /dev/null
+++ b/server/task/src/test/java/org/apache/james/task/eventsourcing/TerminationSubscriberContract.java
@@ -0,0 +1,144 @@
+/**
+ * *************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0                   *
+ * *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ***************************************************************/
+
+package org.apache.james.task.eventsourcing;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.time.Duration;
+import java.util.List;
+
+import org.apache.james.eventsourcing.Event;
+import org.apache.james.eventsourcing.EventId;
+import org.apache.james.task.Task;
+import org.apache.james.task.TaskId;
+
+import org.assertj.core.api.ListAssert;
+import org.junit.jupiter.api.Test;
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+import reactor.core.scheduler.Schedulers;
+
+public interface TerminationSubscriberContract {
+
+    Completed COMPLETED_EVENT = new Completed(new TaskAggregateId(TaskId.generateTaskId()), EventId.fromSerialized(42), Task.Result.COMPLETED);
+    Failed FAILED_EVENT = new Failed(new TaskAggregateId(TaskId.generateTaskId()), EventId.fromSerialized(42));
+    Cancelled CANCELLED_EVENT = new Cancelled(new TaskAggregateId(TaskId.generateTaskId()), EventId.fromSerialized(42));
+    Duration DELAY_BETWEEN_EVENTS = Duration.ofMillis(50);
+    Duration DELAY_BEFORE_PUBLISHING = Duration.ofMillis(50);
+
+    TerminationSubscriber subscriber();
+
+    @Test
+    default void handlingCompletedShouldBeListed() {
+        TerminationSubscriber subscriber = subscriber();
+
+        sendEvents(subscriber, COMPLETED_EVENT);
+
+        assertEvents(subscriber).containsOnly(COMPLETED_EVENT);
+    }
+
+    @Test
+    default void handlingFailedShouldBeListed() {
+        TerminationSubscriber subscriber = subscriber();
+
+        sendEvents(subscriber, FAILED_EVENT);
+
+        assertEvents(subscriber).containsOnly(FAILED_EVENT);
+    }
+
+    @Test
+    default void handlingCancelledShouldBeListed() {
+        TerminationSubscriber subscriber = subscriber();
+
+        sendEvents(subscriber, CANCELLED_EVENT);
+
+        assertEvents(subscriber).containsOnly(CANCELLED_EVENT);
+    }
+
+    @Test
+    default void handlingNonTerminalEventShouldNotBeListed() {
+        TerminationSubscriber subscriber = subscriber();
+        TaskEvent event = new Started(new TaskAggregateId(TaskId.generateTaskId()), EventId.fromSerialized(42), new Hostname("foo"));
+
+        sendEvents(subscriber, event);
+
+        assertEvents(subscriber).isEmpty();
+    }
+
+    @Test
+    default void handlingMultipleEventsShouldBeListed() {
+        TerminationSubscriber subscriber = subscriber();
+
+        sendEvents(subscriber, COMPLETED_EVENT, FAILED_EVENT, CANCELLED_EVENT);
+
+        assertEvents(subscriber).containsExactly(COMPLETED_EVENT, FAILED_EVENT, CANCELLED_EVENT);
+    }
+
+    @Test
+    default void multipleListeningEventsShouldShareEvents() {
+        TerminationSubscriber subscriber = subscriber();
+
+        sendEvents(subscriber, COMPLETED_EVENT, FAILED_EVENT, CANCELLED_EVENT);
+
+        List<List<Event>> listenedEvents = Flux.range(0, 2)
+            .subscribeOn(Schedulers.elastic())
+            .flatMap(ignored -> collectEvents(subscriber))
+            .collectList()
+            .block();
+        assertThat(listenedEvents).hasSize(2);
+        assertThat(listenedEvents.get(0)).containsExactly(COMPLETED_EVENT, FAILED_EVENT, CANCELLED_EVENT);
+        assertThat(listenedEvents.get(1)).isEqualTo(listenedEvents.get(0));
+    }
+
+    @Test
+    default void dynamicListeningEventsShouldGetOnlyNewEvents() {
+        TerminationSubscriber subscriber = subscriber();
+
+        sendEvents(subscriber, COMPLETED_EVENT, FAILED_EVENT, CANCELLED_EVENT);
+
+        List<Event> listenedEvents = Mono.delay(DELAY_BEFORE_PUBLISHING.plus(DELAY_BETWEEN_EVENTS.multipliedBy(3).dividedBy(2)))
+            .then(Mono.defer(() -> collectEvents(subscriber)))
+            .subscribeOn(Schedulers.elastic())
+            .block();
+        assertThat(listenedEvents).containsExactly(FAILED_EVENT, CANCELLED_EVENT);
+    }
+
+    default ListAssert<Event> assertEvents(TerminationSubscriber subscriber) {
+        return assertThat(collectEvents(subscriber)
+            .block());
+    }
+
+    default Mono<List<Event>> collectEvents(TerminationSubscriber subscriber) {
+        return Flux.from(subscriber.listenEvents())
+            .subscribeOn(Schedulers.elastic())
+            .take(DELAY_BEFORE_PUBLISHING.plus(DELAY_BETWEEN_EVENTS.multipliedBy(7)))
+            .collectList();
+    }
+
+    default void sendEvents(TerminationSubscriber subscriber, Event... events) {
+        Mono.delay(DELAY_BEFORE_PUBLISHING)
+            .flatMapMany(ignored -> Flux.fromArray(events)
+                .subscribeOn(Schedulers.elastic())
+                .delayElements(DELAY_BETWEEN_EVENTS)
+                .doOnNext(subscriber::handle))
+            .subscribe();
+    }
+}
\ No newline at end of file


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


[james-project] 02/03: JAMES-2813 Add RabbitMQTerminationSubscriber

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 5ff63262face2880e50cb1c775fcc9b1c13fc320
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Tue Aug 27 16:10:42 2019 +0200

    JAMES-2813 Add RabbitMQTerminationSubscriber
---
 .../apache/james/DistributedTaskManagerModule.java |   4 +-
 .../distributed/RabbitMQTerminationSubscriber.java | 146 +++++++++++++++++++++
 .../distributed/DistributedTaskManagerTest.java    |  15 ++-
 .../RabbitMQTerminationSubscriberTest.java         |  73 +++++++++++
 4 files changed, 230 insertions(+), 8 deletions(-)

diff --git a/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/DistributedTaskManagerModule.java b/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/DistributedTaskManagerModule.java
index 7dd21ef..76197db 100644
--- a/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/DistributedTaskManagerModule.java
+++ b/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/DistributedTaskManagerModule.java
@@ -23,11 +23,11 @@ package org.apache.james;
 import org.apache.james.modules.server.HostnameModule;
 import org.apache.james.task.TaskManager;
 import org.apache.james.task.eventsourcing.EventSourcingTaskManager;
-import org.apache.james.task.eventsourcing.MemoryTerminationSubscriber;
 import org.apache.james.task.eventsourcing.TaskExecutionDetailsProjection;
 import org.apache.james.task.eventsourcing.TerminationSubscriber;
 import org.apache.james.task.eventsourcing.WorkQueueSupplier;
 import org.apache.james.task.eventsourcing.cassandra.CassandraTaskExecutionDetailsProjection;
+import org.apache.james.task.eventsourcing.distributed.RabbitMQTerminationSubscriber;
 import org.apache.james.task.eventsourcing.distributed.RabbitMQWorkQueueSupplier;
 
 import com.google.inject.AbstractModule;
@@ -43,7 +43,7 @@ public class DistributedTaskManagerModule extends AbstractModule {
         bind(WorkQueueSupplier.class).in(Scopes.SINGLETON);
         bind(TaskExecutionDetailsProjection.class).to(CassandraTaskExecutionDetailsProjection.class);
         bind(TerminationSubscriber.class).in(Scopes.SINGLETON);
-        bind(TerminationSubscriber.class).toInstance(new MemoryTerminationSubscriber());
+        bind(TerminationSubscriber.class).to(RabbitMQTerminationSubscriber.class);
         bind(TaskManager.class).to(EventSourcingTaskManager.class);
         bind(WorkQueueSupplier.class).to(RabbitMQWorkQueueSupplier.class);
     }
diff --git a/server/task-distributed/src/main/java/org/apache/james/task/eventsourcing/distributed/RabbitMQTerminationSubscriber.java b/server/task-distributed/src/main/java/org/apache/james/task/eventsourcing/distributed/RabbitMQTerminationSubscriber.java
new file mode 100644
index 0000000..a3a8bb1
--- /dev/null
+++ b/server/task-distributed/src/main/java/org/apache/james/task/eventsourcing/distributed/RabbitMQTerminationSubscriber.java
@@ -0,0 +1,146 @@
+/**
+ * *************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0                   *
+ * *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ***************************************************************/
+
+package org.apache.james.task.eventsourcing.distributed;
+
+import java.io.Closeable;
+import java.nio.charset.StandardCharsets;
+import java.util.Optional;
+import java.util.UUID;
+
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+
+import org.apache.james.backend.rabbitmq.ReactorRabbitMQChannelPool;
+import org.apache.james.backend.rabbitmq.SimpleConnectionPool;
+import org.apache.james.eventsourcing.Event;
+import org.apache.james.eventsourcing.eventstore.cassandra.JsonEventSerializer;
+import org.apache.james.lifecycle.api.Startable;
+import org.apache.james.task.eventsourcing.TerminationSubscriber;
+import org.reactivestreams.Publisher;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.github.fge.lambdas.Throwing;
+import com.rabbitmq.client.AMQP;
+import com.rabbitmq.client.Connection;
+import com.rabbitmq.client.Delivery;
+import reactor.core.Disposable;
+import reactor.core.publisher.DirectProcessor;
+import reactor.core.publisher.Mono;
+import reactor.core.publisher.UnicastProcessor;
+import reactor.core.scheduler.Schedulers;
+import reactor.rabbitmq.BindingSpecification;
+import reactor.rabbitmq.ExchangeSpecification;
+import reactor.rabbitmq.OutboundMessage;
+import reactor.rabbitmq.QueueSpecification;
+import reactor.rabbitmq.RabbitFlux;
+import reactor.rabbitmq.Receiver;
+import reactor.rabbitmq.ReceiverOptions;
+import reactor.rabbitmq.Sender;
+import reactor.rabbitmq.SenderOptions;
+
+public class RabbitMQTerminationSubscriber implements TerminationSubscriber, Startable, Closeable {
+    private static final Logger LOGGER = LoggerFactory.getLogger(RabbitMQTerminationSubscriber.class);
+    private static final Integer MAX_CHANNELS_NUMBER = 1;
+    private static final String EXCHANGE_NAME = "terminationSubscriberExchange";
+    private static final String QUEUE_NAME_PREFIX = "terminationSubscriber";
+    private static final String ROUTING_KEY = "terminationSubscriberRoutingKey";
+
+    private final JsonEventSerializer serializer;
+    private final Mono<Connection> connectionMono;
+    private final ReactorRabbitMQChannelPool channelPool;
+    private final String queueName;
+    private UnicastProcessor<OutboundMessage> sendQueue;
+    private DirectProcessor<Event> listener;
+    private Disposable sendQueueHandle;
+    private Disposable listenQueueHandle;
+
+    @Inject
+    public RabbitMQTerminationSubscriber(SimpleConnectionPool simpleConnectionPool, JsonEventSerializer serializer) {
+        this.serializer = serializer;
+        this.connectionMono = simpleConnectionPool.getResilientConnection();
+        this.channelPool = new ReactorRabbitMQChannelPool(connectionMono, MAX_CHANNELS_NUMBER);
+        this.queueName = QUEUE_NAME_PREFIX + UUID.randomUUID().toString();
+    }
+
+    public void start() {
+        Sender sender = RabbitFlux.createSender(new SenderOptions()
+            .connectionMono(connectionMono)
+            .channelPool(channelPool)
+            .resourceManagementChannelMono(
+                connectionMono.map(Throwing.function(Connection::createChannel)).cache()));
+
+        sender.declareExchange(ExchangeSpecification.exchange(EXCHANGE_NAME)).block();
+        sender.declare(QueueSpecification.queue(queueName).durable(false).autoDelete(true)).block();
+        sender.bind(BindingSpecification.binding(EXCHANGE_NAME, ROUTING_KEY, queueName)).block();
+        sendQueue = UnicastProcessor.create();
+        sendQueueHandle = sender
+            .send(sendQueue)
+            .subscribeOn(Schedulers.elastic())
+            .subscribe();
+
+        Receiver receiver = RabbitFlux.createReceiver(new ReceiverOptions().connectionMono(connectionMono));
+        listener = DirectProcessor.create();
+        listenQueueHandle = receiver
+            .consumeAutoAck(queueName)
+            .subscribeOn(Schedulers.elastic())
+            .concatMap(this::toEvent)
+            .subscribe(listener::onNext);
+    }
+
+    @Override
+    public void addEvent(Event event) {
+        try {
+            byte[] payload = serializer.serialize(event).getBytes(StandardCharsets.UTF_8);
+            AMQP.BasicProperties basicProperties = new AMQP.BasicProperties.Builder().build();
+            OutboundMessage message = new OutboundMessage(EXCHANGE_NAME, ROUTING_KEY, basicProperties, payload);
+            sendQueue.onNext(message);
+        } catch (JsonProcessingException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    @Override
+    public Publisher<Event> listenEvents() {
+        return listener
+            .share();
+    }
+
+    private Mono<Event> toEvent(Delivery delivery) {
+        String message = new String(delivery.getBody(), StandardCharsets.UTF_8);
+        try {
+            Event event = serializer.deserialize(message);
+            return Mono.just(event);
+        } catch (Exception e) {
+            LOGGER.error("Unable to deserialize '{}'", message, e);
+            return Mono.empty();
+        }
+    }
+
+    @Override
+    @PreDestroy
+    public void close() {
+        Optional.ofNullable(sendQueueHandle).ifPresent(Disposable::dispose);
+        Optional.ofNullable(listenQueueHandle).ifPresent(Disposable::dispose);
+        channelPool.close();
+    }
+}
diff --git a/server/task-distributed/src/test/java/org/apache/james/task/eventsourcing/distributed/DistributedTaskManagerTest.java b/server/task-distributed/src/test/java/org/apache/james/task/eventsourcing/distributed/DistributedTaskManagerTest.java
index ced6652..5db982d 100644
--- a/server/task-distributed/src/test/java/org/apache/james/task/eventsourcing/distributed/DistributedTaskManagerTest.java
+++ b/server/task-distributed/src/test/java/org/apache/james/task/eventsourcing/distributed/DistributedTaskManagerTest.java
@@ -34,6 +34,7 @@ import org.apache.james.backends.cassandra.versions.CassandraSchemaVersionModule
 import org.apache.james.eventsourcing.eventstore.EventStore;
 import org.apache.james.eventsourcing.eventstore.cassandra.CassandraEventStoreExtension;
 import org.apache.james.eventsourcing.eventstore.cassandra.CassandraEventStoreModule;
+import org.apache.james.eventsourcing.eventstore.cassandra.JsonEventSerializer;
 import org.apache.james.eventsourcing.eventstore.cassandra.dto.EventDTOModule;
 import org.apache.james.server.task.json.JsonTaskSerializer;
 import org.apache.james.server.task.json.dto.MemoryReferenceTaskStore;
@@ -48,7 +49,6 @@ import org.apache.james.task.TaskManager;
 import org.apache.james.task.TaskManagerContract;
 import org.apache.james.task.eventsourcing.EventSourcingTaskManager;
 import org.apache.james.task.eventsourcing.Hostname;
-import org.apache.james.task.eventsourcing.MemoryTerminationSubscriber;
 import org.apache.james.task.eventsourcing.TaskExecutionDetailsProjection;
 import org.apache.james.task.eventsourcing.WorkQueueSupplier;
 import org.apache.james.task.eventsourcing.cassandra.CassandraTaskExecutionDetailsProjection;
@@ -76,6 +76,7 @@ class DistributedTaskManagerTest implements TaskManagerContract {
     private static final Hostname HOSTNAME = new Hostname("foo");
     private static final Hostname HOSTNAME_2 = new Hostname("bar");
     private static final Set<EventDTOModule> MODULES = TasksSerializationModule.MODULES.apply(TASK_SERIALIZER).stream().collect(Guavate.toImmutableSet());
+    private static final JsonEventSerializer EVENT_SERIALIZER = new JsonEventSerializer(MODULES);
 
     static CassandraClusterExtension cassandraCluster = new CassandraClusterExtension(
         CassandraModule.aggregateModules(
@@ -104,17 +105,19 @@ class DistributedTaskManagerTest implements TaskManagerContract {
     }
 
     public EventSourcingTaskManager taskManager() {
-        return new EventSourcingTaskManager(workQueueSupplier, eventStore, executionDetailsProjection, HOSTNAME);
+        return taskManager(HOSTNAME);
     }
 
     private EventSourcingTaskManager taskManager(Hostname hostname) {
-        return new EventSourcingTaskManager(workQueueSupplier, eventStore, executionDetailsProjection, hostname, new MemoryTerminationSubscriber());
+        RabbitMQTerminationSubscriber terminationSubscriber = new RabbitMQTerminationSubscriber(rabbitMQExtension.getRabbitConnectionPool(), EVENT_SERIALIZER);
+        terminationSubscriber.start();
+        return new EventSourcingTaskManager(workQueueSupplier, eventStore, executionDetailsProjection, hostname, terminationSubscriber);
     }
 
     @Test
     void givenOneEventStoreTwoEventTaskManagersShareTheSameEvents() {
         try (EventSourcingTaskManager taskManager1 = taskManager();
-             EventSourcingTaskManager taskManager2 = new EventSourcingTaskManager(workQueueSupplier, eventStore, executionDetailsProjection, HOSTNAME_2)) {
+             EventSourcingTaskManager taskManager2 = taskManager(HOSTNAME_2)) {
             TaskId taskId = taskManager1.submit(new CompletedTask());
             Awaitility.await()
                 .atMost(Duration.FIVE_SECONDS)
@@ -142,7 +145,7 @@ class DistributedTaskManagerTest implements TaskManagerContract {
         CountDownLatch waitingForFirstTaskLatch = new CountDownLatch(1);
 
         try (EventSourcingTaskManager taskManager1 = taskManager();
-             EventSourcingTaskManager taskManager2 = new EventSourcingTaskManager(workQueueSupplier, eventStore, executionDetailsProjection, HOSTNAME_2)) {
+             EventSourcingTaskManager taskManager2 = taskManager(HOSTNAME_2)) {
 
             taskManager1.submit(new MemoryReferenceTask(() -> {
                 waitingForFirstTaskLatch.await();
@@ -164,7 +167,7 @@ class DistributedTaskManagerTest implements TaskManagerContract {
     void givenTwoTaskManagerATaskSubmittedOnOneCouldBeRunOnTheOther() throws InterruptedException {
         try (EventSourcingTaskManager taskManager1 = taskManager()) {
             Thread.sleep(100);
-            try (EventSourcingTaskManager taskManager2 = new EventSourcingTaskManager(workQueueSupplier, eventStore, executionDetailsProjection, HOSTNAME_2)) {
+            try (EventSourcingTaskManager taskManager2 = taskManager(HOSTNAME_2)) {
 
                 TaskId taskId = taskManager2.submit(new CompletedTask());
 
diff --git a/server/task-distributed/src/test/java/org/apache/james/task/eventsourcing/distributed/RabbitMQTerminationSubscriberTest.java b/server/task-distributed/src/test/java/org/apache/james/task/eventsourcing/distributed/RabbitMQTerminationSubscriberTest.java
new file mode 100644
index 0000000..fe8690d
--- /dev/null
+++ b/server/task-distributed/src/test/java/org/apache/james/task/eventsourcing/distributed/RabbitMQTerminationSubscriberTest.java
@@ -0,0 +1,73 @@
+/**
+ * *************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0                   *
+ * *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ***************************************************************/
+
+package org.apache.james.task.eventsourcing.distributed;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.List;
+import java.util.Set;
+
+import org.apache.james.backend.rabbitmq.RabbitMQExtension;
+import org.apache.james.eventsourcing.Event;
+import org.apache.james.eventsourcing.eventstore.cassandra.JsonEventSerializer;
+import org.apache.james.eventsourcing.eventstore.cassandra.dto.EventDTOModule;
+import org.apache.james.server.task.json.JsonTaskSerializer;
+import org.apache.james.task.eventsourcing.TerminationSubscriber;
+import org.apache.james.task.eventsourcing.TerminationSubscriberContract;
+
+import com.github.steveash.guavate.Guavate;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import reactor.core.publisher.Flux;
+import reactor.core.scheduler.Schedulers;
+
+class RabbitMQTerminationSubscriberTest implements TerminationSubscriberContract {
+    private static final JsonTaskSerializer TASK_SERIALIZER = new JsonTaskSerializer();
+    private static final Set<EventDTOModule> MODULES = TasksSerializationModule.MODULES.apply(TASK_SERIALIZER).stream().collect(Guavate.toImmutableSet());
+    private static final JsonEventSerializer SERIALIZER = new JsonEventSerializer(MODULES);
+
+    @RegisterExtension
+    static RabbitMQExtension rabbitMQExtension = RabbitMQExtension.singletonRabbitMQ();
+
+    @Override
+    public TerminationSubscriber subscriber() {
+        RabbitMQTerminationSubscriber subscriber = new RabbitMQTerminationSubscriber(rabbitMQExtension.getRabbitConnectionPool(), SERIALIZER);
+        subscriber.start();
+        return subscriber;
+    }
+
+    @Test
+    void givenTwoTerminationSubscribersWhenAnEventIsSentItShouldBeReceivedByBoth() {
+        TerminationSubscriber subscriber1 = subscriber();
+        TerminationSubscriber subscriber2 = subscriber();
+
+        sendEvents(subscriber1, COMPLETED_EVENT);
+
+        List<List<Event>> listenedEvents = Flux.just(subscriber1, subscriber2)
+            .subscribeOn(Schedulers.elastic())
+            .flatMap(this::collectEvents)
+            .collectList()
+            .block();
+        assertThat(listenedEvents).hasSize(2);
+        assertThat(listenedEvents.get(0)).containsExactly(COMPLETED_EVENT);
+        assertThat(listenedEvents.get(1)).containsExactly(COMPLETED_EVENT);
+    }
+}
\ No newline at end of file


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


[james-project] 03/03: JAMES-2813 Introduce ReactorRabbitMQChannelPool.createSender

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 0b7669b9b85eb2bcf81c0963410555979c091d47
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Wed Aug 28 10:00:25 2019 +0200

    JAMES-2813 Introduce ReactorRabbitMQChannelPool.createSender
---
 .../backend/rabbitmq/ReactorRabbitMQChannelPool.java      | 15 +++++++++++++++
 .../org/apache/james/mailbox/events/RabbitMQEventBus.java | 11 ++---------
 .../distributed/RabbitMQTerminationSubscriber.java        |  8 +-------
 .../task/eventsourcing/distributed/RabbitMQWorkQueue.java |  9 +--------
 4 files changed, 19 insertions(+), 24 deletions(-)

diff --git a/backends-common/rabbitmq/src/main/java/org/apache/james/backend/rabbitmq/ReactorRabbitMQChannelPool.java b/backends-common/rabbitmq/src/main/java/org/apache/james/backend/rabbitmq/ReactorRabbitMQChannelPool.java
index f05a307..814e70a 100644
--- a/backends-common/rabbitmq/src/main/java/org/apache/james/backend/rabbitmq/ReactorRabbitMQChannelPool.java
+++ b/backends-common/rabbitmq/src/main/java/org/apache/james/backend/rabbitmq/ReactorRabbitMQChannelPool.java
@@ -29,9 +29,11 @@ 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.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.github.fge.lambdas.Throwing;
 import com.rabbitmq.client.Channel;
 import com.rabbitmq.client.Connection;
 
@@ -39,6 +41,9 @@ import reactor.core.publisher.Mono;
 import reactor.core.publisher.SignalType;
 import reactor.core.scheduler.Schedulers;
 import reactor.rabbitmq.ChannelPool;
+import reactor.rabbitmq.RabbitFlux;
+import reactor.rabbitmq.Sender;
+import reactor.rabbitmq.SenderOptions;
 
 public class ReactorRabbitMQChannelPool implements ChannelPool {
 
@@ -87,10 +92,12 @@ public class ReactorRabbitMQChannelPool implements ChannelPool {
 
     private static final long MAXIMUM_BORROW_TIMEOUT_IN_MS = Duration.ofSeconds(5).toMillis();
 
+    private final Mono<Connection> connectionMono;
     private final GenericObjectPool<Channel> pool;
     private final ConcurrentSkipListSet<Channel> borrowedChannels;
 
     public ReactorRabbitMQChannelPool(Mono<Connection> connectionMono, int poolSize) {
+        this.connectionMono = connectionMono;
         ChannelFactory channelFactory = new ChannelFactory(connectionMono);
 
         GenericObjectPoolConfig<Channel> config = new GenericObjectPoolConfig<>();
@@ -120,6 +127,14 @@ public class ReactorRabbitMQChannelPool implements ChannelPool {
         };
     }
 
+    public Sender createSender() {
+       return RabbitFlux.createSender(new SenderOptions()
+           .connectionMono(connectionMono)
+           .channelPool(this)
+           .resourceManagementChannelMono(
+               connectionMono.map(Throwing.function(Connection::createChannel)).cache()));
+    }
+
     private void invalidateObject(Channel channel) {
         try {
             pool.invalidateObject(channel);
diff --git a/mailbox/event/event-rabbitmq/src/main/java/org/apache/james/mailbox/events/RabbitMQEventBus.java b/mailbox/event/event-rabbitmq/src/main/java/org/apache/james/mailbox/events/RabbitMQEventBus.java
index bd53e93..36795c6 100644
--- a/mailbox/event/event-rabbitmq/src/main/java/org/apache/james/mailbox/events/RabbitMQEventBus.java
+++ b/mailbox/event/event-rabbitmq/src/main/java/org/apache/james/mailbox/events/RabbitMQEventBus.java
@@ -30,16 +30,10 @@ import org.apache.james.event.json.EventSerializer;
 import org.apache.james.lifecycle.api.Startable;
 import org.apache.james.metrics.api.MetricFactory;
 
-import com.github.fge.lambdas.Throwing;
 import com.google.common.base.Preconditions;
-import com.rabbitmq.client.Channel;
 import com.rabbitmq.client.Connection;
-
 import reactor.core.publisher.Mono;
-import reactor.rabbitmq.ChannelPool;
-import reactor.rabbitmq.RabbitFlux;
 import reactor.rabbitmq.Sender;
-import reactor.rabbitmq.SenderOptions;
 
 public class RabbitMQEventBus implements EventBus, Startable {
     private static final int MAX_CHANNELS_NUMBER = 5;
@@ -58,7 +52,7 @@ public class RabbitMQEventBus implements EventBus, Startable {
 
     private volatile boolean isRunning;
     private volatile boolean isStopping;
-    private ChannelPool channelPool;
+    private ReactorRabbitMQChannelPool channelPool;
     private GroupRegistrationHandler groupRegistrationHandler;
     private KeyRegistrationHandler keyRegistrationHandler;
     EventDispatcher eventDispatcher;
@@ -84,8 +78,7 @@ public class RabbitMQEventBus implements EventBus, Startable {
         if (!isRunning && !isStopping) {
             this.channelPool = new ReactorRabbitMQChannelPool(connectionMono, MAX_CHANNELS_NUMBER);
 
-            sender = RabbitFlux.createSender(new SenderOptions().connectionMono(connectionMono).channelPool(channelPool)
-                .resourceManagementChannelMono(connectionMono.map(Throwing.<Connection, Channel>function(Connection::createChannel).sneakyThrow()).cache()));
+            sender = channelPool.createSender();
             LocalListenerRegistry localListenerRegistry = new LocalListenerRegistry();
             keyRegistrationHandler = new KeyRegistrationHandler(eventBusId, eventSerializer, sender, connectionMono, routingKeyConverter, localListenerRegistry, mailboxListenerExecutor);
             groupRegistrationHandler = new GroupRegistrationHandler(eventSerializer, sender, connectionMono, retryBackoff, eventDeadLetters, mailboxListenerExecutor);
diff --git a/server/task-distributed/src/main/java/org/apache/james/task/eventsourcing/distributed/RabbitMQTerminationSubscriber.java b/server/task-distributed/src/main/java/org/apache/james/task/eventsourcing/distributed/RabbitMQTerminationSubscriber.java
index a3a8bb1..89d6e96 100644
--- a/server/task-distributed/src/main/java/org/apache/james/task/eventsourcing/distributed/RabbitMQTerminationSubscriber.java
+++ b/server/task-distributed/src/main/java/org/apache/james/task/eventsourcing/distributed/RabbitMQTerminationSubscriber.java
@@ -39,7 +39,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
-import com.github.fge.lambdas.Throwing;
 import com.rabbitmq.client.AMQP;
 import com.rabbitmq.client.Connection;
 import com.rabbitmq.client.Delivery;
@@ -56,7 +55,6 @@ import reactor.rabbitmq.RabbitFlux;
 import reactor.rabbitmq.Receiver;
 import reactor.rabbitmq.ReceiverOptions;
 import reactor.rabbitmq.Sender;
-import reactor.rabbitmq.SenderOptions;
 
 public class RabbitMQTerminationSubscriber implements TerminationSubscriber, Startable, Closeable {
     private static final Logger LOGGER = LoggerFactory.getLogger(RabbitMQTerminationSubscriber.class);
@@ -83,11 +81,7 @@ public class RabbitMQTerminationSubscriber implements TerminationSubscriber, Sta
     }
 
     public void start() {
-        Sender sender = RabbitFlux.createSender(new SenderOptions()
-            .connectionMono(connectionMono)
-            .channelPool(channelPool)
-            .resourceManagementChannelMono(
-                connectionMono.map(Throwing.function(Connection::createChannel)).cache()));
+        Sender sender = channelPool.createSender();
 
         sender.declareExchange(ExchangeSpecification.exchange(EXCHANGE_NAME)).block();
         sender.declare(QueueSpecification.queue(queueName).durable(false).autoDelete(true)).block();
diff --git a/server/task-distributed/src/main/java/org/apache/james/task/eventsourcing/distributed/RabbitMQWorkQueue.java b/server/task-distributed/src/main/java/org/apache/james/task/eventsourcing/distributed/RabbitMQWorkQueue.java
index 69cdf16..e954c31 100644
--- a/server/task-distributed/src/main/java/org/apache/james/task/eventsourcing/distributed/RabbitMQWorkQueue.java
+++ b/server/task-distributed/src/main/java/org/apache/james/task/eventsourcing/distributed/RabbitMQWorkQueue.java
@@ -39,7 +39,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
-import com.github.fge.lambdas.Throwing;
 import com.google.common.collect.ImmutableMap;
 import com.rabbitmq.client.AMQP;
 import com.rabbitmq.client.Connection;
@@ -51,10 +50,8 @@ import reactor.rabbitmq.ConsumeOptions;
 import reactor.rabbitmq.ExchangeSpecification;
 import reactor.rabbitmq.OutboundMessage;
 import reactor.rabbitmq.QueueSpecification;
-import reactor.rabbitmq.RabbitFlux;
 import reactor.rabbitmq.ReceiverOptions;
 import reactor.rabbitmq.Sender;
-import reactor.rabbitmq.SenderOptions;
 
 public class RabbitMQWorkQueue implements WorkQueue, Startable {
     private static final Logger LOGGER = LoggerFactory.getLogger(RabbitMQWorkQueue.class);
@@ -80,11 +77,7 @@ public class RabbitMQWorkQueue implements WorkQueue, Startable {
     }
 
     public void start() {
-        sender = RabbitFlux.createSender(new SenderOptions()
-            .connectionMono(connectionMono)
-            .channelPool(channelPool)
-            .resourceManagementChannelMono(
-                connectionMono.map(Throwing.function(Connection::createChannel)).cache()));
+        sender = channelPool.createSender();
 
         receiver = new RabbitMQExclusiveConsumer(new ReceiverOptions().connectionMono(connectionMono));
 


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