org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreaker Java Examples
The following examples show how to use
org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreaker.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReactiveResilience4JCircuitBreakerFactory.java From spring-cloud-circuitbreaker with Apache License 2.0 | 5 votes |
@Override public ReactiveCircuitBreaker create(String id) { Assert.hasText(id, "A CircuitBreaker must have an id."); Resilience4JConfigBuilder.Resilience4JCircuitBreakerConfiguration config = getConfigurations() .computeIfAbsent(id, defaultConfiguration); return new ReactiveResilience4JCircuitBreaker(id, config, circuitBreakerRegistry, Optional.ofNullable(circuitBreakerCustomizers.get(id))); }
Example #2
Source File: ReactiveResilience4JCircuitBreakerTest.java From spring-cloud-circuitbreaker with Apache License 2.0 | 5 votes |
@Test public void runMono() { ReactiveCircuitBreaker cb = new ReactiveResilience4JCircuitBreakerFactory() .create("foo"); assertThat(Mono.just("foobar").transform(it -> cb.run(it)).block()) .isEqualTo("foobar"); }
Example #3
Source File: ReactiveResilience4JCircuitBreakerTest.java From spring-cloud-circuitbreaker with Apache License 2.0 | 5 votes |
@Test public void runMonoWithFallback() { ReactiveCircuitBreaker cb = new ReactiveResilience4JCircuitBreakerFactory() .create("foo"); assertThat(Mono.error(new RuntimeException("boom")) .transform(it -> cb.run(it, t -> Mono.just("fallback"))).block()) .isEqualTo("fallback"); }
Example #4
Source File: ReactiveResilience4JCircuitBreakerTest.java From spring-cloud-circuitbreaker with Apache License 2.0 | 5 votes |
@Test public void runFlux() { ReactiveCircuitBreaker cb = new ReactiveResilience4JCircuitBreakerFactory() .create("foo"); assertThat(Flux.just("foobar", "hello world").transform(it -> cb.run(it)) .collectList().block()).isEqualTo(Arrays.asList("foobar", "hello world")); }
Example #5
Source File: ReactiveResilience4JCircuitBreakerTest.java From spring-cloud-circuitbreaker with Apache License 2.0 | 5 votes |
@Test public void runFluxWithFallback() { ReactiveCircuitBreaker cb = new ReactiveResilience4JCircuitBreakerFactory() .create("foo"); assertThat(Flux.error(new RuntimeException("boom")) .transform(it -> cb.run(it, t -> Flux.just("fallback"))).collectList() .block()).isEqualTo(Arrays.asList("fallback")); }
Example #6
Source File: ReactiveSentinelCircuitBreakerFactory.java From spring-cloud-alibaba with Apache License 2.0 | 5 votes |
@Override public ReactiveCircuitBreaker create(String id) { Assert.hasText(id, "A CircuitBreaker must have an id."); SentinelConfigBuilder.SentinelCircuitBreakerConfiguration conf = getConfigurations() .computeIfAbsent(id, defaultConfiguration); return new ReactiveSentinelCircuitBreaker(id, conf.getEntryType(), conf.getRules()); }
Example #7
Source File: ReactiveSentinelCircuitBreakerTest.java From spring-cloud-alibaba with Apache License 2.0 | 5 votes |
@Test public void runMono() { ReactiveCircuitBreaker cb = new ReactiveSentinelCircuitBreakerFactory() .create("foo"); assertThat(Mono.just("foobar").transform(it -> cb.run(it)).block()) .isEqualTo("foobar"); }
Example #8
Source File: ReactiveSentinelCircuitBreakerTest.java From spring-cloud-alibaba with Apache License 2.0 | 5 votes |
@Test public void runMonoWithFallback() { ReactiveCircuitBreaker cb = new ReactiveSentinelCircuitBreakerFactory() .create("foo"); assertThat(Mono.error(new RuntimeException("boom")) .transform(it -> cb.run(it, t -> Mono.just("fallback"))).block()) .isEqualTo("fallback"); }
Example #9
Source File: ReactiveSentinelCircuitBreakerTest.java From spring-cloud-alibaba with Apache License 2.0 | 5 votes |
@Test public void runFlux() { ReactiveCircuitBreaker cb = new ReactiveSentinelCircuitBreakerFactory() .create("foo"); assertThat(Flux.just("foobar", "hello world").transform(it -> cb.run(it)) .collectList().block()).isEqualTo(Arrays.asList("foobar", "hello world")); }
Example #10
Source File: ReactiveSentinelCircuitBreakerTest.java From spring-cloud-alibaba with Apache License 2.0 | 5 votes |
@Test public void runFluxWithFallback() { ReactiveCircuitBreaker cb = new ReactiveSentinelCircuitBreakerFactory() .create("foo"); assertThat(Flux.error(new RuntimeException("boom")) .transform(it -> cb.run(it, t -> Flux.just("fallback"))).collectList() .block()).isEqualTo(Arrays.asList("fallback")); }
Example #11
Source File: SpringCloudCircuitBreakerFilterFactory.java From spring-cloud-gateway with Apache License 2.0 | 4 votes |
@Override public GatewayFilter apply(Config config) { ReactiveCircuitBreaker cb = reactiveCircuitBreakerFactory.create(config.getId()); return new GatewayFilter() { @Override public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) { return cb.run(chain.filter(exchange), t -> { if (config.getFallbackUri() == null) { return Mono.error(t); } // TODO: copied from RouteToRequestUrlFilter URI uri = exchange.getRequest().getURI(); // TODO: assume always? boolean encoded = containsEncodedParts(uri); URI requestUrl = UriComponentsBuilder.fromUri(uri).host(null) .port(null).uri(config.getFallbackUri()).scheme(null) .build(encoded).toUri(); exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, requestUrl); addExceptionDetails(t, exchange); // Before we continue on remove the already routed attribute since the // fallback may go back through the route handler if the fallback // is to another route in the Gateway removeAlreadyRouted(exchange); ServerHttpRequest request = exchange.getRequest().mutate() .uri(requestUrl).build(); return getDispatcherHandler() .handle(exchange.mutate().request(request).build()); }).onErrorResume(t -> handleErrorWithoutFallback(t)); } @Override public String toString() { return filterToStringCreator(SpringCloudCircuitBreakerFilterFactory.this) .append("name", config.getName()) .append("fallback", config.fallbackUri).toString(); } }; }