You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2022/02/10 14:36:40 UTC
[james-project] 04/09: JAMES-3683 Document the use of the Redis rate limiter
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 172bf5b4609520bf43ad21d5d69a522200899f6b
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Jan 28 11:50:02 2022 +0700
JAMES-3683 Document the use of the Redis rate limiter
---
server/mailet/rate-limiter-redis/README.adoc | 43 ++++++
.../mailet/rate-limiter-redis/docker-compose.yml | 17 ++
.../rate-limiter-redis/extensions.properties | 1 +
.../mailet/rate-limiter-redis/mailetcontainer.xml | 171 +++++++++++++++++++++
4 files changed, 232 insertions(+)
diff --git a/server/mailet/rate-limiter-redis/README.adoc b/server/mailet/rate-limiter-redis/README.adoc
new file mode 100644
index 0000000..404c455
--- /dev/null
+++ b/server/mailet/rate-limiter-redis/README.adoc
@@ -0,0 +1,43 @@
+= Distributed Rate limiting for Apache James on top of Redis
+
+This package provides distributed rate limiting using Redis as a shared data store.
+
+It reuses work of xref:../rate-limiter/README.adoc[the Rate Limiter extensions] but substitute a Redis implementation
+for the underlying rate limiting.
+
+== Running rate limiting with the memory implementation
+
+- 1. Compile this project.
+- 2. Place the generated "jar with dependencies" in James `extensions-jars` folder.
+- 3. Configure James to use the redis implementation for Rate Limiting by putting the following content within
+`extension.properties`:
+
+----
+guice.extension.module=org.apache.james.rate.limiter.redis.R
+----
+
+- 4. Use the rate limiting mailets within `mailetcontainer.xml`
+
+We provide a sample `docker-compose` demonstrating this setup.
+
+== Additionnal mailet parameters
+
+Mailets need to specify the `redisURL` tag.
+
+This consists in a list of urls to contact the Redis servers.
+
+Specifying a single URL will connect to a single Redis instance.
+
+Specifying a coma delimited list of URLs will connect to Redis as a cluster.
+
+Eg:
+
+```
+<mailet matcher="All" class="PerSenderRateLimit">
+ <redisURL>redis://localhost:6379</redisURL>
+ <keyPrefix>myPrefix</keyPrefix>
+ <duration>1h</duration>
+ <count>10</count>
+</mailet>
+``
+
diff --git a/server/mailet/rate-limiter-redis/docker-compose.yml b/server/mailet/rate-limiter-redis/docker-compose.yml
new file mode 100644
index 0000000..d21bf4c
--- /dev/null
+++ b/server/mailet/rate-limiter-redis/docker-compose.yml
@@ -0,0 +1,17 @@
+version: '3'
+
+services:
+
+ redis:
+ image: redis:6.2.6
+
+ james:
+ image: apache/james:memory-latest
+ depends_on:
+ - redis
+ container_name: james
+ hostname: james.local
+ volumes:
+ - $PWD/target/james-server-rate-limiter-redis-3.7.0-SNAPSHOT-jar-with-dependencies.jar:/root/extensions-jars/james-server-rate-limiter-redis.jar
+ - $PWD/extensions.properties:/root/conf/extensions.properties
+ - $PWD/mailetcontainer.xml:/root/conf/mailetcontainer.xml
diff --git a/server/mailet/rate-limiter-redis/extensions.properties b/server/mailet/rate-limiter-redis/extensions.properties
new file mode 100644
index 0000000..bf6f821
--- /dev/null
+++ b/server/mailet/rate-limiter-redis/extensions.properties
@@ -0,0 +1 @@
+guice.extension.module=org.apache.james.rate.limiter.redis.RedisRateLimiterModule
\ No newline at end of file
diff --git a/server/mailet/rate-limiter-redis/mailetcontainer.xml b/server/mailet/rate-limiter-redis/mailetcontainer.xml
new file mode 100644
index 0000000..1dd804c
--- /dev/null
+++ b/server/mailet/rate-limiter-redis/mailetcontainer.xml
@@ -0,0 +1,171 @@
+<?xml version="1.0"?>
+
+<!--
+ 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.
+ -->
+
+<!-- Read https://james.apache.org/server/config-mailetcontainer.html for further details -->
+
+<mailetcontainer enableJmx="true">
+
+ <context>
+ <!-- When the domain part of the postmaster mailAddress is missing, the default domain is appended.
+ You can configure it to (for example) <postmaster>postmaster@myDomain.com</postmaster> -->
+ <postmaster>postmaster</postmaster>
+ </context>
+
+ <spooler>
+ <threads>20</threads>
+ <errorRepository>memory://var/mail/error/</errorRepository>
+ </spooler>
+
+ <processors>
+ <processor state="root" enableJmx="true">
+ <mailet match="All" class="PostmasterAlias"/>
+ <mailet match="RelayLimit=30" class="Null"/>
+ <mailet match="All" class="ToProcessor">
+ <processor>transport</processor>
+ </mailet>
+ </processor>
+
+ <processor state="error" enableJmx="true">
+ <mailet match="All" class="MetricsMailet">
+ <metricName>mailetContainerErrors</metricName>
+ </mailet>
+ <mailet match="All" class="Bounce">
+ <onMailetException>ignore</onMailetException>
+ </mailet>
+ <mailet match="All" class="ToRepository">
+ <repositoryPath>memory://var/mail/error/</repositoryPath>
+ <onMailetException>propagate</onMailetException>
+ </mailet>
+ </processor>
+
+ <processor state="transport" enableJmx="true">
+ <matcher name="relay-allowed" match="org.apache.james.mailetcontainer.impl.matchers.Or">
+ <matcher match="SMTPAuthSuccessful"/>
+ <matcher match="SMTPIsAuthNetwork"/>
+ <matcher match="SentByMailet"/>
+ <matcher match="org.apache.james.jmap.mailet.SentByJmap"/>
+ </matcher>
+
+ <mailet match="All" class="RemoveMimeHeader">
+ <name>bcc</name>
+ <onMailetException>ignore</onMailetException>
+ </mailet>
+ <mailet match="All" class="RecipientRewriteTable">
+ <errorProcessor>rrt-error</errorProcessor>
+ </mailet>
+ <mailet match="RecipientIsLocal" class="ToProcessor">
+ <processor>local-delivery</processor>
+ </mailet>
+ <mailet match="HostIsLocal" class="ToProcessor">
+ <processor>local-address-error</processor>
+ <notice>550 - Requested action not taken: no such user here</notice>
+ </mailet>
+ <mailet match="relay-allowed" class="ToProcessor">
+ <processor>relay</processor>
+ </mailet>
+ <mailet match="All" class="ToProcessor">
+ <processor>relay-denied</processor>
+ </mailet>
+ </processor>
+
+ <processor state="local-delivery" enableJmx="true">
+ <mailet match="All" class="VacationMailet">
+ <onMailetException>ignore</onMailetException>
+ </mailet>
+ <mailet match="All" class="Sieve">
+ <onMailetException>ignore</onMailetException>
+ </mailet>
+ <mailet match="All" class="AddDeliveredToHeader"/>
+ <mailet match="All" class="org.apache.james.jmap.mailet.filter.JMAPFiltering">
+ <onMailetException>ignore</onMailetException>
+ </mailet>
+ <mailet match="All" class="LocalDelivery"/>
+ </processor>
+
+ <processor state="relay" enableJmx="true">
+ <mailet matcher="All" class="PerSenderRateLimit">
+ <redisURL>redis://redis:6379</redisURL>
+ <keyPrefix>myPrefix</keyPrefix>
+ <duration>1h</duration>
+ <count>10</count>
+ <recipients>20</recipients>
+ <size>100M</size>
+ <totalSize>200M</totalSize>
+ </mailet>
+ <mailet match="All" class="RemoteDelivery">
+ <outgoingQueue>outgoing</outgoingQueue>
+ <delayTime>5000, 100000, 500000</delayTime>
+ <maxRetries>3</maxRetries>
+ <maxDnsProblemRetries>0</maxDnsProblemRetries>
+ <deliveryThreads>10</deliveryThreads>
+ <sendpartial>true</sendpartial>
+ <bounceProcessor>bounces</bounceProcessor>
+ </mailet>
+ </processor>
+
+ <processor state="local-address-error" enableJmx="true">
+ <mailet match="All" class="MetricsMailet">
+ <metricName>mailetContainerLocalAddressError</metricName>
+ </mailet>
+ <mailet match="All" class="Bounce">
+ <attachment>none</attachment>
+ </mailet>
+ <mailet match="All" class="ToRepository">
+ <repositoryPath>memory://var/mail/address-error/</repositoryPath>
+ </mailet>
+ </processor>
+
+ <processor state="relay-denied" enableJmx="true">
+ <mailet match="All" class="MetricsMailet">
+ <metricName>mailetContainerRelayDenied</metricName>
+ </mailet>
+ <mailet match="All" class="Bounce">
+ <attachment>none</attachment>
+ </mailet>
+ <mailet match="All" class="ToRepository">
+ <repositoryPath>memory://var/mail/relay-denied/</repositoryPath>
+ <notice>Warning: You are sending an e-mail to a remote server. You must be authenticated to perform such an operation</notice>
+ </mailet>
+ </processor>
+
+ <processor state="bounces" enableJmx="true">
+ <mailet match="All" class="MetricsMailet">
+ <metricName>bounces</metricName>
+ </mailet>
+ <mailet match="All" class="DSNBounce">
+ <passThrough>false</passThrough>
+ </mailet>
+ </processor>
+
+ <processor state="rrt-error" enableJmx="false">
+ <mailet match="All" class="ToRepository">
+ <repositoryPath>memory://var/mail/rrt-error/</repositoryPath>
+ <passThrough>true</passThrough>
+ </mailet>
+ <mailet match="IsSenderInRRTLoop" class="Null"/>
+ <mailet match="All" class="Bounce"/>
+ </processor>
+
+ </processors>
+
+</mailetcontainer>
+
+
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org