From ee8c639b5486430ff81ecc64f06f4cd7771b9250 Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Fri, 15 Sep 2023 16:00:57 -0400 Subject: [PATCH] Antora migration (#173) * Migrate Structure * Insert explicit ids for headers * Remove unnecessary asciidoc attributes * Copy default antora files * Fix indentation for all pages * Split files * Generate a default navigation * Remove includes * Enable Section Summary TOC for small pages * Antora migration --- .github/workflows/deploy-docs.yml | 32 ++ .gitignore | 6 + .mvn/maven.config | 2 +- .mvn/wrapper/maven-wrapper.properties | 3 +- README.adoc | 517 ++---------------- docs/antora-playbook.yml | 38 ++ docs/antora.yml | 12 + docs/modules/ROOT/nav.adoc | 11 + .../ROOT/pages}/_attributes.adoc | 2 - docs/modules/ROOT/pages/index.adoc | 1 + ...ing-cloud-circuitbreaker-resilience4j.adoc | 4 + .../bulkhead-pattern-supporting.adoc | 30 + .../bulkhead-properties-configuration.adoc | 22 + ...cuit-breaker-properties-configuration.adoc | 86 +++ .../collecting-metrics.adoc | 9 + .../default-configuration.adoc | 49 ++ .../specific-bulkhead-configuration.adoc | 46 ++ ...pecific-circuit-breaker-configuration.adoc | 46 ++ .../starters.adoc | 16 + ...ing-cloud-circuitbreaker-spring-retry.adoc | 15 +- .../pages}/spring-cloud-circuitbreaker.adoc | 12 +- docs/pom.xml | 21 +- .../resources/antora-resources/antora.yml | 20 + docs/src/main/asciidoc/README.adoc | 11 + docs/src/main/asciidoc/index.adoc | 1 - ...ing-cloud-circuitbreaker-resilience4j.adoc | 313 ----------- 26 files changed, 519 insertions(+), 806 deletions(-) create mode 100644 .github/workflows/deploy-docs.yml create mode 100644 docs/antora-playbook.yml create mode 100644 docs/antora.yml create mode 100644 docs/modules/ROOT/nav.adoc rename docs/{src/main/asciidoc => modules/ROOT/pages}/_attributes.adoc (90%) create mode 100644 docs/modules/ROOT/pages/index.adoc create mode 100644 docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j.adoc create mode 100644 docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/bulkhead-pattern-supporting.adoc create mode 100644 docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/bulkhead-properties-configuration.adoc create mode 100644 docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/circuit-breaker-properties-configuration.adoc create mode 100644 docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/collecting-metrics.adoc create mode 100644 docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/default-configuration.adoc create mode 100644 docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/specific-bulkhead-configuration.adoc create mode 100644 docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/specific-circuit-breaker-configuration.adoc create mode 100644 docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/starters.adoc rename docs/{src/main/asciidoc => modules/ROOT/pages}/spring-cloud-circuitbreaker-spring-retry.adoc (92%) rename docs/{src/main/asciidoc => modules/ROOT/pages}/spring-cloud-circuitbreaker.adoc (52%) create mode 100644 docs/src/main/antora/resources/antora-resources/antora.yml delete mode 100644 docs/src/main/asciidoc/index.adoc delete mode 100644 docs/src/main/asciidoc/spring-cloud-circuitbreaker-resilience4j.adoc diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.yml new file mode 100644 index 00000000..be4b92df --- /dev/null +++ b/.github/workflows/deploy-docs.yml @@ -0,0 +1,32 @@ +name: Deploy Docs +on: + push: + branches-ignore: [ gh-pages ] + tags: '**' + repository_dispatch: + types: request-build-reference # legacy + #schedule: + #- cron: '0 10 * * *' # Once per day at 10am UTC + workflow_dispatch: +permissions: + actions: write +jobs: + build: + runs-on: ubuntu-latest + # if: github.repository_owner == 'spring-cloud' + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + ref: docs-build + fetch-depth: 1 + - name: Dispatch (partial build) + if: github.ref_type == 'branch' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: gh workflow run deploy-docs.yml -r $(git rev-parse --abbrev-ref HEAD) -f build-refname=${{ github.ref_name }} + - name: Dispatch (full build) + if: github.ref_type == 'tag' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: gh workflow run deploy-docs.yml -r $(git rev-parse --abbrev-ref HEAD) diff --git a/.gitignore b/.gitignore index 42f20702..9b40b235 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,9 @@ _site/ *.swp *.swo .flattened-pom.xml + +node +node_modules +build +package.json +package-lock.json diff --git a/.mvn/maven.config b/.mvn/maven.config index 3b8cf46e..a6829905 100644 --- a/.mvn/maven.config +++ b/.mvn/maven.config @@ -1 +1 @@ --DaltSnapshotDeploymentRepository=repo.spring.io::default::https://repo.spring.io/libs-snapshot-local -P spring +-P spring diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties index 71793467..b8e54d3a 100755 --- a/.mvn/wrapper/maven-wrapper.properties +++ b/.mvn/wrapper/maven-wrapper.properties @@ -1 +1,2 @@ -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.0/apache-maven-3.9.0-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar diff --git a/README.adoc b/README.adoc index 1598c884..18362024 100644 --- a/README.adoc +++ b/README.adoc @@ -5,443 +5,18 @@ Edit the files in the src/main/asciidoc/ directory instead. //// -:doctype: book -:idprefix: -:idseparator: - -:toc: left -:toclevels: 4 -:tabsize: 4 -:numbered: -:sectanchors: -:sectnums: -:icons: font -:hide-uri-scheme: -:docinfo: shared,private - -:sc-ext: java -:project-full-name: Spring Cloud Circuitbreaker -:all: {asterisk}{asterisk} - -= Spring Cloud Circuit Breaker -:doctype: book -:idprefix: -:idseparator: - -:toc: left -:toclevels: 4 -:tabsize: 4 -:numbered: -:sectanchors: -:sectnums: -:icons: font -:hide-uri-scheme: -:docinfo: shared,private - -:sc-ext: java -:project-full-name: Spring Cloud Circuitbreaker -:all: {asterisk}{asterisk} - -*{spring-cloud-version}* - -## Usage Documentation - -The Spring Cloud CircuitBreaker project contains implementations for Resilience4J and Spring Retry. -The APIs implemented in Spring Cloud CircuitBreaker live in Spring Cloud Commons. The usage documentation -for these APIs are located in the https://docs.spring.io/spring-cloud-commons/docs/current/reference/html/#spring-cloud-circuit-breaker[Spring Cloud Commons documentation]. - -=== Configuring Resilience4J Circuit Breakers - -==== Starters - -There are two starters for the Resilience4J implementations, one for reactive applications and one for non-reactive applications. - -* `org.springframework.cloud:spring-cloud-starter-circuitbreaker-resilience4j` - non-reactive applications -* `org.springframework.cloud:spring-cloud-starter-circuitbreaker-reactor-resilience4j` - reactive applications - -==== Auto-Configuration -You can disable the Resilience4J auto-configuration by setting -`spring.cloud.circuitbreaker.resilience4j.enabled` to `false`. - -==== Default Configuration - -To provide a default configuration for all of your circuit breakers create a `Customizer` bean that is passed a -`Resilience4JCircuitBreakerFactory` or `ReactiveResilience4JCircuitBreakerFactory`. -The `configureDefault` method can be used to provide a default configuration. - -==== -[source,java] ----- -@Bean -public Customizer defaultCustomizer() { - return factory -> factory.configureDefault(id -> new Resilience4JConfigBuilder(id) - .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(4)).build()) - .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()) - .build()); -} ----- -==== - -===== Reactive Example - -==== -[source,java] ----- -@Bean -public Customizer defaultCustomizer() { - return factory -> factory.configureDefault(id -> new Resilience4JConfigBuilder(id) - .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()) - .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(4)).build()).build()); -} ----- -==== - -===== Customizing The ExecutorService -If you would like to configure the `ExecutorService` which executes the circuit breaker you can do so using the `Resilience4JCircuitBreakerFactory`. - -For example if you would like to use a context aware `ExecutorService` you could do the following. - -==== -[source,java] ----- -@Bean -public Customizer defaultCustomizer() { - return factory -> { - ContextAwareScheduledThreadPoolExecutor executor = ContextAwareScheduledThreadPoolExecutor.newScheduledThreadPool().corePoolSize(5) - .build(); - factory.configureExecutorService(executor); - }; -} ----- -==== - -==== Specific Circuit Breaker Configuration - -Similarly to providing a default configuration, you can create a `Customizer` bean this is passed a -`Resilience4JCircuitBreakerFactory` or `ReactiveResilience4JCircuitBreakerFactory`. - -==== -[source,java] ----- -@Bean -public Customizer slowCustomizer() { - return factory -> factory.configure(builder -> builder.circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()) - .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(2)).build()), "slow"); -} ----- -==== - -In addition to configuring the circuit breaker that is created you can also customize the circuit breaker after it has been created but before it is returned to the caller. -To do this you can use the `addCircuitBreakerCustomizer` -method. -This can be useful for adding event handlers to Resilience4J circuit breakers. - -==== -[source,java] ----- -@Bean -public Customizer slowCustomizer() { - return factory -> factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker.getEventPublisher() - .onError(normalFluxErrorConsumer).onSuccess(normalFluxSuccessConsumer), "normalflux"); -} ----- -==== - -===== Reactive Example - -==== -[source,java] ----- -@Bean -public Customizer slowCustomizer() { - return factory -> { - factory.configure(builder -> builder - .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(2)).build()) - .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()), "slow", "slowflux"); - factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker.getEventPublisher() - .onError(normalFluxErrorConsumer).onSuccess(normalFluxSuccessConsumer), "normalflux"); - }; -} ----- -==== - -==== Circuit Breaker Properties Configuration +Unresolved directive in - include::_attributes.adoc[] -You can configure `CircuitBreaker` and `TimeLimiter` configs or instances in your application's configuration properties file. -Property configuration has higher priority than Java `Customizer` configuration. +Unresolved directive in - include::spring-cloud-circuitbreaker.adoc[] -Descending priority from top to bottom. - -* Method(id) config - on specific method or operation -* Service(group) config - on specific application service or operations -* Global default config - -==== -[source,java] ----- -ReactiveResilience4JCircuitBreakerFactory.create(String id, String groupName) -Resilience4JCircuitBreakerFactory.create(String id, String groupName) ----- -==== - -===== Global Default Properties Configuration -==== -[source] ----- -resilience4j.circuitbreaker: - configs: - default: - registerHealthIndicator: true - slidingWindowSize: 50 - -resilience4j.timelimiter: - configs: - default: - timeoutDuration: 5s - cancelRunningFuture: true ----- -==== - -===== Configs Properties Configuration -==== -[source] ----- -resilience4j.circuitbreaker: - configs: - groupA: - registerHealthIndicator: true - slidingWindowSize: 200 - -resilience4j.timelimiter: - configs: - groupC: - timeoutDuration: 3s - cancelRunningFuture: true ----- -==== - -===== Instances Properties Configuration -==== -[source] ----- -resilience4j.circuitbreaker: - instances: - backendA: - registerHealthIndicator: true - slidingWindowSize: 100 - backendB: - registerHealthIndicator: true - slidingWindowSize: 10 - permittedNumberOfCallsInHalfOpenState: 3 - slidingWindowType: TIME_BASED - recordFailurePredicate: io.github.robwin.exception.RecordFailurePredicate - -resilience4j.timelimiter: - instances: - backendA: - timeoutDuration: 2s - cancelRunningFuture: true - backendB: - timeoutDuration: 1s - cancelRunningFuture: false ----- -==== - - -* `ReactiveResilience4JCircuitBreakerFactory.create("backendA")` or `Resilience4JCircuitBreakerFactory.create("backendA")` will apply `instances backendA properties` -* `ReactiveResilience4JCircuitBreakerFactory.create("backendA", "groupA")` or `Resilience4JCircuitBreakerFactory.create("backendA", "groupA")` will apply `instances backendA properties` -* `ReactiveResilience4JCircuitBreakerFactory.create("backendC")` or `Resilience4JCircuitBreakerFactory.create("backendC")` will apply `global default properties` -* `ReactiveResilience4JCircuitBreakerFactory.create("backendC", "groupC")` or `Resilience4JCircuitBreakerFactory.create("backendC", "groupC")` will apply `global default CircuitBreaker properties and config groupC TimeLimiter properties` - -For more information on Resilience4j property configuration, see https://resilience4j.readme.io/docs/getting-started-3#configuration[Resilience4J Spring Boot 2 Configuration]. - -==== Bulkhead pattern supporting -If `resilience4j-bulkhead` is on the classpath, Spring Cloud CircuitBreaker will wrap all methods with a Resilience4j Bulkhead. -You can disable the Resilience4j Bulkhead by setting `spring.cloud.circuitbreaker.bulkhead.resilience4j.enabled` to `false`. - -Spring Cloud CircuitBreaker Resilience4j provides two implementation of bulkhead pattern: - -* a `SemaphoreBulkhead` which uses Semaphores -* a `FixedThreadPoolBulkhead` which uses a bounded queue and a fixed thread pool. - -By default, Spring Cloud CircuitBreaker Resilience4j uses `FixedThreadPoolBulkhead`. To modify the default behavior to use `SemaphoreBulkhead` set the property `spring.cloud.circuitbreaker.resilience4j.enableSemaphoreDefaultBulkhead` to `true`. - -For more information on implementation -of Bulkhead patterns see the https://resilience4j.readme.io/docs/bulkhead[Resilience4j Bulkhead]. - -The `Customizer` can be used to provide a default `Bulkhead` and `ThreadPoolBulkhead` configuration. - -==== -[source,java] ----- -@Bean -public Customizer defaultBulkheadCustomizer() { - return provider -> provider.configureDefault(id -> new Resilience4jBulkheadConfigurationBuilder() - .bulkheadConfig(BulkheadConfig.custom().maxConcurrentCalls(4).build()) - .threadPoolBulkheadConfig(ThreadPoolBulkheadConfig.custom().coreThreadPoolSize(1).maxThreadPoolSize(1).build()) - .build() -); -} ----- -==== - -==== Specific Bulkhead Configuration - -Similarly to proving a default 'Bulkhead' or 'ThreadPoolBulkhead' configuration, you can create a `Customizer` bean this -is passed a `Resilience4jBulkheadProvider`. - -==== -[source,java] ----- -@Bean -public Customizer slowBulkheadProviderCustomizer() { - return provider -> provider.configure(builder -> builder - .bulkheadConfig(BulkheadConfig.custom().maxConcurrentCalls(1).build()) - .threadPoolBulkheadConfig(ThreadPoolBulkheadConfig.ofDefaults()), "slowBulkhead"); -} ----- -==== - -In addition to configuring the Bulkhead that is created you can also customize the bulkhead and thread pool bulkhead after they -have been created but before they are returned to caller. To do this you can use the `addBulkheadCustomizer` and `addThreadPoolBulkheadCustomizer` -methods. - -===== Bulkhead Example - -==== -[source,java] ----- -@Bean -public Customizer customizer() { - return provider -> provider.addBulkheadCustomizer(bulkhead -> bulkhead.getEventPublisher() - .onCallRejected(slowRejectedConsumer) - .onCallFinished(slowFinishedConsumer), "slowBulkhead"); -} ----- -==== - -===== Thread Pool Bulkhead Example - -==== -[source,java] ----- -@Bean -public Customizer slowThreadPoolBulkheadCustomizer() { - return provider -> provider.addThreadPoolBulkheadCustomizer(threadPoolBulkhead -> threadPoolBulkhead.getEventPublisher() - .onCallRejected(slowThreadPoolRejectedConsumer) - .onCallFinished(slowThreadPoolFinishedConsumer), "slowThreadPoolBulkhead"); -} ----- -==== - -==== Bulkhead Properties Configuration - -You can configure ThreadPoolBulkhead and SemaphoreBulkhead instances in your application's configuration properties file. -Property configuration has higher priority than Java `Customizer` configuration. - -==== -[source] ----- -resilience4j.thread-pool-bulkhead: - instances: - backendA: - maxThreadPoolSize: 1 - coreThreadPoolSize: 1 -resilience4j.bulkhead: - instances: - backendB: - maxConcurrentCalls: 10 ----- -==== - -For more inforamtion on the Resilience4j property configuration, see https://resilience4j.readme.io/docs/getting-started-3#configuration[Resilience4J Spring Boot 2 Configuration]. - -==== Collecting Metrics - -Spring Cloud Circuit Breaker Resilience4j includes auto-configuration to setup metrics collection as long as the right -dependencies are on the classpath. To enable metric collection you must include `org.springframework.boot:spring-boot-starter-actuator`, and `io.github.resilience4j:resilience4j-micrometer`. For more information on the metrics that -get produced when these dependencies are present, see the https://resilience4j.readme.io/docs/micrometer[Resilience4j documentation]. - -NOTE: You don't have to include `micrometer-core` directly as it is brought in by `spring-boot-starter-actuator` - -=== Configuring Spring Retry Circuit Breakers - -Spring Retry provides declarative retry support for Spring applications. -A subset of the project includes the ability to implement circuit breaker functionality. -Spring Retry provides a circuit breaker implementation via a combination of it's -https://github.com/spring-projects/spring-retry/blob/master/src/main/java/org/springframework/retry/policy/CircuitBreakerRetryPolicy.java[`CircuitBreakerRetryPolicy`] -and a https://github.com/spring-projects/spring-retry#stateful-retry[stateful retry]. -All circuit breakers created using Spring Retry will be created using the `CircuitBreakerRetryPolicy` and a -https://github.com/spring-projects/spring-retry/blob/master/src/main/java/org/springframework/retry/support/DefaultRetryState.java[`DefaultRetryState`]. -Both of these classes can be configured using `SpringRetryConfigBuilder`. - -==== Default Configuration - -To provide a default configuration for all of your circuit breakers create a `Customizer` bean that is passed a -`SpringRetryCircuitBreakerFactory`. -The `configureDefault` method can be used to provide a default configuration. - -==== -[source,java] ----- -@Bean -public Customizer defaultCustomizer() { - return factory -> factory.configureDefault(id -> new SpringRetryConfigBuilder(id) - .retryPolicy(new TimeoutRetryPolicy()).build()); -} ----- -==== - -==== Specific Circuit Breaker Configuration - -Similarly to providing a default configuration, you can create a `Customizer` bean this is passed a -`SpringRetryCircuitBreakerFactory`. - -==== -[source,java] ----- -@Bean -public Customizer slowCustomizer() { - return factory -> factory.configure(builder -> builder.retryPolicy(new SimpleRetryPolicy(1)).build(), "slow"); -} ----- -==== - -In addition to configuring the circuit breaker that is created you can also customize the circuit breaker after it has been created but before it is returned to the caller. -To do this you can use the `addRetryTemplateCustomizers` -method. -This can be useful for adding event handlers to the `RetryTemplate`. - -==== -[source,java] ----- -@Bean -public Customizer slowCustomizer() { - return factory -> factory.addRetryTemplateCustomizers(retryTemplate -> retryTemplate.registerListener(new RetryListener() { - - @Override - public boolean open(RetryContext context, RetryCallback callback) { - return false; - } - - @Override - public void close(RetryContext context, RetryCallback callback, Throwable throwable) { - - } - - @Override - public void onError(RetryContext context, RetryCallback callback, Throwable throwable) { - - } - })); -} ----- -==== +[[building]] == Building - :jdkversion: 17 -=== Basic Compile and Test +[[basic-compile-and-test]] +== Basic Compile and Test To build the source you will need to install JDK {jdkversion}. @@ -468,31 +43,36 @@ source control. The projects that require middleware (i.e. Redis) for testing generally require that a local instance of [Docker](https://www.docker.com/get-started) is installed and running. - -=== Documentation +[[documentation]] +== Documentation The spring-cloud-build module has a "docs" profile, and if you switch -that on it will try to build asciidoc sources from -`src/main/asciidoc`. As part of that process it will look for a -`README.adoc` and process it by loading all the includes, but not +that on it will try to build asciidoc sources using https://docs.antora.org/antora/latest/[Antora] from +`modules/ROOT/`. + +As part of that process it will look for a +`docs/src/main/asciidoc/README.adoc` and process it by loading all the includes, but not parsing or rendering it, just copying it to `${main.basedir}` -(defaults to `${basedir}`, i.e. the root of the project). If there are +(defaults to `$\{basedir}`, i.e. the root of the project). If there are any changes in the README it will then show up after a Maven build as a modified file in the correct place. Just commit it and push the change. -=== Working with the code +[[working-with-the-code]] +== Working with the code If you don't have an IDE preference we would recommend that you use https://www.springsource.com/developer/sts[Spring Tools Suite] or https://eclipse.org[Eclipse] when working with the code. We use the https://eclipse.org/m2e/[m2eclipse] eclipse plugin for maven support. Other IDEs and tools should also work without issue as long as they use Maven 3.3.3 or better. -==== Activate the Spring Maven profile +[[activate-the-spring-maven-profile]] +=== Activate the Spring Maven profile Spring Cloud projects require the 'spring' Maven profile to be activated to resolve the spring milestone and snapshot repositories. Use your preferred IDE to set this profile to be active, or you may experience build errors. -==== Importing into eclipse with m2eclipse +[[importing-into-eclipse-with-m2eclipse]] +=== Importing into eclipse with m2eclipse We recommend the https://eclipse.org/m2e/[m2eclipse] eclipse plugin when working with eclipse. If you don't already have m2eclipse installed it is available from the "eclipse marketplace". @@ -506,7 +86,8 @@ add the "spring" profile to your `settings.xml`. Alternatively you can copy the repository settings from the "spring" profile of the parent pom into your `settings.xml`. -==== Importing into eclipse without m2eclipse +[[importing-into-eclipse-without-m2eclipse]] +=== Importing into eclipse without m2eclipse If you prefer not to use m2eclipse you can generate eclipse project metadata using the following command: @@ -519,18 +100,20 @@ The generated eclipse projects can be imported by selecting `import existing pro from the `file` menu. - +[[contributing]] == Contributing -:spring-cloud-build-branch: master +:spring-cloud-build-branch: main Spring Cloud is released under the non-restrictive Apache 2.0 license, and follows a very standard Github development process, using Github -tracker for issues and merging pull requests into master. If you want +tracker for issues and merging pull requests into main. If you want to contribute even something trivial please do not hesitate, but follow the guidelines below. -=== Sign the Contributor License Agreement +[[sign-the-contributor-license-agreement]] +== Sign the Contributor License Agreement + Before we accept a non-trivial patch or pull request we will need you to sign the https://cla.pivotal.io/sign/spring[Contributor License Agreement]. Signing the contributor's agreement does not grant anyone commit rights to the main @@ -538,19 +121,21 @@ repository, but it does mean that we can accept your contributions, and you will author credit if we do. Active contributors might be asked to join the core team, and given the ability to merge pull requests. -=== Code of Conduct -This project adheres to the Contributor Covenant https://github.com/spring-cloud/spring-cloud-build/blob/master/docs/src/main/asciidoc/code-of-conduct.adoc[code of +[[code-of-conduct]] +== Code of Conduct +This project adheres to the Contributor Covenant https://github.com/spring-cloud/spring-cloud-build/blob/main/docs/src/main/asciidoc/code-of-conduct.adoc[code of conduct]. By participating, you are expected to uphold this code. Please report unacceptable behavior to spring-code-of-conduct@pivotal.io. -=== Code Conventions and Housekeeping +[[code-conventions-and-housekeeping]] +== Code Conventions and Housekeeping None of these is essential for a pull request, but they will all help. They can also be added after the original pull request but before a merge. * Use the Spring Framework code format conventions. If you use Eclipse you can import formatter settings using the `eclipse-code-formatter.xml` file from the - https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-dependencies-parent/eclipse-code-formatter.xml[Spring + https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/spring-cloud-dependencies-parent/eclipse-code-formatter.xml[Spring Cloud Build] project. If using IntelliJ, you can use the https://plugins.jetbrains.com/plugin/6546[Eclipse Code Formatter Plugin] to import the same file. @@ -563,13 +148,14 @@ added after the original pull request but before a merge. than cosmetic changes). * Add some Javadocs and, if you change the namespace, some XSD doc elements. * A few unit tests would help a lot as well -- someone has to do it. -* If no-one else is using your branch, please rebase it against the current master (or +* If no-one else is using your branch, please rebase it against the current main (or other target branch in the main project). * When writing a commit message please follow https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html[these conventions], if you are fixing an existing issue please add `Fixes gh-XXXX` at the end of the commit message (where XXXX is the issue number). -=== Checkstyle +[[checkstyle]] +== Checkstyle Spring Cloud Build comes with a set of checkstyle rules. You can find them in the `spring-cloud-build-tools` module. The most notable files under the module are: @@ -587,7 +173,8 @@ Spring Cloud Build comes with a set of checkstyle rules. You can find them in th <2> File header setup <3> Default suppression rules -==== Checkstyle configuration +[[checkstyle-configuration]] +=== Checkstyle configuration Checkstyle rules are *disabled by default*. To add checkstyle to your project just define the following properties and plugins. @@ -646,16 +233,18 @@ If you need to suppress some rules (e.g. line length needs to be longer), then i It's advisable to copy the `${spring-cloud-build.rootFolder}/.editorconfig` and `${spring-cloud-build.rootFolder}/.springformat` to your project. That way, some default formatting rules will be applied. You can do so by running this script: ```bash -$ curl https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/.editorconfig -o .editorconfig +$ curl https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/.editorconfig -o .editorconfig $ touch .springformat ``` -=== IDE setup +[[ide-setup]] +== IDE setup -==== Intellij IDEA +[[intellij-idea]] +=== Intellij IDEA In order to setup Intellij you should import our coding conventions, inspection profiles and set up the checkstyle plugin. -The following files can be found in the https://github.com/spring-cloud/spring-cloud-build/tree/master/spring-cloud-build-tools[Spring Cloud Build] project. +The following files can be found in the https://github.com/spring-cloud/spring-cloud-build/tree/main/spring-cloud-build-tools[Spring Cloud Build] project. .spring-cloud-build-tools/ ---- @@ -678,13 +267,13 @@ The following files can be found in the https://github.com/spring-cloud/spring-c .Code style -image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/{spring-cloud-build-branch}/docs/src/main/asciidoc/images/intellij-code-style.png[Code style] +image::cloud-build:ROOT:intellij-code-style.png[Code style] Go to `File` -> `Settings` -> `Editor` -> `Code style`. There click on the icon next to the `Scheme` section. There, click on the `Import Scheme` value and pick the `Intellij IDEA code style XML` option. Import the `spring-cloud-build-tools/src/main/resources/intellij/Intellij_Spring_Boot_Java_Conventions.xml` file. .Inspection profiles -image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/{spring-cloud-build-branch}/docs/src/main/asciidoc/images/intellij-inspections.png[Code style] +image::cloud-build:ROOT:intellij-inspections.png[Code style] Go to `File` -> `Settings` -> `Editor` -> `Inspections`. There click on the icon next to the `Profile` section. There, click on the `Import Profile` and import the `spring-cloud-build-tools/src/main/resources/intellij/Intellij_Project_Defaults.xml` file. @@ -692,21 +281,23 @@ Go to `File` -> `Settings` -> `Editor` -> `Inspections`. There click on the icon To have Intellij work with Checkstyle, you have to install the `Checkstyle` plugin. It's advisable to also install the `Assertions2Assertj` to automatically convert the JUnit assertions -image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/{spring-cloud-build-branch}/docs/src/main/asciidoc/images/intellij-checkstyle.png[Checkstyle] +image::cloud-build:ROOT:intellij-checkstyle.png[Checkstyle] -Go to `File` -> `Settings` -> `Other settings` -> `Checkstyle`. There click on the `+` icon in the `Configuration file` section. There, you'll have to define where the checkstyle rules should be picked from. In the image above, we've picked the rules from the cloned Spring Cloud Build repository. However, you can point to the Spring Cloud Build's GitHub repository (e.g. for the `checkstyle.xml` : `https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/main/resources/checkstyle.xml`). We need to provide the following variables: +Go to `File` -> `Settings` -> `Other settings` -> `Checkstyle`. There click on the `+` icon in the `Configuration file` section. There, you'll have to define where the checkstyle rules should be picked from. In the image above, we've picked the rules from the cloned Spring Cloud Build repository. However, you can point to the Spring Cloud Build's GitHub repository (e.g. for the `checkstyle.xml` : `https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/spring-cloud-build-tools/src/main/resources/checkstyle.xml`). We need to provide the following variables: -- `checkstyle.header.file` - please point it to the Spring Cloud Build's, `spring-cloud-build-tools/src/main/resources/checkstyle-header.txt` file either in your cloned repo or via the `https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/main/resources/checkstyle-header.txt` URL. -- `checkstyle.suppressions.file` - default suppressions. Please point it to the Spring Cloud Build's, `spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml` file either in your cloned repo or via the `https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml` URL. +- `checkstyle.header.file` - please point it to the Spring Cloud Build's, `spring-cloud-build-tools/src/main/resources/checkstyle-header.txt` file either in your cloned repo or via the `https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/spring-cloud-build-tools/src/main/resources/checkstyle-header.txt` URL. +- `checkstyle.suppressions.file` - default suppressions. Please point it to the Spring Cloud Build's, `spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml` file either in your cloned repo or via the `https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml` URL. - `checkstyle.additional.suppressions.file` - this variable corresponds to suppressions in your local project. E.g. you're working on `spring-cloud-contract`. Then point to the `project-root/src/checkstyle/checkstyle-suppressions.xml` folder. Example for `spring-cloud-contract` would be: `/home/username/spring-cloud-contract/src/checkstyle/checkstyle-suppressions.xml`. IMPORTANT: Remember to set the `Scan Scope` to `All sources` since we apply checkstyle rules for production and test sources. -=== Duplicate Finder +[[duplicate-finder]] +== Duplicate Finder Spring Cloud Build brings along the `basepom:duplicate-finder-maven-plugin`, that enables flagging duplicate and conflicting classes and resources on the java classpath. -==== Duplicate Finder configuration +[[duplicate-finder-configuration]] +=== Duplicate Finder configuration Duplicate finder is *enabled by default* and will run in the `verify` phase of your Maven build, but it will only take effect in your project if you add the `duplicate-finder-maven-plugin` to the `build` section of the projecst's `pom.xml`. diff --git a/docs/antora-playbook.yml b/docs/antora-playbook.yml new file mode 100644 index 00000000..9f43a57c --- /dev/null +++ b/docs/antora-playbook.yml @@ -0,0 +1,38 @@ +antora: + extensions: + - '@springio/antora-extensions/partial-build-extension' + - require: '@springio/antora-extensions/latest-version-extension' + - require: '@springio/antora-extensions/inject-collector-cache-config-extension' + - '@antora/collector-extension' + - '@antora/atlas-extension' + - require: '@springio/antora-extensions/root-component-extension' + root_component_name: 'cloud-circuitbreaker' +site: + title: Spring Cloud Circuitbreaker + url: https://docs.spring.io/spring-cloud-circuitbreaker/reference/ +content: + sources: + - url: ./.. + branches: HEAD + start_path: docs + worktrees: true +asciidoc: + attributes: + page-stackoverflow-url: https://stackoverflow.com/tags/spring-cloud + page-pagination: '' + hide-uri-scheme: '@' + tabs-sync-option: '@' + chomp: 'all' + extensions: + - '@asciidoctor/tabs' + - '@springio/asciidoctor-extensions' + sourcemap: true +urls: + latest_version_segment: '' +runtime: + log: + failure_level: warn + format: pretty +ui: + bundle: + url: https://github.com/spring-io/antora-ui-spring/releases/download/v0.3.5/ui-bundle.zip diff --git a/docs/antora.yml b/docs/antora.yml new file mode 100644 index 00000000..05a55e3d --- /dev/null +++ b/docs/antora.yml @@ -0,0 +1,12 @@ +name: cloud-circuitbreaker +version: true +title: Spring-Cloud-CircuitBreaker +nav: + - modules/ROOT/nav.adoc +ext: + collector: + run: + command: ./mvnw --no-transfer-progress -B process-resources -Pdocs -pl docs -Dantora-maven-plugin.phase=none -Dgenerate-docs.phase=none -Dgenerate-readme.phase=none -Dgenerate-cloud-resources.phase=none -Dmaven-dependency-plugin-for-docs.phase=none -Dmaven-dependency-plugin-for-docs-classes.phase=none -DskipTests + local: true + scan: + dir: ./target/classes/antora-resources/ diff --git a/docs/modules/ROOT/nav.adoc b/docs/modules/ROOT/nav.adoc new file mode 100644 index 00000000..a48ba711 --- /dev/null +++ b/docs/modules/ROOT/nav.adoc @@ -0,0 +1,11 @@ +* xref:index.adoc[Introduction] +* xref:spring-cloud-circuitbreaker-resilience4j.adoc[] +** xref:spring-cloud-circuitbreaker-resilience4j/starters.adoc[] +** xref:spring-cloud-circuitbreaker-resilience4j/default-configuration.adoc[] +** xref:spring-cloud-circuitbreaker-resilience4j/specific-circuit-breaker-configuration.adoc[] +** xref:spring-cloud-circuitbreaker-resilience4j/circuit-breaker-properties-configuration.adoc[] +** xref:spring-cloud-circuitbreaker-resilience4j/bulkhead-pattern-supporting.adoc[] +** xref:spring-cloud-circuitbreaker-resilience4j/specific-bulkhead-configuration.adoc[] +** xref:spring-cloud-circuitbreaker-resilience4j/bulkhead-properties-configuration.adoc[] +** xref:spring-cloud-circuitbreaker-resilience4j/collecting-metrics.adoc[] +* xref:spring-cloud-circuitbreaker-spring-retry.adoc[] diff --git a/docs/src/main/asciidoc/_attributes.adoc b/docs/modules/ROOT/pages/_attributes.adoc similarity index 90% rename from docs/src/main/asciidoc/_attributes.adoc rename to docs/modules/ROOT/pages/_attributes.adoc index efac1de1..a724317b 100644 --- a/docs/src/main/asciidoc/_attributes.adoc +++ b/docs/modules/ROOT/pages/_attributes.adoc @@ -1,8 +1,6 @@ :doctype: book :idprefix: :idseparator: - -:toc: left -:toclevels: 4 :tabsize: 4 :numbered: :sectanchors: diff --git a/docs/modules/ROOT/pages/index.adoc b/docs/modules/ROOT/pages/index.adoc new file mode 100644 index 00000000..012c13eb --- /dev/null +++ b/docs/modules/ROOT/pages/index.adoc @@ -0,0 +1 @@ +include::spring-cloud-circuitbreaker.adoc[] \ No newline at end of file diff --git a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j.adoc b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j.adoc new file mode 100644 index 00000000..28d346c2 --- /dev/null +++ b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j.adoc @@ -0,0 +1,4 @@ +[[configuring-resilience4j-circuit-breakers]] += Configuring Resilience4J Circuit Breakers +:page-section-summary-toc: 1 + diff --git a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/bulkhead-pattern-supporting.adoc b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/bulkhead-pattern-supporting.adoc new file mode 100644 index 00000000..ba915f29 --- /dev/null +++ b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/bulkhead-pattern-supporting.adoc @@ -0,0 +1,30 @@ +[[bulkhead-pattern-supporting]] += Bulkhead pattern supporting + +If `resilience4j-bulkhead` is on the classpath, Spring Cloud CircuitBreaker will wrap all methods with a Resilience4j Bulkhead. +You can disable the Resilience4j Bulkhead by setting `spring.cloud.circuitbreaker.bulkhead.resilience4j.enabled` to `false`. + +Spring Cloud CircuitBreaker Resilience4j provides two implementation of bulkhead pattern: + +* a `SemaphoreBulkhead` which uses Semaphores +* a `FixedThreadPoolBulkhead` which uses a bounded queue and a fixed thread pool. + +By default, Spring Cloud CircuitBreaker Resilience4j uses `FixedThreadPoolBulkhead`. To modify the default behavior to use `SemaphoreBulkhead` set the property `spring.cloud.circuitbreaker.resilience4j.enableSemaphoreDefaultBulkhead` to `true`. + +For more information on implementation +of Bulkhead patterns see the https://resilience4j.readme.io/docs/bulkhead[Resilience4j Bulkhead]. + +The `Customizer` can be used to provide a default `Bulkhead` and `ThreadPoolBulkhead` configuration. + +[source,java] +---- +@Bean +public Customizer defaultBulkheadCustomizer() { + return provider -> provider.configureDefault(id -> new Resilience4jBulkheadConfigurationBuilder() + .bulkheadConfig(BulkheadConfig.custom().maxConcurrentCalls(4).build()) + .threadPoolBulkheadConfig(ThreadPoolBulkheadConfig.custom().coreThreadPoolSize(1).maxThreadPoolSize(1).build()) + .build() +); +} +---- + diff --git a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/bulkhead-properties-configuration.adoc b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/bulkhead-properties-configuration.adoc new file mode 100644 index 00000000..b090465a --- /dev/null +++ b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/bulkhead-properties-configuration.adoc @@ -0,0 +1,22 @@ +[[bulkhead-properties-configuration]] += Bulkhead Properties Configuration +:page-section-summary-toc: 1 + +You can configure ThreadPoolBulkhead and SemaphoreBulkhead instances in your application's configuration properties file. +Property configuration has higher priority than Java `Customizer` configuration. + +[source] +---- +resilience4j.thread-pool-bulkhead: + instances: + backendA: + maxThreadPoolSize: 1 + coreThreadPoolSize: 1 +resilience4j.bulkhead: + instances: + backendB: + maxConcurrentCalls: 10 +---- + +For more inforamtion on the Resilience4j property configuration, see https://resilience4j.readme.io/docs/getting-started-3#configuration[Resilience4J Spring Boot 2 Configuration]. + diff --git a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/circuit-breaker-properties-configuration.adoc b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/circuit-breaker-properties-configuration.adoc new file mode 100644 index 00000000..c440d7f9 --- /dev/null +++ b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/circuit-breaker-properties-configuration.adoc @@ -0,0 +1,86 @@ +[[circuit-breaker-properties-configuration]] += Circuit Breaker Properties Configuration + +You can configure `CircuitBreaker` and `TimeLimiter` configs or instances in your application's configuration properties file. +Property configuration has higher priority than Java `Customizer` configuration. + +Descending priority from top to bottom. + +* Method(id) config - on specific method or operation +* Service(group) config - on specific application service or operations +* Global default config + +[source,java] +---- +ReactiveResilience4JCircuitBreakerFactory.create(String id, String groupName) +Resilience4JCircuitBreakerFactory.create(String id, String groupName) +---- + +[[global-default-properties-configuration]] +== Global Default Properties Configuration +[source] +---- +resilience4j.circuitbreaker: + configs: + default: + registerHealthIndicator: true + slidingWindowSize: 50 + +resilience4j.timelimiter: + configs: + default: + timeoutDuration: 5s + cancelRunningFuture: true +---- + +[[configs-properties-configuration]] +== Configs Properties Configuration +[source] +---- +resilience4j.circuitbreaker: + configs: + groupA: + registerHealthIndicator: true + slidingWindowSize: 200 + +resilience4j.timelimiter: + configs: + groupC: + timeoutDuration: 3s + cancelRunningFuture: true +---- + +[[instances-properties-configuration]] +== Instances Properties Configuration +[source] +---- +resilience4j.circuitbreaker: + instances: + backendA: + registerHealthIndicator: true + slidingWindowSize: 100 + backendB: + registerHealthIndicator: true + slidingWindowSize: 10 + permittedNumberOfCallsInHalfOpenState: 3 + slidingWindowType: TIME_BASED + recordFailurePredicate: io.github.robwin.exception.RecordFailurePredicate + +resilience4j.timelimiter: + instances: + backendA: + timeoutDuration: 2s + cancelRunningFuture: true + backendB: + timeoutDuration: 1s + cancelRunningFuture: false +---- + + +* `ReactiveResilience4JCircuitBreakerFactory.create("backendA")` or `Resilience4JCircuitBreakerFactory.create("backendA")` will apply `instances backendA properties` +* `ReactiveResilience4JCircuitBreakerFactory.create("backendA", "groupA")` or `Resilience4JCircuitBreakerFactory.create("backendA", "groupA")` will apply `instances backendA properties` +* `ReactiveResilience4JCircuitBreakerFactory.create("backendC")` or `Resilience4JCircuitBreakerFactory.create("backendC")` will apply `global default properties` +* `ReactiveResilience4JCircuitBreakerFactory.create("backendC", "groupC")` or `Resilience4JCircuitBreakerFactory.create("backendC", "groupC")` will apply `global default CircuitBreaker properties and config groupC TimeLimiter properties` + +For more information on Resilience4j property configuration, see https://resilience4j.readme.io/docs/getting-started-3#configuration[Resilience4J Spring Boot 2 Configuration]. + diff --git a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/collecting-metrics.adoc b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/collecting-metrics.adoc new file mode 100644 index 00000000..7b999392 --- /dev/null +++ b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/collecting-metrics.adoc @@ -0,0 +1,9 @@ +[[collecting-metrics]] += Collecting Metrics +:page-section-summary-toc: 1 + +Spring Cloud Circuit Breaker Resilience4j includes auto-configuration to setup metrics collection as long as the right +dependencies are on the classpath. To enable metric collection you must include `org.springframework.boot:spring-boot-starter-actuator`, and `io.github.resilience4j:resilience4j-micrometer`. For more information on the metrics that +get produced when these dependencies are present, see the https://resilience4j.readme.io/docs/micrometer[Resilience4j documentation]. + +NOTE: You don't have to include `micrometer-core` directly as it is brought in by `spring-boot-starter-actuator` diff --git a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/default-configuration.adoc b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/default-configuration.adoc new file mode 100644 index 00000000..16e596b1 --- /dev/null +++ b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/default-configuration.adoc @@ -0,0 +1,49 @@ +[[default-configuration]] += Default Configuration + +To provide a default configuration for all of your circuit breakers create a `Customizer` bean that is passed a +`Resilience4JCircuitBreakerFactory` or `ReactiveResilience4JCircuitBreakerFactory`. +The `configureDefault` method can be used to provide a default configuration. + +[source,java] +---- +@Bean +public Customizer defaultCustomizer() { + return factory -> factory.configureDefault(id -> new Resilience4JConfigBuilder(id) + .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(4)).build()) + .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()) + .build()); +} +---- + +[[reactive-example]] +== Reactive Example + +[source,java] +---- +@Bean +public Customizer defaultCustomizer() { + return factory -> factory.configureDefault(id -> new Resilience4JConfigBuilder(id) + .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()) + .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(4)).build()).build()); +} +---- + +[[customizing-the-executorservice]] +== Customizing The ExecutorService +If you would like to configure the `ExecutorService` which executes the circuit breaker you can do so using the `Resilience4JCircuitBreakerFactory`. + +For example if you would like to use a context aware `ExecutorService` you could do the following. + +[source,java] +---- +@Bean +public Customizer defaultCustomizer() { + return factory -> { + ContextAwareScheduledThreadPoolExecutor executor = ContextAwareScheduledThreadPoolExecutor.newScheduledThreadPool().corePoolSize(5) + .build(); + factory.configureExecutorService(executor); + }; +} +---- + diff --git a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/specific-bulkhead-configuration.adoc b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/specific-bulkhead-configuration.adoc new file mode 100644 index 00000000..50cd308e --- /dev/null +++ b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/specific-bulkhead-configuration.adoc @@ -0,0 +1,46 @@ +[[specific-bulkhead-configuration]] += Specific Bulkhead Configuration + +Similarly to proving a default 'Bulkhead' or 'ThreadPoolBulkhead' configuration, you can create a `Customizer` bean this +is passed a `Resilience4jBulkheadProvider`. + +[source,java] +---- +@Bean +public Customizer slowBulkheadProviderCustomizer() { + return provider -> provider.configure(builder -> builder + .bulkheadConfig(BulkheadConfig.custom().maxConcurrentCalls(1).build()) + .threadPoolBulkheadConfig(ThreadPoolBulkheadConfig.ofDefaults()), "slowBulkhead"); +} +---- + +In addition to configuring the Bulkhead that is created you can also customize the bulkhead and thread pool bulkhead after they +have been created but before they are returned to caller. To do this you can use the `addBulkheadCustomizer` and `addThreadPoolBulkheadCustomizer` +methods. + +[[bulkhead-example]] +== Bulkhead Example + +[source,java] +---- +@Bean +public Customizer customizer() { + return provider -> provider.addBulkheadCustomizer(bulkhead -> bulkhead.getEventPublisher() + .onCallRejected(slowRejectedConsumer) + .onCallFinished(slowFinishedConsumer), "slowBulkhead"); +} +---- + +[[thread-pool-bulkhead-example]] +== Thread Pool Bulkhead Example + +[source,java] +---- +@Bean +public Customizer slowThreadPoolBulkheadCustomizer() { + return provider -> provider.addThreadPoolBulkheadCustomizer(threadPoolBulkhead -> threadPoolBulkhead.getEventPublisher() + .onCallRejected(slowThreadPoolRejectedConsumer) + .onCallFinished(slowThreadPoolFinishedConsumer), "slowThreadPoolBulkhead"); +} +---- + diff --git a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/specific-circuit-breaker-configuration.adoc b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/specific-circuit-breaker-configuration.adoc new file mode 100644 index 00000000..aacb0ba0 --- /dev/null +++ b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/specific-circuit-breaker-configuration.adoc @@ -0,0 +1,46 @@ +[[specific-circuit-breaker-configuration]] += Specific Circuit Breaker Configuration + +Similarly to providing a default configuration, you can create a `Customizer` bean this is passed a +`Resilience4JCircuitBreakerFactory` or `ReactiveResilience4JCircuitBreakerFactory`. + +[source,java] +---- +@Bean +public Customizer slowCustomizer() { + return factory -> factory.configure(builder -> builder.circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()) + .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(2)).build()), "slow"); +} +---- + +In addition to configuring the circuit breaker that is created you can also customize the circuit breaker after it has been created but before it is returned to the caller. +To do this you can use the `addCircuitBreakerCustomizer` +method. +This can be useful for adding event handlers to Resilience4J circuit breakers. + +[source,java] +---- +@Bean +public Customizer slowCustomizer() { + return factory -> factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker.getEventPublisher() + .onError(normalFluxErrorConsumer).onSuccess(normalFluxSuccessConsumer), "normalflux"); +} +---- + +[[reactive-example]] +== Reactive Example + +[source,java] +---- +@Bean +public Customizer slowCustomizer() { + return factory -> { + factory.configure(builder -> builder + .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(2)).build()) + .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()), "slow", "slowflux"); + factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker.getEventPublisher() + .onError(normalFluxErrorConsumer).onSuccess(normalFluxSuccessConsumer), "normalflux"); + }; +} +---- + diff --git a/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/starters.adoc b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/starters.adoc new file mode 100644 index 00000000..6f14a311 --- /dev/null +++ b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-resilience4j/starters.adoc @@ -0,0 +1,16 @@ +[[starters]] += Starters +:page-section-summary-toc: 1 + +There are two starters for the Resilience4J implementations, one for reactive applications and one for non-reactive applications. + +* `org.springframework.cloud:spring-cloud-starter-circuitbreaker-resilience4j` - non-reactive applications +* `org.springframework.cloud:spring-cloud-starter-circuitbreaker-reactor-resilience4j` - reactive applications + +[[auto-configuration]] +== Auto-Configuration +:page-section-summary-toc: 1 + +You can disable the Resilience4J auto-configuration by setting +`spring.cloud.circuitbreaker.resilience4j.enabled` to `false`. + diff --git a/docs/src/main/asciidoc/spring-cloud-circuitbreaker-spring-retry.adoc b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-spring-retry.adoc similarity index 92% rename from docs/src/main/asciidoc/spring-cloud-circuitbreaker-spring-retry.adoc rename to docs/modules/ROOT/pages/spring-cloud-circuitbreaker-spring-retry.adoc index 8ecea142..257b155a 100644 --- a/docs/src/main/asciidoc/spring-cloud-circuitbreaker-spring-retry.adoc +++ b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker-spring-retry.adoc @@ -1,4 +1,5 @@ -=== Configuring Spring Retry Circuit Breakers +[[configuring-spring-retry-circuit-breakers]] += Configuring Spring Retry Circuit Breakers Spring Retry provides declarative retry support for Spring applications. A subset of the project includes the ability to implement circuit breaker functionality. @@ -9,13 +10,13 @@ All circuit breakers created using Spring Retry will be created using the `Circu https://github.com/spring-projects/spring-retry/blob/master/src/main/java/org/springframework/retry/support/DefaultRetryState.java[`DefaultRetryState`]. Both of these classes can be configured using `SpringRetryConfigBuilder`. -==== Default Configuration +[[default-configuration]] +== Default Configuration To provide a default configuration for all of your circuit breakers create a `Customizer` bean that is passed a `SpringRetryCircuitBreakerFactory`. The `configureDefault` method can be used to provide a default configuration. -==== [source,java] ---- @Bean @@ -24,14 +25,13 @@ public Customizer defaultCustomizer() { .retryPolicy(new TimeoutRetryPolicy()).build()); } ---- -==== -==== Specific Circuit Breaker Configuration +[[specific-circuit-breaker-configuration]] +== Specific Circuit Breaker Configuration Similarly to providing a default configuration, you can create a `Customizer` bean this is passed a `SpringRetryCircuitBreakerFactory`. -==== [source,java] ---- @Bean @@ -39,14 +39,12 @@ public Customizer slowCustomizer() { return factory -> factory.configure(builder -> builder.retryPolicy(new SimpleRetryPolicy(1)).build(), "slow"); } ---- -==== In addition to configuring the circuit breaker that is created you can also customize the circuit breaker after it has been created but before it is returned to the caller. To do this you can use the `addRetryTemplateCustomizers` method. This can be useful for adding event handlers to the `RetryTemplate`. -==== [source,java] ---- @Bean @@ -70,4 +68,3 @@ public Customizer slowCustomizer() { })); } ---- -==== diff --git a/docs/src/main/asciidoc/spring-cloud-circuitbreaker.adoc b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker.adoc similarity index 52% rename from docs/src/main/asciidoc/spring-cloud-circuitbreaker.adoc rename to docs/modules/ROOT/pages/spring-cloud-circuitbreaker.adoc index 94fe02a1..342d9c96 100755 --- a/docs/src/main/asciidoc/spring-cloud-circuitbreaker.adoc +++ b/docs/modules/ROOT/pages/spring-cloud-circuitbreaker.adoc @@ -1,5 +1,6 @@ +[[spring-cloud-circuit-breaker]] = Spring Cloud Circuit Breaker -include::_attributes.adoc[] +:page-section-summary-toc: 1 *{spring-cloud-version}* @@ -9,14 +10,5 @@ The Spring Cloud CircuitBreaker project contains implementations for Resilience4 The APIs implemented in Spring Cloud CircuitBreaker live in Spring Cloud Commons. The usage documentation for these APIs are located in the https://docs.spring.io/spring-cloud-commons/docs/current/reference/html/#spring-cloud-circuit-breaker[Spring Cloud Commons documentation]. -include::spring-cloud-circuitbreaker-resilience4j.adoc[] -include::spring-cloud-circuitbreaker-spring-retry.adoc[] -== Building - -include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/docs/modules/ROOT/partials/building.adoc[] - -== Contributing - -include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/docs/modules/ROOT/partials/contributing.adoc[] diff --git a/docs/pom.xml b/docs/pom.xml index 98e1a92a..a27acefb 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -3,21 +3,20 @@ xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - spring-cloud-circuitbreaker org.springframework.cloud + spring-cloud-circuitbreaker 3.1.0-SNAPSHOT 4.0.0 spring-cloud-circuitbreaker-docs - pom + jar Spring Cloud CircuitBreaker Docs - Spring Cloud Docs + Spring Cloud CircuitBreaker Docs spring-cloud-circuitbreaker ${basedir}/.. spring.cloud.circuit.* - deploy none @@ -42,6 +41,12 @@ docs + + + src/main/antora/resources/antora-resources + true + + pl.project13.maven @@ -60,8 +65,12 @@ exec-maven-plugin - org.asciidoctor - asciidoctor-maven-plugin + io.spring.maven.antora + antora-component-version-maven-plugin + + + io.spring.maven.antora + antora-maven-plugin org.apache.maven.plugins diff --git a/docs/src/main/antora/resources/antora-resources/antora.yml b/docs/src/main/antora/resources/antora-resources/antora.yml new file mode 100644 index 00000000..9148923f --- /dev/null +++ b/docs/src/main/antora/resources/antora-resources/antora.yml @@ -0,0 +1,20 @@ +version: @antora-component.version@ +prerelease: @antora-component.prerelease@ + +asciidoc: + attributes: + attribute-missing: 'warn' + chomp: 'all' + project-root: @maven.multiModuleProjectDirectory@ + github-repo: @docs.main@ + github-raw: https://raw.githubusercontent.com/spring-cloud/@docs.main@/@github-tag@ + github-code: https://github.com/spring-cloud/@docs.main@/tree/@github-tag@ + github-issues: https://github.com/spring-cloud/@docs.main@/issues/ + github-wiki: https://github.com/spring-cloud/@docs.main@/wiki + spring-cloud-version: @project.version@ + github-tag: @github-tag@ + version-type: @version-type@ + docs-url: https://docs.spring.io/@docs.main@/docs/@project.version@ + raw-docs-url: https://raw.githubusercontent.com/spring-cloud/@docs.main@/@github-tag@ + project-version: @project.version@ + project-name: @docs.main@ diff --git a/docs/src/main/asciidoc/README.adoc b/docs/src/main/asciidoc/README.adoc index 4f2f911b..8668d0b4 100644 --- a/docs/src/main/asciidoc/README.adoc +++ b/docs/src/main/asciidoc/README.adoc @@ -1,3 +1,14 @@ include::_attributes.adoc[] include::spring-cloud-circuitbreaker.adoc[] + + +[[building]] +== Building + +include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/docs/modules/ROOT/partials/building.adoc[] + +[[contributing]] +== Contributing + +include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/docs/modules/ROOT/partials/contributing.adoc[] \ No newline at end of file diff --git a/docs/src/main/asciidoc/index.adoc b/docs/src/main/asciidoc/index.adoc deleted file mode 100644 index 2bb64c7b..00000000 --- a/docs/src/main/asciidoc/index.adoc +++ /dev/null @@ -1 +0,0 @@ -include::spring-cloud-circuitbreaker.adoc[] diff --git a/docs/src/main/asciidoc/spring-cloud-circuitbreaker-resilience4j.adoc b/docs/src/main/asciidoc/spring-cloud-circuitbreaker-resilience4j.adoc deleted file mode 100644 index 95d07115..00000000 --- a/docs/src/main/asciidoc/spring-cloud-circuitbreaker-resilience4j.adoc +++ /dev/null @@ -1,313 +0,0 @@ -=== Configuring Resilience4J Circuit Breakers - -==== Starters - -There are two starters for the Resilience4J implementations, one for reactive applications and one for non-reactive applications. - -* `org.springframework.cloud:spring-cloud-starter-circuitbreaker-resilience4j` - non-reactive applications -* `org.springframework.cloud:spring-cloud-starter-circuitbreaker-reactor-resilience4j` - reactive applications - -==== Auto-Configuration -You can disable the Resilience4J auto-configuration by setting -`spring.cloud.circuitbreaker.resilience4j.enabled` to `false`. - -==== Default Configuration - -To provide a default configuration for all of your circuit breakers create a `Customizer` bean that is passed a -`Resilience4JCircuitBreakerFactory` or `ReactiveResilience4JCircuitBreakerFactory`. -The `configureDefault` method can be used to provide a default configuration. - -==== -[source,java] ----- -@Bean -public Customizer defaultCustomizer() { - return factory -> factory.configureDefault(id -> new Resilience4JConfigBuilder(id) - .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(4)).build()) - .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()) - .build()); -} ----- -==== - -===== Reactive Example - -==== -[source,java] ----- -@Bean -public Customizer defaultCustomizer() { - return factory -> factory.configureDefault(id -> new Resilience4JConfigBuilder(id) - .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()) - .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(4)).build()).build()); -} ----- -==== - -===== Customizing The ExecutorService -If you would like to configure the `ExecutorService` which executes the circuit breaker you can do so using the `Resilience4JCircuitBreakerFactory`. - -For example if you would like to use a context aware `ExecutorService` you could do the following. - -==== -[source,java] ----- -@Bean -public Customizer defaultCustomizer() { - return factory -> { - ContextAwareScheduledThreadPoolExecutor executor = ContextAwareScheduledThreadPoolExecutor.newScheduledThreadPool().corePoolSize(5) - .build(); - factory.configureExecutorService(executor); - }; -} ----- -==== - -==== Specific Circuit Breaker Configuration - -Similarly to providing a default configuration, you can create a `Customizer` bean this is passed a -`Resilience4JCircuitBreakerFactory` or `ReactiveResilience4JCircuitBreakerFactory`. - -==== -[source,java] ----- -@Bean -public Customizer slowCustomizer() { - return factory -> factory.configure(builder -> builder.circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()) - .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(2)).build()), "slow"); -} ----- -==== - -In addition to configuring the circuit breaker that is created you can also customize the circuit breaker after it has been created but before it is returned to the caller. -To do this you can use the `addCircuitBreakerCustomizer` -method. -This can be useful for adding event handlers to Resilience4J circuit breakers. - -==== -[source,java] ----- -@Bean -public Customizer slowCustomizer() { - return factory -> factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker.getEventPublisher() - .onError(normalFluxErrorConsumer).onSuccess(normalFluxSuccessConsumer), "normalflux"); -} ----- -==== - -===== Reactive Example - -==== -[source,java] ----- -@Bean -public Customizer slowCustomizer() { - return factory -> { - factory.configure(builder -> builder - .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(2)).build()) - .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()), "slow", "slowflux"); - factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker.getEventPublisher() - .onError(normalFluxErrorConsumer).onSuccess(normalFluxSuccessConsumer), "normalflux"); - }; -} ----- -==== - -==== Circuit Breaker Properties Configuration - -You can configure `CircuitBreaker` and `TimeLimiter` configs or instances in your application's configuration properties file. -Property configuration has higher priority than Java `Customizer` configuration. - -Descending priority from top to bottom. - -* Method(id) config - on specific method or operation -* Service(group) config - on specific application service or operations -* Global default config - -==== -[source,java] ----- -ReactiveResilience4JCircuitBreakerFactory.create(String id, String groupName) -Resilience4JCircuitBreakerFactory.create(String id, String groupName) ----- -==== - -===== Global Default Properties Configuration -==== -[source] ----- -resilience4j.circuitbreaker: - configs: - default: - registerHealthIndicator: true - slidingWindowSize: 50 - -resilience4j.timelimiter: - configs: - default: - timeoutDuration: 5s - cancelRunningFuture: true ----- -==== - -===== Configs Properties Configuration -==== -[source] ----- -resilience4j.circuitbreaker: - configs: - groupA: - registerHealthIndicator: true - slidingWindowSize: 200 - -resilience4j.timelimiter: - configs: - groupC: - timeoutDuration: 3s - cancelRunningFuture: true ----- -==== - -===== Instances Properties Configuration -==== -[source] ----- -resilience4j.circuitbreaker: - instances: - backendA: - registerHealthIndicator: true - slidingWindowSize: 100 - backendB: - registerHealthIndicator: true - slidingWindowSize: 10 - permittedNumberOfCallsInHalfOpenState: 3 - slidingWindowType: TIME_BASED - recordFailurePredicate: io.github.robwin.exception.RecordFailurePredicate - -resilience4j.timelimiter: - instances: - backendA: - timeoutDuration: 2s - cancelRunningFuture: true - backendB: - timeoutDuration: 1s - cancelRunningFuture: false ----- -==== - - -* `ReactiveResilience4JCircuitBreakerFactory.create("backendA")` or `Resilience4JCircuitBreakerFactory.create("backendA")` will apply `instances backendA properties` -* `ReactiveResilience4JCircuitBreakerFactory.create("backendA", "groupA")` or `Resilience4JCircuitBreakerFactory.create("backendA", "groupA")` will apply `instances backendA properties` -* `ReactiveResilience4JCircuitBreakerFactory.create("backendC")` or `Resilience4JCircuitBreakerFactory.create("backendC")` will apply `global default properties` -* `ReactiveResilience4JCircuitBreakerFactory.create("backendC", "groupC")` or `Resilience4JCircuitBreakerFactory.create("backendC", "groupC")` will apply `global default CircuitBreaker properties and config groupC TimeLimiter properties` - -For more information on Resilience4j property configuration, see https://resilience4j.readme.io/docs/getting-started-3#configuration[Resilience4J Spring Boot 2 Configuration]. - -==== Bulkhead pattern supporting -If `resilience4j-bulkhead` is on the classpath, Spring Cloud CircuitBreaker will wrap all methods with a Resilience4j Bulkhead. -You can disable the Resilience4j Bulkhead by setting `spring.cloud.circuitbreaker.bulkhead.resilience4j.enabled` to `false`. - -Spring Cloud CircuitBreaker Resilience4j provides two implementation of bulkhead pattern: - -* a `SemaphoreBulkhead` which uses Semaphores -* a `FixedThreadPoolBulkhead` which uses a bounded queue and a fixed thread pool. - -By default, Spring Cloud CircuitBreaker Resilience4j uses `FixedThreadPoolBulkhead`. To modify the default behavior to use `SemaphoreBulkhead` set the property `spring.cloud.circuitbreaker.resilience4j.enableSemaphoreDefaultBulkhead` to `true`. - -For more information on implementation -of Bulkhead patterns see the https://resilience4j.readme.io/docs/bulkhead[Resilience4j Bulkhead]. - -The `Customizer` can be used to provide a default `Bulkhead` and `ThreadPoolBulkhead` configuration. - -==== -[source,java] ----- -@Bean -public Customizer defaultBulkheadCustomizer() { - return provider -> provider.configureDefault(id -> new Resilience4jBulkheadConfigurationBuilder() - .bulkheadConfig(BulkheadConfig.custom().maxConcurrentCalls(4).build()) - .threadPoolBulkheadConfig(ThreadPoolBulkheadConfig.custom().coreThreadPoolSize(1).maxThreadPoolSize(1).build()) - .build() -); -} ----- -==== - -==== Specific Bulkhead Configuration - -Similarly to proving a default 'Bulkhead' or 'ThreadPoolBulkhead' configuration, you can create a `Customizer` bean this -is passed a `Resilience4jBulkheadProvider`. - -==== -[source,java] ----- -@Bean -public Customizer slowBulkheadProviderCustomizer() { - return provider -> provider.configure(builder -> builder - .bulkheadConfig(BulkheadConfig.custom().maxConcurrentCalls(1).build()) - .threadPoolBulkheadConfig(ThreadPoolBulkheadConfig.ofDefaults()), "slowBulkhead"); -} ----- -==== - -In addition to configuring the Bulkhead that is created you can also customize the bulkhead and thread pool bulkhead after they -have been created but before they are returned to caller. To do this you can use the `addBulkheadCustomizer` and `addThreadPoolBulkheadCustomizer` -methods. - -===== Bulkhead Example - -==== -[source,java] ----- -@Bean -public Customizer customizer() { - return provider -> provider.addBulkheadCustomizer(bulkhead -> bulkhead.getEventPublisher() - .onCallRejected(slowRejectedConsumer) - .onCallFinished(slowFinishedConsumer), "slowBulkhead"); -} ----- -==== - -===== Thread Pool Bulkhead Example - -==== -[source,java] ----- -@Bean -public Customizer slowThreadPoolBulkheadCustomizer() { - return provider -> provider.addThreadPoolBulkheadCustomizer(threadPoolBulkhead -> threadPoolBulkhead.getEventPublisher() - .onCallRejected(slowThreadPoolRejectedConsumer) - .onCallFinished(slowThreadPoolFinishedConsumer), "slowThreadPoolBulkhead"); -} ----- -==== - -==== Bulkhead Properties Configuration - -You can configure ThreadPoolBulkhead and SemaphoreBulkhead instances in your application's configuration properties file. -Property configuration has higher priority than Java `Customizer` configuration. - -==== -[source] ----- -resilience4j.thread-pool-bulkhead: - instances: - backendA: - maxThreadPoolSize: 1 - coreThreadPoolSize: 1 -resilience4j.bulkhead: - instances: - backendB: - maxConcurrentCalls: 10 ----- -==== - -For more inforamtion on the Resilience4j property configuration, see https://resilience4j.readme.io/docs/getting-started-3#configuration[Resilience4J Spring Boot 2 Configuration]. - -==== Collecting Metrics - -Spring Cloud Circuit Breaker Resilience4j includes auto-configuration to setup metrics collection as long as the right -dependencies are on the classpath. To enable metric collection you must include `org.springframework.boot:spring-boot-starter-actuator`, and `io.github.resilience4j:resilience4j-micrometer`. For more information on the metrics that -get produced when these dependencies are present, see the https://resilience4j.readme.io/docs/micrometer[Resilience4j documentation]. - -NOTE: You don't have to include `micrometer-core` directly as it is brought in by `spring-boot-starter-actuator`