Ограничение скорости весенних облаков с помощью Bucket 4j и HazelcastJAVA

Программисты JAVA общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 Ограничение скорости весенних облаков с помощью Bucket 4j и Hazelcast

Сообщение Anonymous »

Я использую «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
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «JAVA»