forked from spring-cloud/spring-cloud-gateway
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial set of changes to add a circuit breaker filter using Spring C…
…loud CircuitBreaker
- Loading branch information
Ryan Baxter
committed
Nov 5, 2019
1 parent
3f0364d
commit 76e4187
Showing
18 changed files
with
1,017 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...java/org/springframework/cloud/gateway/config/GatewayCircuitBreakerAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright 2013-2019 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.cloud.gateway.config; | ||
|
||
import org.springframework.beans.factory.ObjectProvider; | ||
import org.springframework.boot.autoconfigure.AutoConfigureAfter; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.cloud.circuitbreaker.resilience4j.ReactiveResilience4JAutoConfiguration; | ||
import org.springframework.cloud.circuitbreaker.resilience4j.ReactiveResilience4JCircuitBreakerFactory; | ||
import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreakerFactory; | ||
import org.springframework.cloud.gateway.filter.factory.FallbackHeadersGatewayFilterFactory; | ||
import org.springframework.cloud.gateway.filter.factory.SpringCloudCircuitBreakerHystrixFilterFactory; | ||
import org.springframework.cloud.gateway.filter.factory.SpringCloudCircuitBreakerResilience4JFilterFactory; | ||
import org.springframework.cloud.netflix.hystrix.HystrixCircuitBreakerAutoConfiguration; | ||
import org.springframework.cloud.netflix.hystrix.ReactiveHystrixCircuitBreakerFactory; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.reactive.DispatcherHandler; | ||
|
||
/** | ||
* @author Ryan Baxter | ||
*/ | ||
@Configuration | ||
@ConditionalOnProperty(name = "spring.cloud.gateway.enabled", matchIfMissing = true) | ||
@AutoConfigureAfter({ ReactiveResilience4JAutoConfiguration.class, | ||
HystrixCircuitBreakerAutoConfiguration.class }) | ||
@ConditionalOnClass({ DispatcherHandler.class, | ||
ReactiveResilience4JAutoConfiguration.class, | ||
HystrixCircuitBreakerAutoConfiguration.class }) | ||
public class GatewayCircuitBreakerAutoConfiguration { | ||
|
||
@Configuration | ||
@ConditionalOnClass({ ReactiveCircuitBreakerFactory.class, | ||
ReactiveHystrixCircuitBreakerFactory.class }) | ||
protected static class SpringCloudCircuitBreakerHystrixConfiguration { | ||
|
||
@Bean | ||
@ConditionalOnBean(ReactiveHystrixCircuitBreakerFactory.class) | ||
public SpringCloudCircuitBreakerHystrixFilterFactory springCloudCircuitBreakerHystrixFilterFactory( | ||
ReactiveHystrixCircuitBreakerFactory reactiveCircuitBreakerFactory, | ||
ObjectProvider<DispatcherHandler> dispatcherHandler) { | ||
return new SpringCloudCircuitBreakerHystrixFilterFactory( | ||
reactiveCircuitBreakerFactory, dispatcherHandler); | ||
} | ||
|
||
@Bean | ||
@ConditionalOnMissingBean(FallbackHeadersGatewayFilterFactory.class) | ||
public FallbackHeadersGatewayFilterFactory fallbackHeadersGatewayFilterFactory() { | ||
return new FallbackHeadersGatewayFilterFactory(); | ||
} | ||
|
||
} | ||
|
||
@Configuration | ||
@ConditionalOnClass({ ReactiveCircuitBreakerFactory.class, | ||
ReactiveResilience4JCircuitBreakerFactory.class }) | ||
protected static class Resilience4JConfiguration { | ||
|
||
@Bean | ||
@ConditionalOnMissingBean(FallbackHeadersGatewayFilterFactory.class) | ||
public FallbackHeadersGatewayFilterFactory fallbackHeadersGatewayFilterFactory() { | ||
return new FallbackHeadersGatewayFilterFactory(); | ||
} | ||
|
||
@Bean | ||
@ConditionalOnBean(ReactiveResilience4JCircuitBreakerFactory.class) | ||
public SpringCloudCircuitBreakerResilience4JFilterFactory springCloudCircuitBreakerResilience4JFilterFactory( | ||
ReactiveResilience4JCircuitBreakerFactory reactiveCircuitBreakerFactory, | ||
ObjectProvider<DispatcherHandler> dispatcherHandler) { | ||
return new SpringCloudCircuitBreakerResilience4JFilterFactory( | ||
reactiveCircuitBreakerFactory, dispatcherHandler); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.