RateLimitCaller invoke with query param and headers.

pull/952/head
atomzhong 3 years ago
parent a1ff970111
commit f178902482

@ -63,18 +63,24 @@ public class BusinessController {
@Value("${spring.application.name}")
private String appName;
@Value("${server.port:0}")
private int port;
@Value("${spring.cloud.client.ip-address:127.0.0.1}")
private String ip;
/**
* Get information.
* @return information
*/
@GetMapping("/info")
public String info() {
return "hello world for ratelimit service " + index.incrementAndGet();
return String.format("hello world for ratelimit service %s [%s:%s] is called.", index.incrementAndGet(), ip, port);
}
@GetMapping("/info/webclient")
public Mono<String> infoWebClient() {
return Mono.just("hello world for ratelimit service " + index.incrementAndGet());
return Mono.just(String.format("hello world for ratelimit service %s [%s:%s] is called.", index.incrementAndGet(), ip, port));
}
@GetMapping("/invoke/webclient")
@ -92,11 +98,11 @@ public class BusinessController {
.header("xxx", "xxx")
.retrieve()
.bodyToMono(String.class)
.doOnSuccess(s -> builder.append(s + "\n"))
.doOnSuccess(s -> builder.append(s).append("\n"))
.doOnError(e -> {
if (e instanceof WebClientResponseException) {
if (((WebClientResponseException) e).getRawStatusCode() == 429) {
builder.append("TooManyRequests ").append(index.incrementAndGet() + "\n");
builder.append("TooManyRequests ").append(index.incrementAndGet()).append("\n");
}
}
})
@ -132,11 +138,11 @@ public class BusinessController {
String.class,
"yyy"
);
builder.append(entity.getBody() + "\n");
builder.append(entity.getBody()).append("\n");
}
catch (RestClientException e) {
if (e instanceof TooManyRequests) {
builder.append("TooManyRequests ").append(index.incrementAndGet() + "\n");
builder.append("TooManyRequests ").append(index.incrementAndGet()).append("\n");
}
else {
throw e;

@ -76,7 +76,7 @@ public class Controller {
}
@GetMapping("/invoke/webclient")
public String invokeInfoWebClient(@RequestParam String value1, @RequestParam String value2, @RequestHeader Map<String, String> headers) throws InterruptedException, ExecutionException {
public String invokeInfoWebClient(@RequestParam(defaultValue = "value1") String value1, @RequestParam(defaultValue = "value1") String value2, @RequestHeader Map<String, String> headers) throws InterruptedException, ExecutionException {
StringBuffer builder = new StringBuffer();
WebClient webClient = webClientBuilder.baseUrl("http://" + appName).build();
@ -123,7 +123,7 @@ public class Controller {
* @throws InterruptedException exception
*/
@GetMapping("/invoke")
public String invokeInfo(@RequestParam String value1, @RequestParam String value2, @RequestHeader Map<String, String> headers) throws InterruptedException {
public String invokeInfo(@RequestParam(defaultValue = "value1") String value1, @RequestParam(defaultValue = "value1") String value2, @RequestHeader Map<String, String> headers) throws InterruptedException {
StringBuffer builder = new StringBuffer();
CountDownLatch count = new CountDownLatch(30);
for (int i = 0; i < 30; i++) {

Loading…
Cancel
Save