Skip to content

Commit 0a41838

Browse files
committed
Makes policies optional for each route
1 parent 2388f63 commit 0a41838

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,17 @@ There are four built-in rate limit approachs:
77
- Authenticated User and Request Origin: *Combine the authenticated user and the Request Origin*
88
- Global configuration per service: *This one doesn't validate the request Origin or the Authenticated User*
99
- To use this approach just don't set param 'type'
10+
11+
Adding Project Lombok Agent
12+
---
1013

14+
This project uses [Project Lombok](http://projectlombok.org/features/index.html)
15+
to generate getters and setters etc. Compiling from the command line this
16+
shouldn't cause any problems, but in an IDE you need to add an agent
17+
to the JVM. Full instructions can be found in the Lombok website. The
18+
sign that you need to do this is a lot of compiler errors to do with
19+
missing methods and fields.
20+
1121
Usage
1222
---
1323
>This project is available on maven central
@@ -17,7 +27,7 @@ Add the dependency on pom.xml
1727
<dependency>
1828
<groupId>com.marcosbarbero.cloud</groupId>
1929
<artifactId>spring-cloud-zuul-ratelimit</artifactId>
20-
<version>1.0.1.RELEASE</version>
30+
<version>1.0.2.RELEASE</version>
2131
</dependency>
2232
```
2333

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
]]>
1414
</description>
1515
<url>https://github.com/marcosbarbero/spring-cloud-starter-zuul-ratelimit</url>
16-
<version>1.0.1.RELEASE</version>
16+
<version>1.0.2.RELEASE</version>
1717

1818
<licenses>
1919
<license>
@@ -24,7 +24,7 @@
2424
</licenses>
2525

2626
<properties>
27-
<lombok.version>1.16.10</lombok.version>
27+
<lombok.version>1.16.12</lombok.version>
2828
<maven.compiler.target>1.8</maven.compiler.target>
2929
<maven.compiler.source>1.8</maven.compiler.source>
3030
<java.version>1.8</java.version>
@@ -118,7 +118,7 @@
118118
<dependency>
119119
<groupId>org.springframework.cloud</groupId>
120120
<artifactId>spring-cloud-netflix</artifactId>
121-
<version>1.1.5.RELEASE</version>
121+
<version>1.2.3.RELEASE</version>
122122
<type>pom</type>
123123
<scope>import</scope>
124124
</dependency>

src/main/java/com/marcosbarbero/zuul/filters/pre/ratelimit/config/RateLimitAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818
@Configuration
1919
@EnableConfigurationProperties(RateLimitProperties.class)
20-
@ConditionalOnProperty(name = "zuul.ratelimit.enabled", matchIfMissing = false)
20+
@ConditionalOnProperty(name = "zuul.ratelimit.enabled")
2121
public class RateLimitAutoConfiguration {
2222

2323
@Bean

src/main/java/com/marcosbarbero/zuul/filters/pre/ratelimit/config/redis/RedisRateLimiter.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.marcosbarbero.zuul.filters.pre.ratelimit.config.redis;
22

33
import com.marcosbarbero.zuul.filters.pre.ratelimit.config.Policy;
4-
import com.marcosbarbero.zuul.filters.pre.ratelimit.config.RateLimiter;
54
import com.marcosbarbero.zuul.filters.pre.ratelimit.config.Rate;
5+
import com.marcosbarbero.zuul.filters.pre.ratelimit.config.RateLimiter;
66
import org.springframework.dao.DataAccessException;
77
import org.springframework.data.redis.core.RedisOperations;
88
import org.springframework.data.redis.core.RedisTemplate;
@@ -32,9 +32,7 @@ public Rate consume(final Policy policy, final String key) {
3232
public List<Object> execute(RedisOperations ops) throws DataAccessException {
3333
ops.multi();
3434
ops.boundValueOps(tempKey).increment(1L);
35-
if (ops.getExpire(tempKey) == null) {
36-
ops.expire(tempKey, policy.getRefreshInterval(), TimeUnit.SECONDS);
37-
}
35+
ops.expire(tempKey, policy.getRefreshInterval(), TimeUnit.SECONDS);
3836
return ops.exec();
3937
}
4038
});

0 commit comments

Comments
 (0)