我想为我的项目申请基于IP (/get)服务的速率限制,例如,每个IP都可以访问特定的no的每个服务。时间,即5次/10秒。我使用过bucket4j速率限制,但它不起作用。有人知道这件事吗?
这是我的application.properties
spring.cache.jcache.config=classpath:ehcache.xml
logging.level.org.ehcache=info
bucket4j.enabled=true
bucket4j.filters[0].cache-name=buckets
bucket4j.filters[0].filter-method=servlet
bucket4j.filters[0].url=.*
bucket4j.filters[0].rate-limits[0].bandwidths[0].capacity=5
bucket4j.filters[0].rate-limits[0].bandwidths[0].time=10
bucket4j.filters[0].rate-limits[0].bandwidths[0].unit=seconds
bucket4j.filters[0].rate-limits[0].expression="getRemoteAddress()"
bucket4j.filters[0].rate-limits[0].bandwidths[0].fixed-refill-interval=0
bucket4j.filters[0].rate-limits[0].bandwidths[0].fixed-refill-interval-unit=seconds我是encache.xml
<config xmlns='http://www.ehcache.org/v3'
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jsr107="http://www.ehcache.org/v3/jsr107"
xsi:schemaLocation="http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.0.xsd
http://www.ehcache.org/v3/jsr107 http://www.ehcache.org/schema/ehcache-107-ext-3.0.xsd">
<cache alias="buckets">
<expiry><ttl unit="seconds">6</ttl></expiry>
<heap unit="entries">2000</heap>
<jsr107:mbeans enable-statistics="true"/>
</cache>
</config>pom.xml
<dependency>
<groupId>com.giffing.bucket4j.spring.boot.starter</groupId>
<artifactId>bucket4j-spring-boot-starter</artifactId>
<version>0.2.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
<dependency>
<groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId>
<scope>runtime</scope>
</dependency>服务器初始化器
@EnableCaching
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(EwseparationApplication.class);
}
}发布于 2022-02-21 07:08:27
我也有同样的问题。看起来,bucket4j spring启动github项目(链接)出现了一个问题。
我将我的application.properties转换为application.yml,就像在问题中报告的个人一样,我的利率限制也开始起作用。我不知道实际问题是什么(为什么application.yml工作,而application.properties不工作)。比起yml,我更喜欢属性格式。
发布于 2022-10-19 14:20:06
您可以使用.yaml,因为.properties在识别标记时仍然存在一些问题。
https://stackoverflow.com/questions/63048121
复制相似问题