diff --git a/build.gradle b/build.gradle
index 7408b2b67f..a38cabdeeb 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,4 +1,4 @@
-buildscript {
+buildscript {
ext.kotlinVersion = '1.3.21'
repositories {
maven { url 'https://repo.spring.io/plugins-release' }
@@ -131,6 +131,7 @@ subprojects { subproject ->
postgresVersion = '42.2.5'
reactorNettyVersion = '0.8.5.RELEASE'
reactorVersion = '3.2.6.RELEASE'
+ resilience4jVersion = '0.13.2'
romeToolsVersion = '1.12.0'
servletApiVersion = '4.0.1'
smackVersion = '4.3.1'
@@ -381,6 +382,7 @@ project('spring-integration-core') {
compile("io.fastjson:boon:$boonVersion", optional)
compile("com.esotericsoftware:kryo-shaded:$kryoShadedVersion", optional)
compile("io.micrometer:micrometer-core:$micrometerVersion", optional)
+ compile("io.github.resilience4j:resilience4j-ratelimiter:$resilience4jVersion", optional)
testCompile ("org.aspectj:aspectjweaver:$aspectjVersion")
testCompile "io.projectreactor:reactor-test:$reactorVersion"
diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/RateLimiterRequestHandlerAdvice.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/RateLimiterRequestHandlerAdvice.java
new file mode 100644
index 0000000000..7270f2a82f
--- /dev/null
+++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/RateLimiterRequestHandlerAdvice.java
@@ -0,0 +1,147 @@
+/*
+ * Copyright 2019 the original author or authors.
+ *
+ * Licensed 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.springframework.integration.handler.advice;
+
+import java.time.Duration;
+
+import org.springframework.messaging.Message;
+import org.springframework.messaging.MessagingException;
+import org.springframework.util.Assert;
+
+import io.github.resilience4j.ratelimiter.RateLimiter;
+import io.github.resilience4j.ratelimiter.RateLimiterConfig;
+import io.github.resilience4j.ratelimiter.RequestNotPermitted;
+import io.vavr.CheckedFunction0;
+import io.vavr.control.Try;
+
+/**
+ * An {@link AbstractRequestHandlerAdvice} extension for a rate limiting to service method calls.
+ * The implementation is based on the
+ * Resilience4j.
+ *
+ * @author Artem Bilan
+ *
+ * @since 5.2
+ */
+public class RateLimiterRequestHandlerAdvice extends AbstractRequestHandlerAdvice {
+
+ public static final String DEFAULT_NAME = "RateLimiterRequestHandlerAdvice";
+
+ private final RateLimiter rateLimiter;
+
+ /**
+ * Construct an instance based on default rate limiter options
+ * and {@value #DEFAULT_NAME} as a rate limiter name.
+ * @see RateLimiter#ofDefaults
+ */
+ public RateLimiterRequestHandlerAdvice() {
+ this(RateLimiter.ofDefaults(DEFAULT_NAME));
+ }
+
+ /**
+ * Construct an instance based on default rate limiter options and provided name.
+ * @param name the name for the rate limiter.
+ */
+ public RateLimiterRequestHandlerAdvice(String name) {
+ this(RateLimiter.ofDefaults(name));
+ Assert.hasText(name, "'name' must not be empty");
+ }
+
+ /**
+ * Construct an instance based on the provided {@link RateLimiter}.
+ * @param rateLimiter the {@link RateLimiter} to use.
+ */
+ public RateLimiterRequestHandlerAdvice(RateLimiter rateLimiter) {
+ Assert.notNull(rateLimiter, "'rateLimiter' must not be null");
+ this.rateLimiter = rateLimiter;
+ }
+
+ /**
+ * Construct an instance based on the provided {@link RateLimiterConfig}
+ * and {@value #DEFAULT_NAME} as a rate limiter name.
+ * @param rateLimiterConfig the {@link RateLimiterConfig} to use.
+ */
+ public RateLimiterRequestHandlerAdvice(RateLimiterConfig rateLimiterConfig) {
+ this(rateLimiterConfig, DEFAULT_NAME);
+ }
+
+ /**
+ * Construct an instance based on the provided {@link RateLimiterConfig} and name.
+ * @param rateLimiterConfig the {@link RateLimiterConfig} to use.
+ * @param name the name for the rate limiter.
+ */
+ public RateLimiterRequestHandlerAdvice(RateLimiterConfig rateLimiterConfig, String name) {
+ Assert.notNull(rateLimiterConfig, "'rateLimiterConfig' must not be null");
+ Assert.hasText(name, "'name' must not be empty");
+ this.rateLimiter = RateLimiter.of(name, rateLimiterConfig);
+ }
+
+ /**
+ * Change the {@code limitForPeriod} option of the {@link #rateLimiter}.
+ * @param limitForPeriod the {@code limitForPeriod} to use.
+ * @see RateLimiter#changeLimitForPeriod(int)
+ */
+ public void setLimitForPeriod(int limitForPeriod) {
+ this.rateLimiter.changeLimitForPeriod(limitForPeriod);
+ }
+
+ /**
+ * Change the {@code timeoutDuration} option of the {@link #rateLimiter}.
+ * @param timeoutDuration the {@code timeoutDuration} to use.
+ * @see RateLimiter#changeTimeoutDuration(Duration)
+ */
+ public void setTimeoutDuration(Duration timeoutDuration) {
+ this.rateLimiter.changeTimeoutDuration(timeoutDuration);
+ }
+
+ /**
+ * Obtain the metrics from the rate limiter.
+ * @return the {@link RateLimiter.Metrics} from rate limiter.
+ * @see RateLimiter#getMetrics()
+ */
+ public RateLimiter.Metrics getMetrics() {
+ return this.rateLimiter.getMetrics();
+ }
+
+ @Override
+ protected Object doInvoke(ExecutionCallback callback, Object target, Message> message) throws Exception {
+ CheckedFunction0