A Spring Boot component that provides request path-based rate limiting, proxying, parameter modification, and request body modification within applications.
- Rate Limiting
- Multiple rate limiting algorithms support:
- Google Guava Token Bucket Algorithm
- Redisson Distributed Rate Limiting
- Multiple Redis deployment modes support:
- Single Node Redis
- Redis Cluster Mode
- Redis Sentinel Mode
- Multiple Redis deployment modes support:
- Multiple rate limiting algorithms support:
- Proxy
- Supports weight configuration
- SpEL Expression Parameter Modification
- SpEL Expression Request Body Modification
- Dynamic rate limiting and proxy configuration route modification
- Real-time monitoring dashboard
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories><dependency>
<groupId>com.gitee.wb04307201.smart-router</groupId>
<artifactId>smart-router-spring-boot-starter</artifactId>
<version>1.0.6</version>
</dependency>smart-router:
rateLimiter:
rateLimitingType: standalone # Rate limiting type: standalone, redis, redis-cluster, redis-sentinel
rateLimitRules: # Rate limiting rules list
- endpoint: /test/hello # Rate limiting path
capacity: 1 # Capacity/token count
period: 10 # Time period
unit: SECONDS # Time unit (optional, default SECONDS)
proxyRules: # Proxy rules list
- endpoint: /test/get # Proxy path
proxies: # Proxy targets list
- targetEndpoint: /test/v1/get # Target path
weight: 5 # Weight
# Parameter mapping
mapRule: |-
#params.put('flagv1',#params.get('flag'))
- targetEndpoint: /test/v2/get
weight: 5
mapRule: |-
#params.put('flagv2',#params.get('flag'))
- endpoint: /test/post
proxies:
- targetEndpoint: /test/v1/post
weight: 5
# Request body mapping
bodyRule: |-
#params.put('value1','Hello')smart-router:
rateLimiter:
rateLimitingType: standalonesmart-router:
rateLimiter:
rateLimitingType: redis
attributes:
address: localhost:6379 # Redis address
password: your_password # Redis password
database: 0 # Database index (0-15)smart-router:
rateLimiter:
rateLimitingType: redis-cluster
attributes:
nodes: # Cluster node list
- localhost:7000
- localhost:7001
password: your_password # Passwordsmart-router:
rateLimiter:
rateLimitingType: redis-sentinel
attributes:
nodes: # Sentinel node list
- localhost:26379
- localhost:26380
password: your_password # Password
masterName: mymaster # Master node nameGet current rate limiting and proxy configuration
GET http://localhost:8080/smart/router/monitor/rules
Accept: application/jsonResponse
{
"rateLimitRules": [ //Rate limiting rules
{
"endpoint": "/test/hello",
"capacity": 1,
"period": 10,
"unit": "SECONDS"
}
],
"proxyRules": [ //Proxy rules
{
"endpoint": "/test/get",
"proxies": [
{
"targetEndpoint": "/test/v1/get",
"weight": 5,
"mapRule": "#params.put('flagv1',#params.get('flag'))",
"bodyRule": null
},
{
"targetEndpoint": "/test/v2/get",
"weight": 5,
"mapRule": "#params.put('flagv2',#params.get('flag'))",
"bodyRule": null
}
]
},
{
"endpoint": "/test/post",
"proxies": [
{
"targetEndpoint": "/test/v1/post",
"weight": 10,
"mapRule": null,
"bodyRule": "#params.put('value1','Hello')"
}
]
}
]
}Modify rate limiting and proxy configuration
POST http://localhost:8080/smart/router/monitor/rules
Content-Type: application/json
The project provides a built-in monitoring page. Access /smart/router/monitor/view to view the monitoring page

You can view and adjust rate limiting configuration and proxy configuration on the page

The project design has good extensibility:
- New rate limiting algorithms can be added by implementing the IFactory.java and IRateLimiter.java interfaces
- Custom storage can be implemented by implementing the IStorage.java interface