forked from eugenp/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
141 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 44 additions & 3 deletions
47
...c/main/java/com/baeldung/spring/cloud/zuulratelimitdemo/ZuulRatelimitDemoApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,53 @@ | ||
package com.baeldung.spring.cloud.zuulratelimitdemo; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.cloud.netflix.zuul.filters.Route; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
import com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.RateLimitKeyGenerator; | ||
import com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.RateLimitUtils; | ||
import com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.properties.RateLimitProperties; | ||
import com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.repository.RateLimiterErrorHandler; | ||
import com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.repository.DefaultRateLimiterErrorHandler; | ||
import com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.support.DefaultRateLimitKeyGenerator; | ||
|
||
@SpringBootApplication | ||
public class ZuulRatelimitDemoApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(ZuulRatelimitDemoApplication.class, args); | ||
} | ||
public static void main(String[] args) { | ||
SpringApplication.run(ZuulRatelimitDemoApplication.class, args); | ||
} | ||
|
||
@Bean | ||
public RateLimitKeyGenerator ratelimitKeyGenerator(RateLimitProperties properties, RateLimitUtils rateLimitUtils) { | ||
return new DefaultRateLimitKeyGenerator(properties, rateLimitUtils) { | ||
@Override | ||
public String key(HttpServletRequest request, Route route, RateLimitProperties.Policy policy) { | ||
return super.key(request, route, policy) + ":" + request.getMethod(); | ||
} | ||
}; | ||
} | ||
|
||
@Bean | ||
public RateLimiterErrorHandler rateLimitErrorHandler() { | ||
return new DefaultRateLimiterErrorHandler() { | ||
@Override | ||
public void handleSaveError(String key, Exception e) { | ||
// custom code | ||
} | ||
|
||
@Override | ||
public void handleFetchError(String key, Exception e) { | ||
// custom code | ||
} | ||
|
||
@Override | ||
public void handleError(String msg, Exception e) { | ||
// custom code | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters