Я использую «com.giffing.bucket4j.spring.boot.starter» для реализации ограничения скорости с помощью hazelcast в своем проекте Spring Cloud.
Bucket4j не инициализируется в приложении запускать. Из-за этого ограничение скорости не работает.
Мой проект имеет ограничение на использование весенней загрузки версии 3.1.2, и согласно документации по giffing Bucket4j я использую версию Bucket4j Starter 0.10.3. . Но ограничение скорости не работает.
Пожалуйста, помогите.
Полная база кода:
GatewaySampleApplication.java
package com.oardic.springbootbucket4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
@EnableCaching
public class GatewaySampleApplication {
public static void main(String[] args) {
SpringApplication.run(GatewaySampleApplication.class, args);
}
@Bean
public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
//@formatter:off
return builder.routes()
.route(p -> p
.path("/get")
.filters(f -> f.addRequestHeader("Hello", "World"))
.uri("http://httpbin.org:80"))
.build();
//@formatter:on
}
}
MyController.java
package com.oardic.springbootbucket4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;
@RestController
@RequestMapping
public class MyController {
@GetMapping("/hello")
public Mono hello(
@RequestParam(defaultValue = "World") String name) {
return Mono.just("Hello")
.flatMap(s -> Mono
.just(s + ", " + name + "!\n")
);
}
@GetMapping("/world")
public Mono world(
@RequestParam(defaultValue = "World") String name) {
return Mono.just("Hello")
.flatMap(s -> Mono
.just(s + ", " + name + "!\n")
);
}
}
application.yml
spring:
cache:
type: jcache
jcache:
provider: com.hazelcast.cache.impl.HazelcastServerCachingProvider
config: classpath:hazelcast.xml
management:
endpoints:
web:
exposure:
include: "*"
bucket4j:
cache-to-use: hazelcast
enabled: true
filters:
- cache-name: buckets
rate-limits:
- bandwidths:
- capacity: 1
time: 5
unit: seconds
cache-key: '@securityService.getClientIP(#this)'
url: /myservice/endpoint/*
debug: true
logging:
file:
name: temp.log
path: D://temp.log
hazelcast.xml
120
BINARY
CREATE_ON_UPDATE
true
pom.xml
4.0.0
org.springframework.boot
spring-boot-starter-parent
3.1.2
com.giffing.bucket4j.spring.boot.starter
bucket4j-spring-boot-starter-example-gateway
0.0.1-SNAPSHOT
17
2022.0.3
org.springframework.boot
spring-boot-starter-actuator
org.springframework.boot
spring-boot-starter-webflux
org.springframework.cloud
spring-cloud-starter-gateway
com.giffing.bucket4j.spring.boot.starter
bucket4j-spring-boot-starter
0.10.3
org.springframework.boot
spring-boot-starter-cache
javax.cache
cache-api
com.github.vladimir-bukhtoyarov
bucket4j-hazelcast
7.6.0
com.hazelcast
hazelcast
jakarta.servlet
jakarta.servlet-api
provided
org.springframework.boot
spring-boot-devtools
runtime
true
org.springframework.boot
spring-boot-starter-test
test
org.springframework.cloud
spring-cloud-dependencies
${spring-cloud.version}
pom
import
org.springframework.boot
spring-boot-maven-plugin
Подробнее здесь: https://stackoverflow.com/questions/791 ... -hazelcast
Ограничение скорости весенних облаков с помощью Bucket 4j и Hazelcast ⇐ JAVA
Программисты JAVA общаются здесь
1731215190
Anonymous
Я использую «com.giffing.bucket4j.spring.boot.starter» для реализации ограничения скорости с помощью hazelcast в своем проекте Spring Cloud.
Bucket4j не инициализируется в приложении запускать. Из-за этого ограничение скорости не работает.
Мой проект имеет ограничение на использование весенней загрузки версии 3.1.2, и согласно документации по giffing Bucket4j я использую версию Bucket4j Starter 0.10.3. . Но ограничение скорости не работает.
Пожалуйста, помогите.
Полная база кода:
[b]GatewaySampleApplication.java[/b]
package com.oardic.springbootbucket4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
@EnableCaching
public class GatewaySampleApplication {
public static void main(String[] args) {
SpringApplication.run(GatewaySampleApplication.class, args);
}
@Bean
public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
//@formatter:off
return builder.routes()
.route(p -> p
.path("/get")
.filters(f -> f.addRequestHeader("Hello", "World"))
.uri("http://httpbin.org:80"))
.build();
//@formatter:on
}
}
[b]MyController.java[/b]
package com.oardic.springbootbucket4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;
@RestController
@RequestMapping
public class MyController {
@GetMapping("/hello")
public Mono hello(
@RequestParam(defaultValue = "World") String name) {
return Mono.just("Hello")
.flatMap(s -> Mono
.just(s + ", " + name + "!\n")
);
}
@GetMapping("/world")
public Mono world(
@RequestParam(defaultValue = "World") String name) {
return Mono.just("Hello")
.flatMap(s -> Mono
.just(s + ", " + name + "!\n")
);
}
}
[b]application.yml[/b]
spring:
cache:
type: jcache
jcache:
provider: com.hazelcast.cache.impl.HazelcastServerCachingProvider
config: classpath:hazelcast.xml
management:
endpoints:
web:
exposure:
include: "*"
bucket4j:
cache-to-use: hazelcast
enabled: true
filters:
- cache-name: buckets
rate-limits:
- bandwidths:
- capacity: 1
time: 5
unit: seconds
cache-key: '@securityService.getClientIP(#this)'
url: /myservice/endpoint/*
debug: true
logging:
file:
name: temp.log
path: D://temp.log
[b]hazelcast.xml[/b]
120
BINARY
CREATE_ON_UPDATE
true
[b]pom.xml[/b]
4.0.0
org.springframework.boot
spring-boot-starter-parent
3.1.2
com.giffing.bucket4j.spring.boot.starter
bucket4j-spring-boot-starter-example-gateway
0.0.1-SNAPSHOT
17
2022.0.3
org.springframework.boot
spring-boot-starter-actuator
org.springframework.boot
spring-boot-starter-webflux
org.springframework.cloud
spring-cloud-starter-gateway
com.giffing.bucket4j.spring.boot.starter
bucket4j-spring-boot-starter
0.10.3
org.springframework.boot
spring-boot-starter-cache
javax.cache
cache-api
com.github.vladimir-bukhtoyarov
bucket4j-hazelcast
7.6.0
com.hazelcast
hazelcast
jakarta.servlet
jakarta.servlet-api
provided
org.springframework.boot
spring-boot-devtools
runtime
true
org.springframework.boot
spring-boot-starter-test
test
org.springframework.cloud
spring-cloud-dependencies
${spring-cloud.version}
pom
import
org.springframework.boot
spring-boot-maven-plugin
Подробнее здесь: [url]https://stackoverflow.com/questions/79174174/spring-cloud-ratelimit-with-bucket-4j-and-hazelcast[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия