Arsnael commented on a change in pull request #880:
URL: https://github.com/apache/james-project/pull/880#discussion_r802525644
##########
File path: server/mailet/rate-limiter/README.adoc
##########
@@ -105,4 +105,37 @@ For instance, to apply all the examples given above:
</mailet>
----
-When the rate is exceeded, all mails will be moved to processor *tooMuchMails*
which send a bounce message notifies that user exceeded the rate limit.
\ No newline at end of file
+When the rate is exceeded, all mails will be moved to processor *tooMuchMails*
which send a bounce message notifies that user exceeded the rate limit.
+
+=== Throttling
+
+Can combine RateLimit mailet with `Requeue` mailet, it allows for a (very
basic) throttler: smooth the traffic to the expected rate.
Review comment:
```suggestion
It's possible to combine RateLimit mailet with `Requeue` mailet to allow for
a (very basic) throttler and smoothing the traffic to the expected rate.
```
##########
File path:
server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Requeue.java
##########
@@ -0,0 +1,87 @@
+/****************************************************************
+ * 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.transport.mailets;
+
+import java.time.Duration;
+import java.time.temporal.ChronoUnit;
+import java.util.Optional;
+
+import javax.inject.Inject;
+import javax.mail.MessagingException;
+
+import org.apache.james.lifecycle.api.LifecycleUtil;
+import org.apache.james.queue.api.MailQueue;
+import org.apache.james.queue.api.MailQueueFactory;
+import org.apache.james.queue.api.MailQueueName;
+import org.apache.james.util.DurationParser;
+import org.apache.mailet.Mail;
+import org.apache.mailet.base.GenericMailet;
+
+import com.google.common.base.Preconditions;
+
+public class Requeue extends GenericMailet {
+ private final MailQueueFactory<?> mailQueueFactory;
+
+ private MailQueue mailQueue;
+ private Optional<Duration> delayDuration;
+ private String processor;
+ private String consumeProcessor;
+
+ @Inject
+ public Requeue(MailQueueFactory<?> mailQueueFactory) {
+ this.mailQueueFactory = mailQueueFactory;
+ }
+
+ @Override
+ public void init() throws MessagingException {
+ MailQueueName mailQueueName =
Optional.ofNullable(getInitParameter("queue"))
+ .map(MailQueueName::of).orElse(MailQueueFactory.SPOOL);
+
+ mailQueue = mailQueueFactory.getQueue(mailQueueName)
+ .orElseThrow(() -> new IllegalArgumentException("Can not find
queue " + mailQueueName.asString()));
+ delayDuration = Optional.ofNullable(getInitParameter("delay"))
+ .map(delayValue -> DurationParser.parse(delayValue,
ChronoUnit.SECONDS));
+ processor = Optional.ofNullable(getInitParameter("processor"))
+ .orElse(Mail.DEFAULT);
+ consumeProcessor = Optional.ofNullable(getInitParameter("consume"))
+ .orElse(Mail.GHOST);
Review comment:
If we consume the mail, isn't it always GHOST anyway? why need a param
here? I saw it was one of @chibenwa comment but I'm not sure to get it :)
##########
File path: server/mailet/rate-limiter/README.adoc
##########
@@ -105,4 +105,37 @@ For instance, to apply all the examples given above:
</mailet>
----
-When the rate is exceeded, all mails will be moved to processor *tooMuchMails*
which send a bounce message notifies that user exceeded the rate limit.
\ No newline at end of file
+When the rate is exceeded, all mails will be moved to processor *tooMuchMails*
which send a bounce message notifies that user exceeded the rate limit.
+
+=== Throttling
+
+Can combine RateLimit mailet with `Requeue` mailet, it allows for a (very
basic) throttler: smooth the traffic to the expected rate.
+The throttler work by re-enqueue mail.
+
+Requeue are supported configuration parameters:
Review comment:
```suggestion
The supported configuration parameters for the `Requeue` mailet are:
```
##########
File path:
server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Requeue.java
##########
@@ -36,6 +36,32 @@
import com.google.common.base.Preconditions;
+/**
+ * <p><b>Requeue</b> allows for a throttling when combined with rate limiting
mailet. {@link org.apache.james.transport.mailets.PerSenderRateLimit}</p>
+ *
+ * <ul>Here are supported configuration parameters:
+ * <li><b>queue</b>: a Mail Queue name (optional, default to spool).</li>
+ * <li><b>processor</b>: a target processor (optional, defaults to
root).</li>
+ * <li><b>delay</b>: a delay when en-queueing mail (optional, defaults to
none). Supported units include: s (second), m (minute), h (hour), d (day).</li>
+ * <li><b>consume</b>: a processor to which current email should be
redirected to (optional, defaults to ghost).</li>
+ * </ul>
+ *
+ * <p>For instance, to apply all the examples given above:</p>
+ *
+ * <pre><code>
+ * <mailet matcher="All" class="Requeue">
+ * <queue>spool</queue>
+ * <processor>root</processor>
+ * <delay>2h</delay>
+ * <consume>ghost</consume>
+ * </mailet>
+ * </code></pre>
+ *
+ * <p>Note that this is a naive approach: if you have a large number of emails
(say N) submitted at once,
+ * you would need O(N) re-queues to eventually send all your emails,
+ * where the constant is the number of mail allowed over the time window.
+ * So this gives an overall complexity of O(N2), while careful planning could
achieve this in O(N). </p>
Review comment:
```suggestion
* So this gives an overall complexity of O(N2). </p>
```
Not sure to keep the end in the javadoc... it's saying we are lazy to do
better? Or maybe I misunderstand here
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]