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

[james-project] branch 3.8.x updated: JAMES-3934 Allow external scheduling for RabbitMQ mailQueue browse st… (#1682)

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

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


The following commit(s) were added to refs/heads/3.8.x by this push:
     new 30dc0bef95 JAMES-3934 Allow external scheduling for RabbitMQ mailQueue browse st… (#1682)
30dc0bef95 is described below

commit 30dc0bef952869ee7142ed4b17afc9a573054d50
Author: Benoit TELLIER <bt...@linagora.com>
AuthorDate: Fri Aug 18 07:24:51 2023 +0200

    JAMES-3934 Allow external scheduling for RabbitMQ mailQueue browse st… (#1682)
---
 .../docs/modules/ROOT/pages/operate/webadmin.adoc  | 15 ++++
 .../modules/server/BrowseStartTaskModule.java      | 63 +++++++++++++++
 .../server/RabbitMailQueueRoutesModule.java        |  6 +-
 .../queue/rabbitmq/MailQueueViewChoice.java        |  5 +-
 .../RabbitMQWebAdminServerIntegrationTest.java     | 72 +++++++++++++++++
 .../routes/BrowseStartUpdateTaskRegistration.java} | 24 +++---
 .../webadmin/routes/RabbitMQMailQueuesRoutes.java  | 13 +++-
 .../webadmin/service/BrowseStartUpdateTask.java    | 90 ++++++++++++++++++++++
 ...wseStartUpdateTaskAdditionalInformationDTO.java | 71 +++++++++++++++++
 .../webadmin/service/BrowseStartUpdateTaskDTO.java | 61 +++++++++++++++
 .../routes/RabbitMQMailQueuesRoutesTest.java       |  4 +-
 .../cassandra/CassandraMailQueueMailDelete.java    | 10 ++-
 .../view/cassandra/CassandraMailQueueView.java     |  4 +
 src/site/markdown/server/manage-webadmin.md        | 15 ++++
 14 files changed, 432 insertions(+), 21 deletions(-)

diff --git a/server/apps/distributed-app/docs/modules/ROOT/pages/operate/webadmin.adoc b/server/apps/distributed-app/docs/modules/ROOT/pages/operate/webadmin.adoc
index 04c05b3db7..ad2db99f72 100644
--- a/server/apps/distributed-app/docs/modules/ROOT/pages/operate/webadmin.adoc
+++ b/server/apps/distributed-app/docs/modules/ROOT/pages/operate/webadmin.adoc
@@ -3995,6 +3995,21 @@ Response codes:
 The response body contains the id of the republishing task.
 `{      "taskId": "a650a66a-5984-431e-bdad-f1baad885856"  }`
 
+=== Cassandra view of the RabbitMQ mailQueue: browse start update
+
+....
+curl -XPOST 'http://ip:port/mailQueues/{mailQueueName}?action=updateBrowseStart
+....
+
+Will return a task that updates the browse start of the aforementioned mailQueue, regardless of the configuration.
+
+link:#_endpoints_returning_a_task[More details about endpoints returning
+a task].
+
+This is an advanced, potentially expensive operation which requires a good understanding of the RabbitMQMailQueue design
+(https://github.com/apache/james-project/blob/master/src/adr/0031-distributed-mail-queue.md). Especially, care needs to
+be taken to call this at most once per slice (not doing so might be expensive).
+
 == Sending email over webAdmin
 
 ....
diff --git a/server/container/guice/protocols/webadmin-rabbitmq-mailqueue/src/main/java/org/apache/james/modules/server/BrowseStartTaskModule.java b/server/container/guice/protocols/webadmin-rabbitmq-mailqueue/src/main/java/org/apache/james/modules/server/BrowseStartTaskModule.java
new file mode 100644
index 0000000000..60bb0fb882
--- /dev/null
+++ b/server/container/guice/protocols/webadmin-rabbitmq-mailqueue/src/main/java/org/apache/james/modules/server/BrowseStartTaskModule.java
@@ -0,0 +1,63 @@
+/****************************************************************
+ * 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.modules.server;
+
+import org.apache.james.queue.rabbitmq.view.cassandra.CassandraMailQueueView;
+import org.apache.james.server.task.json.dto.AdditionalInformationDTO;
+import org.apache.james.server.task.json.dto.AdditionalInformationDTOModule;
+import org.apache.james.server.task.json.dto.TaskDTO;
+import org.apache.james.server.task.json.dto.TaskDTOModule;
+import org.apache.james.task.Task;
+import org.apache.james.task.TaskExecutionDetails;
+import org.apache.james.webadmin.dto.DTOModuleInjections;
+import org.apache.james.webadmin.routes.BrowseStartUpdateTaskRegistration;
+import org.apache.james.webadmin.service.BrowseStartUpdateTaskAdditionalInformationDTO;
+import org.apache.james.webadmin.service.BrowseStartUpdateTaskDTO;
+import org.apache.james.webadmin.tasks.TaskFromRequestRegistry;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.multibindings.Multibinder;
+import com.google.inject.multibindings.ProvidesIntoSet;
+import com.google.inject.name.Named;
+import com.google.inject.name.Names;
+
+public class BrowseStartTaskModule extends AbstractModule {
+    @Override
+    protected void configure() {
+        Multibinder.newSetBinder(binder(), TaskFromRequestRegistry.TaskRegistration.class, Names.named("RabbitMQMailQueuesRoutes"))
+            .addBinding()
+            .to(BrowseStartUpdateTaskRegistration.class);
+    }
+
+    @ProvidesIntoSet
+    public TaskDTOModule<? extends Task, ? extends TaskDTO> updateBrowseStartTask(CassandraMailQueueView.Factory view) {
+        return BrowseStartUpdateTaskDTO.module(view);
+    }
+
+    @ProvidesIntoSet
+    public AdditionalInformationDTOModule<? extends TaskExecutionDetails.AdditionalInformation, ? extends AdditionalInformationDTO> updateBrowseStartAdditionalInformation() {
+        return BrowseStartUpdateTaskAdditionalInformationDTO.module();
+    }
+
+    @Named(DTOModuleInjections.WEBADMIN_DTO)
+    @ProvidesIntoSet
+    public AdditionalInformationDTOModule<? extends TaskExecutionDetails.AdditionalInformation, ? extends AdditionalInformationDTO> updateBrowseStartAdditionalInformationWebAdmin() {
+        return BrowseStartUpdateTaskAdditionalInformationDTO.module();
+    }
+}
diff --git a/server/container/guice/protocols/webadmin-rabbitmq-mailqueue/src/main/java/org/apache/james/modules/server/RabbitMailQueueRoutesModule.java b/server/container/guice/protocols/webadmin-rabbitmq-mailqueue/src/main/java/org/apache/james/modules/server/RabbitMailQueueRoutesModule.java
index dbffe7697d..32d65e267a 100644
--- a/server/container/guice/protocols/webadmin-rabbitmq-mailqueue/src/main/java/org/apache/james/modules/server/RabbitMailQueueRoutesModule.java
+++ b/server/container/guice/protocols/webadmin-rabbitmq-mailqueue/src/main/java/org/apache/james/modules/server/RabbitMailQueueRoutesModule.java
@@ -21,16 +21,18 @@ package org.apache.james.modules.server;
 
 import org.apache.james.webadmin.Routes;
 import org.apache.james.webadmin.routes.RabbitMQMailQueuesRoutes;
+import org.apache.james.webadmin.tasks.TaskFromRequestRegistry;
 
 import com.google.inject.AbstractModule;
 import com.google.inject.multibindings.Multibinder;
+import com.google.inject.name.Names;
 
 public class RabbitMailQueueRoutesModule extends AbstractModule {
     @Override
     protected void configure() {
         install(new RabbitMailQueueTaskSerializationModule());
 
-        Multibinder<Routes> routesMultibinder = Multibinder.newSetBinder(binder(), Routes.class);
-        routesMultibinder.addBinding().to(RabbitMQMailQueuesRoutes.class);
+        Multibinder.newSetBinder(binder(), Routes.class).addBinding().to(RabbitMQMailQueuesRoutes.class);
+        Multibinder.newSetBinder(binder(), TaskFromRequestRegistry.TaskRegistration.class, Names.named("RabbitMQMailQueuesRoutes"));
     }
 }
diff --git a/server/container/guice/queue/rabbitmq/src/main/java/org/apache/james/modules/queue/rabbitmq/MailQueueViewChoice.java b/server/container/guice/queue/rabbitmq/src/main/java/org/apache/james/modules/queue/rabbitmq/MailQueueViewChoice.java
index ad0260f92d..eb817ad08a 100644
--- a/server/container/guice/queue/rabbitmq/src/main/java/org/apache/james/modules/queue/rabbitmq/MailQueueViewChoice.java
+++ b/server/container/guice/queue/rabbitmq/src/main/java/org/apache/james/modules/queue/rabbitmq/MailQueueViewChoice.java
@@ -26,9 +26,11 @@ import java.io.FileNotFoundException;
 import org.apache.commons.configuration2.Configuration;
 import org.apache.commons.configuration2.ex.ConfigurationException;
 import org.apache.commons.lang3.NotImplementedException;
+import org.apache.james.modules.server.BrowseStartTaskModule;
 import org.apache.james.utils.PropertiesProvider;
 
 import com.google.inject.Module;
+import com.google.inject.util.Modules;
 
 public enum MailQueueViewChoice {
     CASSANDRA,
@@ -38,7 +40,8 @@ public enum MailQueueViewChoice {
         public static Module choose(MailQueueViewChoice choice) {
             switch (choice) {
                 case CASSANDRA:
-                    return new CassandraMailQueueViewModule();
+                    return Modules.combine(new CassandraMailQueueViewModule(),
+                        new BrowseStartTaskModule());
                 case NONE:
                     return new FakeMailQueueViewModule();
                 default:
diff --git a/server/protocols/webadmin-integration-test/distributed-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/rabbitmq/RabbitMQWebAdminServerIntegrationTest.java b/server/protocols/webadmin-integration-test/distributed-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/rabbitmq/RabbitMQWebAdminServerIntegrationTest.java
index 63d1aeeaee..03f904a9d3 100644
--- a/server/protocols/webadmin-integration-test/distributed-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/rabbitmq/RabbitMQWebAdminServerIntegrationTest.java
+++ b/server/protocols/webadmin-integration-test/distributed-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/rabbitmq/RabbitMQWebAdminServerIntegrationTest.java
@@ -24,11 +24,19 @@ import static io.restassured.RestAssured.when;
 import static io.restassured.RestAssured.with;
 import static org.apache.james.webadmin.Constants.JSON_CONTENT_TYPE;
 import static org.apache.james.webadmin.Constants.SEPARATOR;
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.awaitility.Durations.TEN_SECONDS;
 import static org.hamcrest.CoreMatchers.hasItems;
 import static org.hamcrest.Matchers.hasSize;
 import static org.hamcrest.Matchers.is;
 
+import com.datastax.oss.driver.api.core.CqlSession;
+import com.google.inject.AbstractModule;
+import com.google.inject.Inject;
+import com.google.inject.Provides;
+import com.google.inject.Singleton;
+import com.google.inject.multibindings.Multibinder;
+import com.google.inject.name.Names;
 import org.apache.james.CassandraExtension;
 import org.apache.james.CassandraRabbitMQJamesConfiguration;
 import org.apache.james.CassandraRabbitMQJamesServerMain;
@@ -36,11 +44,17 @@ import org.apache.james.DockerOpenSearchExtension;
 import org.apache.james.JamesServerBuilder;
 import org.apache.james.JamesServerExtension;
 import org.apache.james.SearchConfiguration;
+import org.apache.james.backends.cassandra.StatementRecorder;
+import org.apache.james.backends.cassandra.TestingSession;
+import org.apache.james.backends.cassandra.components.CassandraModule;
+import org.apache.james.backends.cassandra.init.SessionWithInitializedTablesFactory;
 import org.apache.james.backends.cassandra.versions.CassandraSchemaVersionManager;
+import org.apache.james.blob.cassandra.cache.CassandraBlobCacheModule;
 import org.apache.james.junit.categories.BasicFeature;
 import org.apache.james.modules.AwsS3BlobStoreExtension;
 import org.apache.james.modules.RabbitMQExtension;
 import org.apache.james.modules.blobstore.BlobStoreConfiguration;
+import org.apache.james.utils.GuiceProbe;
 import org.apache.james.webadmin.integration.WebAdminServerIntegrationTest;
 import org.apache.james.webadmin.routes.AliasRoutes;
 import org.apache.james.webadmin.routes.CassandraMappingsRoutes;
@@ -55,6 +69,40 @@ import io.restassured.http.ContentType;
 
 @Tag(BasicFeature.TAG)
 class RabbitMQWebAdminServerIntegrationTest extends WebAdminServerIntegrationTest {
+    private static class TestingSessionProbe implements GuiceProbe {
+        private final TestingSession testingSession;
+
+        @Inject
+        private TestingSessionProbe(TestingSession testingSession) {
+            this.testingSession = testingSession;
+        }
+
+        public TestingSession getTestingSession() {
+            return testingSession;
+        }
+    }
+
+    private static class TestingSessionModule extends AbstractModule {
+        @Override
+        protected void configure() {
+            Multibinder.newSetBinder(binder(), GuiceProbe.class)
+                .addBinding()
+                .to(TestingSessionProbe.class);
+
+            bind(CqlSession.class)
+                .annotatedWith(Names.named("cache"))
+                .to(TestingSession.class);
+            bind(CqlSession.class)
+                .to(TestingSession.class);
+            Multibinder.newSetBinder(binder(), CassandraModule.class).addBinding().toInstance(CassandraBlobCacheModule.MODULE);
+        }
+
+        @Provides
+        @Singleton
+        TestingSession provideSession(SessionWithInitializedTablesFactory factory) {
+            return new TestingSession(factory.get());
+        }
+    }
 
     @RegisterExtension
     static JamesServerExtension testExtension = new JamesServerBuilder<CassandraRabbitMQJamesConfiguration>(tmpDir ->
@@ -73,6 +121,7 @@ class RabbitMQWebAdminServerIntegrationTest extends WebAdminServerIntegrationTes
         .extension(new AwsS3BlobStoreExtension())
         .extension(new RabbitMQExtension())
         .server(CassandraRabbitMQJamesServerMain::createServer)
+        .overrideServerModule(new TestingSessionModule())
         .build();
 
     private static final String VERSION = "/cassandra/version";
@@ -115,6 +164,29 @@ class RabbitMQWebAdminServerIntegrationTest extends WebAdminServerIntegrationTes
                     .body(is("{\"version\":" + CassandraSchemaVersionManager.MAX_VERSION.getValue() + "}")));
     }
 
+    @Test
+    void shouldUpdateBrowseStart() {
+        StatementRecorder statementRecorder = testExtension.getGuiceJamesServer()
+            .getProbe(TestingSessionProbe.class)
+            .getTestingSession()
+            .recordStatements();
+
+        String taskId = with()
+            .queryParam("action", "updateBrowseStart")
+            .body(String.valueOf(CassandraSchemaVersionManager.MAX_VERSION.getValue()))
+        .post("/mailQueues/root")
+            .jsonPath()
+            .get("taskId");
+
+        with()
+            .get("/tasks/" + taskId + "/await")
+        .then()
+            .body("status", is("completed"));
+
+        assertThat(statementRecorder.listExecutedStatements(StatementRecorder.Selector.preparedStatementStartingWith("SELECT * FROM browsestart")))
+            .isNotEmpty();
+    }
+
     @Test
     void postShouldDoMigrationAndUpdateToTheLatestVersion() {
         String taskId = with().post(UPGRADE_TO_LATEST_VERSION)
diff --git a/server/container/guice/protocols/webadmin-rabbitmq-mailqueue/src/main/java/org/apache/james/modules/server/RabbitMailQueueRoutesModule.java b/server/protocols/webadmin/webadmin-rabbitmq/src/main/java/org/apache/james/webadmin/routes/BrowseStartUpdateTaskRegistration.java
similarity index 57%
copy from server/container/guice/protocols/webadmin-rabbitmq-mailqueue/src/main/java/org/apache/james/modules/server/RabbitMailQueueRoutesModule.java
copy to server/protocols/webadmin/webadmin-rabbitmq/src/main/java/org/apache/james/webadmin/routes/BrowseStartUpdateTaskRegistration.java
index dbffe7697d..cb5984b4b8 100644
--- a/server/container/guice/protocols/webadmin-rabbitmq-mailqueue/src/main/java/org/apache/james/modules/server/RabbitMailQueueRoutesModule.java
+++ b/server/protocols/webadmin/webadmin-rabbitmq/src/main/java/org/apache/james/webadmin/routes/BrowseStartUpdateTaskRegistration.java
@@ -17,20 +17,22 @@
  * under the License.                                           *
  ****************************************************************/
 
-package org.apache.james.modules.server;
+package org.apache.james.webadmin.routes;
 
-import org.apache.james.webadmin.Routes;
-import org.apache.james.webadmin.routes.RabbitMQMailQueuesRoutes;
+import static org.apache.james.webadmin.routes.MailQueueRoutes.MAIL_QUEUE_NAME;
 
-import com.google.inject.AbstractModule;
-import com.google.inject.multibindings.Multibinder;
+import javax.inject.Inject;
 
-public class RabbitMailQueueRoutesModule extends AbstractModule {
-    @Override
-    protected void configure() {
-        install(new RabbitMailQueueTaskSerializationModule());
+import org.apache.james.queue.rabbitmq.MailQueueName;
+import org.apache.james.queue.rabbitmq.view.cassandra.CassandraMailQueueView;
+import org.apache.james.webadmin.service.BrowseStartUpdateTask;
+import org.apache.james.webadmin.tasks.TaskFromRequestRegistry;
+import org.apache.james.webadmin.tasks.TaskRegistrationKey;
 
-        Multibinder<Routes> routesMultibinder = Multibinder.newSetBinder(binder(), Routes.class);
-        routesMultibinder.addBinding().to(RabbitMQMailQueuesRoutes.class);
+public class BrowseStartUpdateTaskRegistration extends TaskFromRequestRegistry.TaskRegistration {
+    @Inject
+    public BrowseStartUpdateTaskRegistration(CassandraMailQueueView.Factory cassandraMailQueueViewFactory) {
+        super(TaskRegistrationKey.of("updateBrowseStart"),
+            request -> new BrowseStartUpdateTask(MailQueueName.fromString(request.params(MAIL_QUEUE_NAME)), cassandraMailQueueViewFactory));
     }
 }
diff --git a/server/protocols/webadmin/webadmin-rabbitmq/src/main/java/org/apache/james/webadmin/routes/RabbitMQMailQueuesRoutes.java b/server/protocols/webadmin/webadmin-rabbitmq/src/main/java/org/apache/james/webadmin/routes/RabbitMQMailQueuesRoutes.java
index 4a3802a6e9..9f2574a668 100644
--- a/server/protocols/webadmin/webadmin-rabbitmq/src/main/java/org/apache/james/webadmin/routes/RabbitMQMailQueuesRoutes.java
+++ b/server/protocols/webadmin/webadmin-rabbitmq/src/main/java/org/apache/james/webadmin/routes/RabbitMQMailQueuesRoutes.java
@@ -22,6 +22,7 @@ package org.apache.james.webadmin.routes;
 import static org.apache.james.webadmin.Constants.SEPARATOR;
 import static org.apache.james.webadmin.routes.MailQueueRoutes.BASE_URL;
 import static org.apache.james.webadmin.routes.MailQueueRoutes.MAIL_QUEUE_NAME;
+import static org.apache.james.webadmin.tasks.TaskFromRequestRegistry.builder;
 
 import java.time.Clock;
 import java.time.Duration;
@@ -29,9 +30,11 @@ import java.time.Instant;
 import java.time.temporal.ChronoUnit;
 import java.util.NoSuchElementException;
 import java.util.Optional;
+import java.util.Set;
 import java.util.function.Predicate;
 
 import javax.inject.Inject;
+import javax.inject.Named;
 
 import org.apache.james.queue.api.MailQueueFactory;
 import org.apache.james.queue.api.MailQueueName;
@@ -42,7 +45,7 @@ import org.apache.james.util.DurationParser;
 import org.apache.james.webadmin.Routes;
 import org.apache.james.webadmin.service.ClearMailQueueTask;
 import org.apache.james.webadmin.service.RepublishNotprocessedMailsTask;
-import org.apache.james.webadmin.tasks.TaskFromRequestRegistry;
+import org.apache.james.webadmin.tasks.TaskFromRequestRegistry.TaskRegistration;
 import org.apache.james.webadmin.tasks.TaskRegistrationKey;
 import org.apache.james.webadmin.utils.ErrorResponder;
 import org.apache.james.webadmin.utils.JsonTransformer;
@@ -61,16 +64,19 @@ public class RabbitMQMailQueuesRoutes implements Routes {
     private final JsonTransformer jsonTransformer;
     private final TaskManager taskManager;
     private final Clock clock;
+    private final Set<TaskRegistration> extraTasks;
 
     @Inject
     @SuppressWarnings("unchecked")
     @VisibleForTesting
     RabbitMQMailQueuesRoutes(MailQueueFactory<RabbitMQMailQueue> mailQueueFactory,
-                             Clock clock, JsonTransformer jsonTransformer, TaskManager taskManager) {
+                             Clock clock, JsonTransformer jsonTransformer, TaskManager taskManager,
+                             @Named("RabbitMQMailQueuesRoutes") Set<TaskRegistration> extraTasks) {
         this.mailQueueFactory = mailQueueFactory;
         this.clock = clock;
         this.jsonTransformer = jsonTransformer;
         this.taskManager = taskManager;
+        this.extraTasks = extraTasks;
     }
 
     @Override
@@ -85,8 +91,9 @@ public class RabbitMQMailQueuesRoutes implements Routes {
 
     public void republishNotProcessedMails(Service service) {
         service.post(BASE_URL + SEPARATOR + MAIL_QUEUE_NAME,
-            TaskFromRequestRegistry.builder()
+            builder()
                 .register(REPUBLISH_NOT_PROCESSED_MAILS_REGISTRATION_KEY, this::republishNotProcessedMails)
+                .registrations(extraTasks)
                 .buildAsRoute(taskManager),
             jsonTransformer);
     }
diff --git a/server/protocols/webadmin/webadmin-rabbitmq/src/main/java/org/apache/james/webadmin/service/BrowseStartUpdateTask.java b/server/protocols/webadmin/webadmin-rabbitmq/src/main/java/org/apache/james/webadmin/service/BrowseStartUpdateTask.java
new file mode 100644
index 0000000000..963fcad849
--- /dev/null
+++ b/server/protocols/webadmin/webadmin-rabbitmq/src/main/java/org/apache/james/webadmin/service/BrowseStartUpdateTask.java
@@ -0,0 +1,90 @@
+/****************************************************************
+ * 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.webadmin.service;
+
+import java.time.Clock;
+import java.time.Instant;
+import java.util.Optional;
+
+import org.apache.james.queue.rabbitmq.MailQueueName;
+import org.apache.james.queue.rabbitmq.view.cassandra.CassandraMailQueueView;
+import org.apache.james.task.Task;
+import org.apache.james.task.TaskExecutionDetails;
+import org.apache.james.task.TaskType;
+
+public class BrowseStartUpdateTask implements Task {
+    public static class AdditionalInformation implements TaskExecutionDetails.AdditionalInformation {
+        private final Instant timestamp;
+        private final MailQueueName mailQueue;
+
+        public AdditionalInformation(MailQueueName mailQueue, Instant timestamp) {
+            this.mailQueue = mailQueue;
+            this.timestamp = timestamp;
+        }
+
+        @Override
+        public Instant timestamp() {
+            return timestamp;
+        }
+
+
+        public MailQueueName getMailQueue() {
+            return mailQueue;
+        }
+
+    }
+
+    public static final TaskType TYPE = TaskType.of("browse-start-update");
+
+    private final MailQueueName name;
+    private final CassandraMailQueueView.Factory cassandraMailQueueView;
+
+    public BrowseStartUpdateTask(MailQueueName name, CassandraMailQueueView.Factory cassandraMailQueueView) {
+        this.name = name;
+        this.cassandraMailQueueView = cassandraMailQueueView;
+    }
+
+    @Override
+    public Result run() {
+        try {
+            CassandraMailQueueView mailQueueView = (CassandraMailQueueView) cassandraMailQueueView.create(name);
+            mailQueueView.updateBrowseStart()
+                .block();
+            return Result.COMPLETED;
+        } catch (Exception e) {
+            LOGGER.error("Error when republishing mails", e);
+            return Result.PARTIAL;
+        }
+    }
+
+    @Override
+    public TaskType type() {
+        return TYPE;
+    }
+
+    @Override
+    public Optional<TaskExecutionDetails.AdditionalInformation> details() {
+        return Optional.of(new AdditionalInformation(name, Clock.systemUTC().instant()));
+    }
+
+    public MailQueueName getMailQueue() {
+        return name;
+    }
+}
diff --git a/server/protocols/webadmin/webadmin-rabbitmq/src/main/java/org/apache/james/webadmin/service/BrowseStartUpdateTaskAdditionalInformationDTO.java b/server/protocols/webadmin/webadmin-rabbitmq/src/main/java/org/apache/james/webadmin/service/BrowseStartUpdateTaskAdditionalInformationDTO.java
new file mode 100644
index 0000000000..3fa8588e46
--- /dev/null
+++ b/server/protocols/webadmin/webadmin-rabbitmq/src/main/java/org/apache/james/webadmin/service/BrowseStartUpdateTaskAdditionalInformationDTO.java
@@ -0,0 +1,71 @@
+/****************************************************************
+ * 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.webadmin.service;
+
+import static org.apache.james.queue.rabbitmq.MailQueueName.fromString;
+
+import java.time.Instant;
+
+import org.apache.james.json.DTOModule;
+import org.apache.james.server.task.json.dto.AdditionalInformationDTO;
+import org.apache.james.server.task.json.dto.AdditionalInformationDTOModule;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class BrowseStartUpdateTaskAdditionalInformationDTO implements AdditionalInformationDTO {
+    public static AdditionalInformationDTOModule<BrowseStartUpdateTask.AdditionalInformation, BrowseStartUpdateTaskAdditionalInformationDTO> module() {
+        return DTOModule.forDomainObject(BrowseStartUpdateTask.AdditionalInformation.class)
+            .convertToDTO(BrowseStartUpdateTaskAdditionalInformationDTO.class)
+            .toDomainObjectConverter(dto -> new BrowseStartUpdateTask.AdditionalInformation(
+                fromString(dto.mailQueue),
+                dto.timestamp))
+            .toDTOConverter((details, type) -> new BrowseStartUpdateTaskAdditionalInformationDTO(
+                type,
+                details.getMailQueue().asString(),
+                details.timestamp()))
+            .typeName(BrowseStartUpdateTask.TYPE.asString())
+            .withFactory(AdditionalInformationDTOModule::new);
+    }
+
+    private final String type;
+    private final String mailQueue;
+    private final Instant timestamp;
+
+    public BrowseStartUpdateTaskAdditionalInformationDTO(@JsonProperty("type") String type,
+                                                         @JsonProperty("mailQueue") String mailQueue,
+                                                         @JsonProperty("timestamp") Instant timestamp) {
+        this.type = type;
+        this.mailQueue = mailQueue;
+        this.timestamp = timestamp;
+    }
+
+    public String getMailQueue() {
+        return mailQueue;
+    }
+
+    @Override
+    public String getType() {
+        return type;
+    }
+
+    @Override
+    public Instant getTimestamp() {
+        return timestamp;
+    }
+}
diff --git a/server/protocols/webadmin/webadmin-rabbitmq/src/main/java/org/apache/james/webadmin/service/BrowseStartUpdateTaskDTO.java b/server/protocols/webadmin/webadmin-rabbitmq/src/main/java/org/apache/james/webadmin/service/BrowseStartUpdateTaskDTO.java
new file mode 100644
index 0000000000..bb3b5614aa
--- /dev/null
+++ b/server/protocols/webadmin/webadmin-rabbitmq/src/main/java/org/apache/james/webadmin/service/BrowseStartUpdateTaskDTO.java
@@ -0,0 +1,61 @@
+/****************************************************************
+ * 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.webadmin.service;
+
+import static org.apache.james.queue.rabbitmq.MailQueueName.fromString;
+
+import org.apache.james.json.DTOModule;
+import org.apache.james.queue.rabbitmq.view.cassandra.CassandraMailQueueView;
+import org.apache.james.server.task.json.dto.TaskDTO;
+import org.apache.james.server.task.json.dto.TaskDTOModule;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class BrowseStartUpdateTaskDTO implements TaskDTO {
+    public static TaskDTOModule<BrowseStartUpdateTask, BrowseStartUpdateTaskDTO> module(CassandraMailQueueView.Factory cassandraMailQueueView) {
+        return DTOModule
+            .forDomainObject(BrowseStartUpdateTask.class)
+            .convertToDTO(BrowseStartUpdateTaskDTO.class)
+            .toDomainObjectConverter(dto -> new BrowseStartUpdateTask(fromString(dto.mailQueue), cassandraMailQueueView))
+            .toDTOConverter(BrowseStartUpdateTaskDTO::toDTO)
+            .typeName(BrowseStartUpdateTask.TYPE.asString())
+            .withFactory(TaskDTOModule::new);
+    }
+
+    public static BrowseStartUpdateTaskDTO toDTO(BrowseStartUpdateTask domainObject, String typeName) {
+        return new BrowseStartUpdateTaskDTO(typeName, domainObject.getMailQueue().asString());
+    }
+
+    private final String type;
+    private final String mailQueue;
+
+    public BrowseStartUpdateTaskDTO(@JsonProperty("type") String type, @JsonProperty("mailQueue") String mailQueue) {
+        this.type = type;
+        this.mailQueue = mailQueue;
+    }
+
+    @Override
+    public String getType() {
+        return type;
+    }
+
+    public String getMailQueue() {
+        return mailQueue;
+    }
+}
diff --git a/server/protocols/webadmin/webadmin-rabbitmq/src/test/java/org/apache/james/webadmin/routes/RabbitMQMailQueuesRoutesTest.java b/server/protocols/webadmin/webadmin-rabbitmq/src/test/java/org/apache/james/webadmin/routes/RabbitMQMailQueuesRoutesTest.java
index 4daaa08227..389fe8653c 100644
--- a/server/protocols/webadmin/webadmin-rabbitmq/src/test/java/org/apache/james/webadmin/routes/RabbitMQMailQueuesRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-rabbitmq/src/test/java/org/apache/james/webadmin/routes/RabbitMQMailQueuesRoutesTest.java
@@ -34,6 +34,7 @@ import java.time.ZoneOffset;
 import java.time.ZonedDateTime;
 import java.util.Optional;
 
+import com.google.common.collect.ImmutableSet;
 import org.apache.james.json.DTOConverter;
 import org.apache.james.queue.api.MailQueueFactory;
 import org.apache.james.queue.rabbitmq.RabbitMQMailQueue;
@@ -67,7 +68,8 @@ class RabbitMQMailQueuesRoutesTest {
         JsonTransformer jsonTransformer = new JsonTransformer();
         clock = UpdatableTickingClock.fixed(DATE.toInstant(), ZoneOffset.UTC);
         return WebAdminUtils.createWebAdminServer(
-                new RabbitMQMailQueuesRoutes(mailQueueFactory, clock, jsonTransformer, taskManager),
+                new RabbitMQMailQueuesRoutes(mailQueueFactory, clock, jsonTransformer, taskManager,
+                    ImmutableSet.of()),
                 new TasksRoutes(taskManager, jsonTransformer, DTOConverter.of()))
             .start();
     }
diff --git a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueMailDelete.java b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueMailDelete.java
index eb105c94e5..4d4cdc818e 100644
--- a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueMailDelete.java
+++ b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueMailDelete.java
@@ -75,13 +75,17 @@ public class CassandraMailQueueMailDelete {
     }
 
     void updateBrowseStart(MailQueueName mailQueueName) {
-        findNewBrowseStart(mailQueueName)
-            .flatMap(newBrowseStart -> updateNewBrowseStart(mailQueueName, newBrowseStart)
-                .then(clearContentBeforeBrowse(mailQueueName, newBrowseStart)))
+        updateBrowseStartReactive(mailQueueName)
             .subscribeOn(Schedulers.parallel())
             .subscribe();
     }
 
+    Mono<Void> updateBrowseStartReactive(MailQueueName mailQueueName) {
+        return findNewBrowseStart(mailQueueName)
+            .flatMap(newBrowseStart -> updateNewBrowseStart(mailQueueName, newBrowseStart)
+                .then(clearContentBeforeBrowse(mailQueueName, newBrowseStart)));
+    }
+
     private void maybeUpdateBrowseStart(MailQueueName mailQueueName) {
         if (shouldUpdateBrowseStart()) {
             updateBrowseStart(mailQueueName);
diff --git a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueView.java b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueView.java
index 94643777b9..98bb470b49 100644
--- a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueView.java
+++ b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueView.java
@@ -86,6 +86,10 @@ public class CassandraMailQueueView implements MailQueueView<CassandraMailQueueB
         this.mimeMessageStore = mimeMessageStore;
     }
 
+    public Mono<Void> updateBrowseStart() {
+        return cassandraMailQueueMailDelete.updateBrowseStartReactive(mailQueueName);
+    }
+
     @Override
     public void initialize(MailQueueName mailQueueName) {
         storeHelper.initializeBrowseStart(mailQueueName).block();
diff --git a/src/site/markdown/server/manage-webadmin.md b/src/site/markdown/server/manage-webadmin.md
index b630db5611..a319c51aa9 100644
--- a/src/site/markdown/server/manage-webadmin.md
+++ b/src/site/markdown/server/manage-webadmin.md
@@ -3391,6 +3391,7 @@ The scheduled task will have the following type `reprocessing-one` and the follo
  - [Clearing a mail queue](#Clearing_a_mail_queue)
  - [Flushing mails from a mail queue](#Flushing_mails_from_a_mail_queue)
  - [RabbitMQ republishing a mail queue from cassandra](#RabbitMQ_republishing_a_mail_queue_from_cassandra)
+ - [Cassandra view of the RabbitMQ mailQueue: browse start update](#Cassandra_view_of_the_rabbitmq_mailqueue_browse_start_update)
 
 ### Listing mail queues
 
@@ -3574,6 +3575,20 @@ Response codes:
  }
  ```
 
+### Cassandra view of the RabbitMQ mailQueue: browse start update
+
+```
+curl -XPOST 'http://ip:port/mailQueues/{mailQueueName}?action=updateBrowseStart
+```
+
+Will return a task that updates the browse start of the aforementioned mailQueue, regardless of the configuration.
+
+[More details about endpoints returning a task](#Endpoints_returning_a_task).
+
+This is an advanced, potentially expensive operation which requires a good understanding of the RabbitMQMailQueue design
+(https://github.com/apache/james-project/blob/master/src/adr/0031-distributed-mail-queue.md). Especially, care needs to
+be taken to call this at most once per slice (not doing so might be expensive).
+
 ## Sending email over webAdmin
 
 ```


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