├── .gitignore ├── .mvn ├── jvm.config ├── maven.config └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── .settings.xml ├── LICENSE.txt ├── README.md ├── grafana ├── config │ └── provisioning │ │ ├── dashboards │ │ ├── Resilience4JDashboard-1571775123060.json │ │ └── dashboard.yml │ │ └── datasources │ │ └── datasource.yml ├── docker-compose.yml └── prometheus │ └── prometheus.yml ├── mvnw ├── mvnw.cmd ├── pom.xml ├── spring-cloud-circuitbreaker-demo-reactive-resilience4j ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── springframework │ │ │ └── cloud │ │ │ └── circuitbreaker │ │ │ └── demo │ │ │ └── reactiveresilience4jcircuitbreakerdemo │ │ │ ├── DemoController.java │ │ │ ├── HttpBinService.java │ │ │ └── ReactiveResilience4JCircuitbreakerDemoApplication.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── org │ └── springframework │ └── cloud │ └── circuitbreaker │ └── demo │ └── reactiveresilience4jcircuitbreakerdemo │ └── ReactiveResilience4JCircuitbreakerDemoApplicationTests.java ├── spring-cloud-circuitbreaker-demo-reactive ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── springframework │ │ │ └── cloud │ │ │ └── circuitbreaker │ │ │ └── demo │ │ │ └── reactive │ │ │ ├── CompletableFutureDemoController.java │ │ │ ├── CompletableFutureHttpBinService.java │ │ │ ├── RxJava2DemoController.java │ │ │ ├── RxJava2HttpBinService.java │ │ │ └── SpringCloudCircuitbreakerDemoReactiveApplication.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── org │ └── springframework │ └── cloud │ └── circuitbreaker │ └── demo │ └── reactive │ └── SpringCloudCircuitbreakerDemoReactiveApplicationTests.java └── spring-cloud-circuitbreaker-demo-resilience4j ├── .gitignore ├── pom.xml └── src ├── main ├── java │ └── org │ │ └── springframework │ │ └── cloud │ │ └── circuitbreaker │ │ └── demo │ │ └── resilience4jcircuitbreakerdemo │ │ ├── DemoController.java │ │ ├── HttpBinService.java │ │ └── Resilience4JCircuitbreakerDemoApplication.java └── resources │ └── application.yml └── test └── java └── org └── springframework └── cloud └── circuitbreaker └── demo └── resilience4jcircuitbreakerdemo └── Resilience4JCircuitbreakerDemoApplicationTests.java /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /.mvn/jvm.config: -------------------------------------------------------------------------------- 1 | -Xmx1024m -XX:CICompilerCount=1 -XX:TieredStopAtLevel=1 -Djava.security.egd=file:/dev/./urandom -------------------------------------------------------------------------------- /.mvn/maven.config: -------------------------------------------------------------------------------- 1 | -DaltSnapshotDeploymentRepository=repo.spring.io::default::https://repo.spring.io/libs-snapshot-local -P spring 2 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-circuitbreaker-demo/faafc24da64df3a6a2b2bc2dffaf68342839a626/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip -------------------------------------------------------------------------------- /.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | repo.spring.io 6 | ${env.CI_DEPLOY_USERNAME} 7 | ${env.CI_DEPLOY_PASSWORD} 8 | 9 | 10 | 11 | 12 | 18 | spring 19 | true 20 | 21 | 22 | spring-snapshots 23 | Spring Snapshots 24 | https://repo.spring.io/libs-snapshot-local 25 | 26 | true 27 | 28 | 29 | 30 | spring-milestones 31 | Spring Milestones 32 | https://repo.spring.io/libs-milestone-local 33 | 34 | false 35 | 36 | 37 | 38 | spring-releases 39 | Spring Releases 40 | https://repo.spring.io/release 41 | 42 | false 43 | 44 | 45 | 46 | 47 | 48 | spring-snapshots 49 | Spring Snapshots 50 | https://repo.spring.io/libs-snapshot-local 51 | 52 | true 53 | 54 | 55 | 56 | spring-milestones 57 | Spring Milestones 58 | https://repo.spring.io/libs-milestone-local 59 | 60 | false 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | https://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | https://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # About 2 | 3 | This repo contains a collection of apps that demonstrate how to using Spring Cloud CircuitBreaker 4 | with various circuit breaker implementations. 5 | 6 | # Non-Reactive Samples 7 | 8 | The non-reactive example can be found in `spring-cloud-circuitbreaker-resilience4j`. 9 | 10 | When these apps are running there are two endpoints available for testing 11 | 12 | 1. `/get` - This endpoint makes a request to [httpbin's `/get` endpoint](http://httpbin.org/#/HTTP_Methods/get_get) and returns the data 13 | 14 | 2. `/delay/{seconds}` - This endpoint makes a request to [httpbin's `/delay` endpoint](http://httpbin.org/#/Dynamic_data/get_delay__delay_) passing 15 | the delay in the response in seconds. Since this request can take a significant amount 16 | of time it is wrapped in a circuit breaker. If the `seconds` parameter is greater than or 17 | equal to 3 the circuit breaker will time out and return the response `{"hello": "world"}`. 18 | 19 | # Reactive Samples 20 | 21 | There are two reactive samples in this repo, `spring-cloud-circuitbreaker-demo-reactive` and `spring-cloud-circuibreaker-demo-reactive-resilience4j`. 22 | 23 | ## Resilience4J Reactive Samples 24 | 25 | Both of these samples contain the same two endpoints as the non-reactive samples 26 | (which in this case return a `Mono`), but also 27 | contain an additional endpoint to demonstrate the use of `Flux`. This endpoint can be 28 | accessed by calling `/fluxdelay/{seconds}`. It has the same functionality as `/delay/{seconds}` 29 | but the fallback returns a `Flux`. 30 | 31 | ## spring-cloud-circuitbreaker-demo-reactive 32 | 33 | This sample demonstrates how to using Spring Cloud CircuitBreaker with reactive types from 34 | RxJava2 and CompletableFuture. There are four endpoints available for testing in this app 35 | 36 | 1. `/rxjava2/get` 37 | 2. `/rxjava2/delay/{seconds}` 38 | 3. `/completablefuture/get` 39 | 4. `/completablefuture/delay/{seconds}` 40 | 41 | Each of these have the same functionality as the other endpoints in the other apps. 42 | 43 | # Resilience4J and Metrics 44 | 45 | With Spring Cloud CircuitBreaker and Resilience4J you can easily collect metrics about 46 | the circuit breakers in your app. This is demoed in both `spring-cloud-circuitbreaker-demo-resilience4j` 47 | and `spring-cloud-circuitbreaker-demo-reactive-resilience4j`. You can see the metrics available 48 | by hitting `/actuator/metrics`. 49 | 50 | NOTE: The code wrapped by the circuit breaker needs to be executed before any metrics appear 51 | 52 | You can also have these metrics collected by Prometheus and visualized in Grafana. To demonstrate 53 | this, the repo contains a Docker Compose file that will start Prometheus and Grafana locally 54 | and scrape the metrics being surfaces at `/actuator/prometheus`. To see it in action 55 | 56 | 1. Start either `spring-cloud-circuitbreaker-demo-resilience4j` or `spring-cloud-circuitbreaker-demo-reactive-resilience4j`. 57 | 2. `cd` into the `grafana` directory in the root of the repo 58 | 3. Run `docker-compose up` 59 | 4. Go to http://localhost:3000 and login with the username `admin` and the password `admin` 60 | 5. There will be a datasource pointing to the docker container running Prometheus and dashboard already configured to visualize the Resilience4J metrics 61 | 6. Make some requests to the `/delay` endpoint. You can easily do this with a tool like `watch`. 62 | For example `watch -n 1 http :8080/delay/5`. 63 | 7. If you refresh the Grafana dashboard or set its automatic refresh you should see the graphs begin to change 64 | as requests are made. 65 | -------------------------------------------------------------------------------- /grafana/config/provisioning/dashboards/Resilience4JDashboard-1571775123060.json: -------------------------------------------------------------------------------- 1 | { 2 | "annotations": { 3 | "list": [ 4 | { 5 | "builtIn": 1, 6 | "datasource": "-- Grafana --", 7 | "enable": true, 8 | "hide": true, 9 | "iconColor": "rgba(0, 211, 255, 1)", 10 | "name": "Annotations & Alerts", 11 | "type": "dashboard" 12 | } 13 | ] 14 | }, 15 | "editable": true, 16 | "gnetId": null, 17 | "graphTooltip": 0, 18 | "id": 2, 19 | "links": [], 20 | "panels": [ 21 | { 22 | "aliasColors": {}, 23 | "bars": false, 24 | "dashLength": 10, 25 | "dashes": false, 26 | "datasource": null, 27 | "fill": 1, 28 | "fillGradient": 0, 29 | "gridPos": { 30 | "h": 8, 31 | "w": 12, 32 | "x": 0, 33 | "y": 0 34 | }, 35 | "id": 18, 36 | "legend": { 37 | "avg": false, 38 | "current": false, 39 | "max": false, 40 | "min": false, 41 | "show": true, 42 | "total": false, 43 | "values": false 44 | }, 45 | "lines": true, 46 | "linewidth": 1, 47 | "nullPointMode": "null", 48 | "options": { 49 | "dataLinks": [] 50 | }, 51 | "percentage": false, 52 | "pointradius": 2, 53 | "points": false, 54 | "renderer": "flot", 55 | "seriesOverrides": [], 56 | "spaceLength": 10, 57 | "stack": false, 58 | "steppedLine": false, 59 | "targets": [ 60 | { 61 | "expr": "resilience4j_circuitbreaker_state", 62 | "refId": "A" 63 | } 64 | ], 65 | "thresholds": [], 66 | "timeFrom": null, 67 | "timeRegions": [], 68 | "timeShift": null, 69 | "title": "resilience4j_circuitbreaker_state", 70 | "tooltip": { 71 | "shared": true, 72 | "sort": 0, 73 | "value_type": "individual" 74 | }, 75 | "type": "graph", 76 | "xaxis": { 77 | "buckets": null, 78 | "mode": "time", 79 | "name": null, 80 | "show": true, 81 | "values": [] 82 | }, 83 | "yaxes": [ 84 | { 85 | "format": "short", 86 | "label": null, 87 | "logBase": 1, 88 | "max": null, 89 | "min": null, 90 | "show": true 91 | }, 92 | { 93 | "format": "short", 94 | "label": null, 95 | "logBase": 1, 96 | "max": null, 97 | "min": null, 98 | "show": true 99 | } 100 | ], 101 | "yaxis": { 102 | "align": false, 103 | "alignLevel": null 104 | } 105 | }, 106 | { 107 | "aliasColors": {}, 108 | "bars": false, 109 | "dashLength": 10, 110 | "dashes": false, 111 | "datasource": null, 112 | "fill": 1, 113 | "fillGradient": 0, 114 | "gridPos": { 115 | "h": 8, 116 | "w": 12, 117 | "x": 12, 118 | "y": 0 119 | }, 120 | "id": 16, 121 | "legend": { 122 | "avg": false, 123 | "current": false, 124 | "max": false, 125 | "min": false, 126 | "show": true, 127 | "total": false, 128 | "values": false 129 | }, 130 | "lines": true, 131 | "linewidth": 1, 132 | "nullPointMode": "null", 133 | "options": { 134 | "dataLinks": [] 135 | }, 136 | "percentage": false, 137 | "pointradius": 2, 138 | "points": false, 139 | "renderer": "flot", 140 | "seriesOverrides": [], 141 | "spaceLength": 10, 142 | "stack": false, 143 | "steppedLine": false, 144 | "targets": [ 145 | { 146 | "expr": "resilience4j_circuitbreaker_slow_calls", 147 | "refId": "A" 148 | } 149 | ], 150 | "thresholds": [], 151 | "timeFrom": null, 152 | "timeRegions": [], 153 | "timeShift": null, 154 | "title": "resilience4j_circuitbreaker_slow_calls", 155 | "tooltip": { 156 | "shared": true, 157 | "sort": 0, 158 | "value_type": "individual" 159 | }, 160 | "type": "graph", 161 | "xaxis": { 162 | "buckets": null, 163 | "mode": "time", 164 | "name": null, 165 | "show": true, 166 | "values": [] 167 | }, 168 | "yaxes": [ 169 | { 170 | "format": "short", 171 | "label": null, 172 | "logBase": 1, 173 | "max": null, 174 | "min": null, 175 | "show": true 176 | }, 177 | { 178 | "format": "short", 179 | "label": null, 180 | "logBase": 1, 181 | "max": null, 182 | "min": null, 183 | "show": true 184 | } 185 | ], 186 | "yaxis": { 187 | "align": false, 188 | "alignLevel": null 189 | } 190 | }, 191 | { 192 | "aliasColors": {}, 193 | "bars": false, 194 | "dashLength": 10, 195 | "dashes": false, 196 | "datasource": null, 197 | "fill": 1, 198 | "fillGradient": 0, 199 | "gridPos": { 200 | "h": 8, 201 | "w": 12, 202 | "x": 0, 203 | "y": 8 204 | }, 205 | "id": 14, 206 | "legend": { 207 | "avg": false, 208 | "current": false, 209 | "max": false, 210 | "min": false, 211 | "show": true, 212 | "total": false, 213 | "values": false 214 | }, 215 | "lines": true, 216 | "linewidth": 1, 217 | "nullPointMode": "null", 218 | "options": { 219 | "dataLinks": [] 220 | }, 221 | "percentage": false, 222 | "pointradius": 2, 223 | "points": false, 224 | "renderer": "flot", 225 | "seriesOverrides": [], 226 | "spaceLength": 10, 227 | "stack": false, 228 | "steppedLine": false, 229 | "targets": [ 230 | { 231 | "expr": "resilience4j_circuitbreaker_slow_call_rate", 232 | "refId": "A" 233 | } 234 | ], 235 | "thresholds": [], 236 | "timeFrom": null, 237 | "timeRegions": [], 238 | "timeShift": null, 239 | "title": "resilience4j_circuitbreaker_slow_call_rate", 240 | "tooltip": { 241 | "shared": true, 242 | "sort": 0, 243 | "value_type": "individual" 244 | }, 245 | "type": "graph", 246 | "xaxis": { 247 | "buckets": null, 248 | "mode": "time", 249 | "name": null, 250 | "show": true, 251 | "values": [] 252 | }, 253 | "yaxes": [ 254 | { 255 | "format": "short", 256 | "label": null, 257 | "logBase": 1, 258 | "max": null, 259 | "min": null, 260 | "show": true 261 | }, 262 | { 263 | "format": "short", 264 | "label": null, 265 | "logBase": 1, 266 | "max": null, 267 | "min": null, 268 | "show": true 269 | } 270 | ], 271 | "yaxis": { 272 | "align": false, 273 | "alignLevel": null 274 | } 275 | }, 276 | { 277 | "aliasColors": {}, 278 | "bars": false, 279 | "dashLength": 10, 280 | "dashes": false, 281 | "datasource": null, 282 | "fill": 1, 283 | "fillGradient": 0, 284 | "gridPos": { 285 | "h": 8, 286 | "w": 12, 287 | "x": 12, 288 | "y": 8 289 | }, 290 | "id": 12, 291 | "legend": { 292 | "avg": false, 293 | "current": false, 294 | "max": false, 295 | "min": false, 296 | "show": true, 297 | "total": false, 298 | "values": false 299 | }, 300 | "lines": true, 301 | "linewidth": 1, 302 | "nullPointMode": "null", 303 | "options": { 304 | "dataLinks": [] 305 | }, 306 | "percentage": false, 307 | "pointradius": 2, 308 | "points": false, 309 | "renderer": "flot", 310 | "seriesOverrides": [], 311 | "spaceLength": 10, 312 | "stack": false, 313 | "steppedLine": false, 314 | "targets": [ 315 | { 316 | "expr": "resilience4j_circuitbreaker_failure_rate", 317 | "refId": "A" 318 | } 319 | ], 320 | "thresholds": [], 321 | "timeFrom": null, 322 | "timeRegions": [], 323 | "timeShift": null, 324 | "title": "resilience4j_circuitbreaker_failure_rate", 325 | "tooltip": { 326 | "shared": true, 327 | "sort": 0, 328 | "value_type": "individual" 329 | }, 330 | "type": "graph", 331 | "xaxis": { 332 | "buckets": null, 333 | "mode": "time", 334 | "name": null, 335 | "show": true, 336 | "values": [] 337 | }, 338 | "yaxes": [ 339 | { 340 | "format": "short", 341 | "label": null, 342 | "logBase": 1, 343 | "max": null, 344 | "min": null, 345 | "show": true 346 | }, 347 | { 348 | "format": "short", 349 | "label": null, 350 | "logBase": 1, 351 | "max": null, 352 | "min": null, 353 | "show": true 354 | } 355 | ], 356 | "yaxis": { 357 | "align": false, 358 | "alignLevel": null 359 | } 360 | }, 361 | { 362 | "aliasColors": {}, 363 | "bars": false, 364 | "dashLength": 10, 365 | "dashes": false, 366 | "datasource": null, 367 | "fill": 1, 368 | "fillGradient": 0, 369 | "gridPos": { 370 | "h": 8, 371 | "w": 12, 372 | "x": 0, 373 | "y": 16 374 | }, 375 | "id": 10, 376 | "legend": { 377 | "avg": false, 378 | "current": false, 379 | "max": false, 380 | "min": false, 381 | "show": true, 382 | "total": false, 383 | "values": false 384 | }, 385 | "lines": true, 386 | "linewidth": 1, 387 | "nullPointMode": "null", 388 | "options": { 389 | "dataLinks": [] 390 | }, 391 | "percentage": false, 392 | "pointradius": 2, 393 | "points": false, 394 | "renderer": "flot", 395 | "seriesOverrides": [], 396 | "spaceLength": 10, 397 | "stack": false, 398 | "steppedLine": false, 399 | "targets": [ 400 | { 401 | "expr": "resilience4j_circuitbreaker_calls_total", 402 | "refId": "A" 403 | } 404 | ], 405 | "thresholds": [], 406 | "timeFrom": null, 407 | "timeRegions": [], 408 | "timeShift": null, 409 | "title": "resilience4j_circuitbreaker_calls_seconds_sum", 410 | "tooltip": { 411 | "shared": true, 412 | "sort": 0, 413 | "value_type": "individual" 414 | }, 415 | "type": "graph", 416 | "xaxis": { 417 | "buckets": null, 418 | "mode": "time", 419 | "name": null, 420 | "show": true, 421 | "values": [] 422 | }, 423 | "yaxes": [ 424 | { 425 | "format": "short", 426 | "label": null, 427 | "logBase": 1, 428 | "max": null, 429 | "min": null, 430 | "show": true 431 | }, 432 | { 433 | "format": "short", 434 | "label": null, 435 | "logBase": 1, 436 | "max": null, 437 | "min": null, 438 | "show": true 439 | } 440 | ], 441 | "yaxis": { 442 | "align": false, 443 | "alignLevel": null 444 | } 445 | }, 446 | { 447 | "aliasColors": {}, 448 | "bars": false, 449 | "dashLength": 10, 450 | "dashes": false, 451 | "datasource": null, 452 | "fill": 1, 453 | "fillGradient": 0, 454 | "gridPos": { 455 | "h": 8, 456 | "w": 12, 457 | "x": 12, 458 | "y": 16 459 | }, 460 | "id": 8, 461 | "legend": { 462 | "avg": false, 463 | "current": false, 464 | "max": false, 465 | "min": false, 466 | "show": true, 467 | "total": false, 468 | "values": false 469 | }, 470 | "lines": true, 471 | "linewidth": 1, 472 | "nullPointMode": "null", 473 | "options": { 474 | "dataLinks": [] 475 | }, 476 | "percentage": false, 477 | "pointradius": 2, 478 | "points": false, 479 | "renderer": "flot", 480 | "seriesOverrides": [], 481 | "spaceLength": 10, 482 | "stack": false, 483 | "steppedLine": false, 484 | "targets": [ 485 | { 486 | "expr": "resilience4j_circuitbreaker_calls_seconds_sum", 487 | "refId": "A" 488 | } 489 | ], 490 | "thresholds": [], 491 | "timeFrom": null, 492 | "timeRegions": [], 493 | "timeShift": null, 494 | "title": "resilience4j_circuitbreaker_calls_seconds_sum", 495 | "tooltip": { 496 | "shared": true, 497 | "sort": 0, 498 | "value_type": "individual" 499 | }, 500 | "type": "graph", 501 | "xaxis": { 502 | "buckets": null, 503 | "mode": "time", 504 | "name": null, 505 | "show": true, 506 | "values": [] 507 | }, 508 | "yaxes": [ 509 | { 510 | "format": "short", 511 | "label": null, 512 | "logBase": 1, 513 | "max": null, 514 | "min": null, 515 | "show": true 516 | }, 517 | { 518 | "format": "short", 519 | "label": null, 520 | "logBase": 1, 521 | "max": null, 522 | "min": null, 523 | "show": true 524 | } 525 | ], 526 | "yaxis": { 527 | "align": false, 528 | "alignLevel": null 529 | } 530 | }, 531 | { 532 | "aliasColors": {}, 533 | "bars": false, 534 | "dashLength": 10, 535 | "dashes": false, 536 | "datasource": null, 537 | "fill": 1, 538 | "fillGradient": 0, 539 | "gridPos": { 540 | "h": 8, 541 | "w": 12, 542 | "x": 0, 543 | "y": 24 544 | }, 545 | "id": 6, 546 | "legend": { 547 | "avg": false, 548 | "current": false, 549 | "max": false, 550 | "min": false, 551 | "show": true, 552 | "total": false, 553 | "values": false 554 | }, 555 | "lines": true, 556 | "linewidth": 1, 557 | "nullPointMode": "null", 558 | "options": { 559 | "dataLinks": [] 560 | }, 561 | "percentage": false, 562 | "pointradius": 2, 563 | "points": false, 564 | "renderer": "flot", 565 | "seriesOverrides": [], 566 | "spaceLength": 10, 567 | "stack": false, 568 | "steppedLine": false, 569 | "targets": [ 570 | { 571 | "expr": "resilience4j_circuitbreaker_calls_seconds_max", 572 | "refId": "A" 573 | } 574 | ], 575 | "thresholds": [], 576 | "timeFrom": null, 577 | "timeRegions": [], 578 | "timeShift": null, 579 | "title": "resilience4j_circuitbreaker_calls_seconds_max", 580 | "tooltip": { 581 | "shared": true, 582 | "sort": 0, 583 | "value_type": "individual" 584 | }, 585 | "type": "graph", 586 | "xaxis": { 587 | "buckets": null, 588 | "mode": "time", 589 | "name": null, 590 | "show": true, 591 | "values": [] 592 | }, 593 | "yaxes": [ 594 | { 595 | "format": "short", 596 | "label": null, 597 | "logBase": 1, 598 | "max": null, 599 | "min": null, 600 | "show": true 601 | }, 602 | { 603 | "format": "short", 604 | "label": null, 605 | "logBase": 1, 606 | "max": null, 607 | "min": null, 608 | "show": true 609 | } 610 | ], 611 | "yaxis": { 612 | "align": false, 613 | "alignLevel": null 614 | } 615 | }, 616 | { 617 | "aliasColors": {}, 618 | "bars": false, 619 | "dashLength": 10, 620 | "dashes": false, 621 | "datasource": null, 622 | "fill": 1, 623 | "fillGradient": 0, 624 | "gridPos": { 625 | "h": 8, 626 | "w": 12, 627 | "x": 12, 628 | "y": 24 629 | }, 630 | "id": 4, 631 | "legend": { 632 | "avg": false, 633 | "current": false, 634 | "max": false, 635 | "min": false, 636 | "show": true, 637 | "total": false, 638 | "values": false 639 | }, 640 | "lines": true, 641 | "linewidth": 1, 642 | "nullPointMode": "null", 643 | "options": { 644 | "dataLinks": [] 645 | }, 646 | "percentage": false, 647 | "pointradius": 2, 648 | "points": false, 649 | "renderer": "flot", 650 | "seriesOverrides": [], 651 | "spaceLength": 10, 652 | "stack": false, 653 | "steppedLine": false, 654 | "targets": [ 655 | { 656 | "expr": "resilience4j_circuitbreaker_calls_seconds_count", 657 | "refId": "A" 658 | } 659 | ], 660 | "thresholds": [], 661 | "timeFrom": null, 662 | "timeRegions": [], 663 | "timeShift": null, 664 | "title": "resilience4j_circuitbreaker_calls_seconds_count", 665 | "tooltip": { 666 | "shared": true, 667 | "sort": 0, 668 | "value_type": "individual" 669 | }, 670 | "type": "graph", 671 | "xaxis": { 672 | "buckets": null, 673 | "mode": "time", 674 | "name": null, 675 | "show": true, 676 | "values": [] 677 | }, 678 | "yaxes": [ 679 | { 680 | "format": "short", 681 | "label": null, 682 | "logBase": 1, 683 | "max": null, 684 | "min": null, 685 | "show": true 686 | }, 687 | { 688 | "format": "short", 689 | "label": null, 690 | "logBase": 1, 691 | "max": null, 692 | "min": null, 693 | "show": true 694 | } 695 | ], 696 | "yaxis": { 697 | "align": false, 698 | "alignLevel": null 699 | } 700 | }, 701 | { 702 | "aliasColors": {}, 703 | "bars": false, 704 | "dashLength": 10, 705 | "dashes": false, 706 | "datasource": null, 707 | "fill": 1, 708 | "fillGradient": 0, 709 | "gridPos": { 710 | "h": 9, 711 | "w": 12, 712 | "x": 0, 713 | "y": 32 714 | }, 715 | "id": 2, 716 | "legend": { 717 | "avg": false, 718 | "current": false, 719 | "max": false, 720 | "min": false, 721 | "show": true, 722 | "total": false, 723 | "values": false 724 | }, 725 | "lines": true, 726 | "linewidth": 1, 727 | "nullPointMode": "null", 728 | "options": { 729 | "dataLinks": [] 730 | }, 731 | "percentage": false, 732 | "pointradius": 2, 733 | "points": false, 734 | "renderer": "flot", 735 | "seriesOverrides": [], 736 | "spaceLength": 10, 737 | "stack": false, 738 | "steppedLine": false, 739 | "targets": [ 740 | { 741 | "expr": "resilience4j_circuitbreaker_buffered_calls", 742 | "refId": "A" 743 | } 744 | ], 745 | "thresholds": [], 746 | "timeFrom": null, 747 | "timeRegions": [], 748 | "timeShift": null, 749 | "title": "resilience4j_circuitbreaker_buffered_calls", 750 | "tooltip": { 751 | "shared": true, 752 | "sort": 0, 753 | "value_type": "individual" 754 | }, 755 | "type": "graph", 756 | "xaxis": { 757 | "buckets": null, 758 | "mode": "time", 759 | "name": null, 760 | "show": true, 761 | "values": [] 762 | }, 763 | "yaxes": [ 764 | { 765 | "format": "short", 766 | "label": null, 767 | "logBase": 1, 768 | "max": null, 769 | "min": null, 770 | "show": true 771 | }, 772 | { 773 | "format": "short", 774 | "label": null, 775 | "logBase": 1, 776 | "max": null, 777 | "min": null, 778 | "show": true 779 | } 780 | ], 781 | "yaxis": { 782 | "align": false, 783 | "alignLevel": null 784 | } 785 | } 786 | ], 787 | "schemaVersion": 20, 788 | "style": "dark", 789 | "tags": [], 790 | "templating": { 791 | "list": [] 792 | }, 793 | "time": { 794 | "from": "now-5m", 795 | "to": "now" 796 | }, 797 | "timepicker": {}, 798 | "timezone": "", 799 | "title": "Resilience4J Dashboard", 800 | "uid": "cT25vjTZz", 801 | "version": 9 802 | } -------------------------------------------------------------------------------- /grafana/config/provisioning/dashboards/dashboard.yml: -------------------------------------------------------------------------------- 1 | apiVersion: 1 2 | 3 | providers: 4 | - name: 'Prometheus' 5 | orgId: 1 6 | folder: '' 7 | type: file 8 | disableDeletion: false 9 | editable: true 10 | options: 11 | path: /etc/grafana/provisioning/dashboards -------------------------------------------------------------------------------- /grafana/config/provisioning/datasources/datasource.yml: -------------------------------------------------------------------------------- 1 | # config file version 2 | apiVersion: 1 3 | 4 | # list of datasources that should be deleted from the database 5 | deleteDatasources: 6 | - name: Prometheus 7 | orgId: 1 8 | 9 | # list of datasources to insert/update depending 10 | # whats available in the database 11 | datasources: 12 | # name of the datasource. Required 13 | - name: Prometheus 14 | # datasource type. Required 15 | type: prometheus 16 | # access mode. direct or proxy. Required 17 | access: proxy 18 | # org id. will default to orgId 1 if not specified 19 | orgId: 1 20 | # url 21 | url: http://prometheus:9090 22 | # database password, if used 23 | #password: 24 | # database user, if used 25 | #user: 26 | # database name, if used 27 | #database: 28 | # enable/disable basic auth 29 | #basicAuth: true 30 | # basic auth username 31 | #basicAuthUser: admin 32 | # basic auth password 33 | #basicAuthPassword: foobar 34 | # enable/disable with credentials headers 35 | #withCredentials: 36 | # mark as default datasource. Max one per org 37 | isDefault: true 38 | # fields that will be converted to json and stored in json_data 39 | jsonData: 40 | graphiteVersion: "1.1" 41 | tlsAuth: false 42 | tlsAuthWithCACert: false 43 | # json object of data that will be encrypted. 44 | # secureJsonData: 45 | # tlsCACert: "..." 46 | # tlsClientCert: "..." 47 | # tlsClientKey: "..." 48 | version: 1 49 | # allow users to edit datasources from the UI. 50 | editable: true -------------------------------------------------------------------------------- /grafana/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | services: 3 | prometheus: 4 | image: prom/prometheus 5 | volumes: 6 | - ./prometheus/:/etc/prometheus/ 7 | command: 8 | - '--config.file=/etc/prometheus/prometheus.yml' 9 | ports: 10 | - '9090:9090' 11 | grafana: 12 | image: grafana/grafana 13 | ports: 14 | - '3000:3000' 15 | volumes: 16 | - ./config/provisioning/:/etc/grafana/provisioning/ -------------------------------------------------------------------------------- /grafana/prometheus/prometheus.yml: -------------------------------------------------------------------------------- 1 | # my global config 2 | global: 3 | scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. 4 | evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. 5 | # scrape_timeout is set to the global default (10s). 6 | 7 | # Load rules once and periodically evaluate them according to the global 'evaluation_interval'. 8 | rule_files: 9 | # - "first_rules.yml" 10 | # - "second_rules.yml" 11 | 12 | # A scrape configuration containing exactly one endpoint to scrape: 13 | # Here it's Prometheus itself. 14 | scrape_configs: 15 | # The job name is added as a label `job=` to any timeseries scraped from this config. 16 | - job_name: 'prometheus' 17 | # metrics_path defaults to '/metrics' 18 | # scheme defaults to 'http'. 19 | static_configs: 20 | - targets: ['127.0.0.1:9090'] 21 | 22 | - job_name: 'spring-actuator' 23 | metrics_path: '/actuator/prometheus' 24 | scrape_interval: 5s 25 | static_configs: 26 | - targets: ['host.docker.internal:8080'] -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # 58 | # Look for the Apple JDKs first to preserve the existing behaviour, and then look 59 | # for the new JDKs provided by Oracle. 60 | # 61 | if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ] ; then 62 | # 63 | # Apple JDKs 64 | # 65 | export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home 66 | fi 67 | 68 | if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Java/JavaVirtualMachines/CurrentJDK ] ; then 69 | # 70 | # Apple JDKs 71 | # 72 | export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home 73 | fi 74 | 75 | if [ -z "$JAVA_HOME" ] && [ -L "/Library/Java/JavaVirtualMachines/CurrentJDK" ] ; then 76 | # 77 | # Oracle JDKs 78 | # 79 | export JAVA_HOME=/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home 80 | fi 81 | 82 | if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then 83 | # 84 | # Apple JDKs 85 | # 86 | export JAVA_HOME=`/usr/libexec/java_home` 87 | fi 88 | ;; 89 | esac 90 | 91 | if [ -z "$JAVA_HOME" ] ; then 92 | if [ -r /etc/gentoo-release ] ; then 93 | JAVA_HOME=`java-config --jre-home` 94 | fi 95 | fi 96 | 97 | if [ -z "$M2_HOME" ] ; then 98 | ## resolve links - $0 may be a link to maven's home 99 | PRG="$0" 100 | 101 | # need this for relative symlinks 102 | while [ -h "$PRG" ] ; do 103 | ls=`ls -ld "$PRG"` 104 | link=`expr "$ls" : '.*-> \(.*\)$'` 105 | if expr "$link" : '/.*' > /dev/null; then 106 | PRG="$link" 107 | else 108 | PRG="`dirname "$PRG"`/$link" 109 | fi 110 | done 111 | 112 | saveddir=`pwd` 113 | 114 | M2_HOME=`dirname "$PRG"`/.. 115 | 116 | # make it fully qualified 117 | M2_HOME=`cd "$M2_HOME" && pwd` 118 | 119 | cd "$saveddir" 120 | # echo Using m2 at $M2_HOME 121 | fi 122 | 123 | # For Cygwin, ensure paths are in UNIX format before anything is touched 124 | if $cygwin ; then 125 | [ -n "$M2_HOME" ] && 126 | M2_HOME=`cygpath --unix "$M2_HOME"` 127 | [ -n "$JAVA_HOME" ] && 128 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 129 | [ -n "$CLASSPATH" ] && 130 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 131 | fi 132 | 133 | # For Migwn, ensure paths are in UNIX format before anything is touched 134 | if $mingw ; then 135 | [ -n "$M2_HOME" ] && 136 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 137 | [ -n "$JAVA_HOME" ] && 138 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 139 | # TODO classpath? 140 | fi 141 | 142 | if [ -z "$JAVA_HOME" ]; then 143 | javaExecutable="`which javac`" 144 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 145 | # readlink(1) is not available as standard on Solaris 10. 146 | readLink=`which readlink` 147 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 148 | if $darwin ; then 149 | javaHome="`dirname \"$javaExecutable\"`" 150 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 151 | else 152 | javaExecutable="`readlink -f \"$javaExecutable\"`" 153 | fi 154 | javaHome="`dirname \"$javaExecutable\"`" 155 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 156 | JAVA_HOME="$javaHome" 157 | export JAVA_HOME 158 | fi 159 | fi 160 | fi 161 | 162 | if [ -z "$JAVACMD" ] ; then 163 | if [ -n "$JAVA_HOME" ] ; then 164 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 165 | # IBM's JDK on AIX uses strange locations for the executables 166 | JAVACMD="$JAVA_HOME/jre/sh/java" 167 | else 168 | JAVACMD="$JAVA_HOME/bin/java" 169 | fi 170 | else 171 | JAVACMD="`which java`" 172 | fi 173 | fi 174 | 175 | if [ ! -x "$JAVACMD" ] ; then 176 | echo "Error: JAVA_HOME is not defined correctly." >&2 177 | echo " We cannot execute $JAVACMD" >&2 178 | exit 1 179 | fi 180 | 181 | if [ -z "$JAVA_HOME" ] ; then 182 | echo "Warning: JAVA_HOME environment variable is not set." 183 | fi 184 | 185 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 186 | 187 | # For Cygwin, switch paths to Windows format before running java 188 | if $cygwin; then 189 | [ -n "$M2_HOME" ] && 190 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 191 | [ -n "$JAVA_HOME" ] && 192 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 193 | [ -n "$CLASSPATH" ] && 194 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 195 | fi 196 | 197 | # traverses directory structure from process work directory to filesystem root 198 | # first directory with .mvn subdirectory is considered project base directory 199 | find_maven_basedir() { 200 | local basedir=$(pwd) 201 | local wdir=$(pwd) 202 | while [ "$wdir" != '/' ] ; do 203 | if [ -d "$wdir"/.mvn ] ; then 204 | basedir=$wdir 205 | break 206 | fi 207 | wdir=$(cd "$wdir/.."; pwd) 208 | done 209 | echo "${basedir}" 210 | } 211 | 212 | # concatenates all lines of a file 213 | concat_lines() { 214 | if [ -f "$1" ]; then 215 | echo "$(tr -s '\n' ' ' < "$1")" 216 | fi 217 | } 218 | 219 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)} 220 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 221 | 222 | # Provide a "standardized" way to retrieve the CLI args that will 223 | # work with both Windows and non-Windows executions. 224 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 225 | export MAVEN_CMD_LINE_ARGS 226 | 227 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 228 | 229 | echo "Running version check" 230 | VERSION=$( sed '\!//' -e 's!.*$!!' ) 231 | echo "The found version is [${VERSION}]" 232 | 233 | if echo $VERSION | egrep -q 'M|RC'; then 234 | echo Activating \"milestone\" profile for version=\"$VERSION\" 235 | echo $MAVEN_ARGS | grep -q milestone || MAVEN_ARGS="$MAVEN_ARGS -Pmilestone" 236 | else 237 | echo Deactivating \"milestone\" profile for version=\"$VERSION\" 238 | echo $MAVEN_ARGS | grep -q milestone && MAVEN_ARGS=$(echo $MAVEN_ARGS | sed -e 's/-Pmilestone//') 239 | fi 240 | 241 | if echo $VERSION | egrep -q 'RELEASE'; then 242 | echo Activating \"central\" profile for version=\"$VERSION\" 243 | echo $MAVEN_ARGS | grep -q milestone || MAVEN_ARGS="$MAVEN_ARGS -Pcentral" 244 | else 245 | echo Deactivating \"central\" profile for version=\"$VERSION\" 246 | echo $MAVEN_ARGS | grep -q central && MAVEN_ARGS=$(echo $MAVEN_ARGS | sed -e 's/-Pcentral//') 247 | fi 248 | 249 | exec "$JAVACMD" \ 250 | $MAVEN_OPTS \ 251 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 252 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 253 | ${WRAPPER_LAUNCHER} ${MAVEN_ARGS} "$@" -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | set MAVEN_CMD_LINE_ARGS=%* 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | 121 | set WRAPPER_JAR="".\.mvn\wrapper\maven-wrapper.jar"" 122 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 123 | 124 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CMD_LINE_ARGS% 125 | if ERRORLEVEL 1 goto error 126 | goto end 127 | 128 | :error 129 | set ERROR_CODE=1 130 | 131 | :end 132 | @endlocal & set ERROR_CODE=%ERROR_CODE% 133 | 134 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 135 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 136 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 137 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 138 | :skipRcPost 139 | 140 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 141 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 142 | 143 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 144 | 145 | exit /B %ERROR_CODE% 146 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.springframework.cloud 8 | spring-cloud-circuitbreaker-demo 9 | pom 10 | 0.0.1.SNAPSHOT 11 | 12 | 13 | org.springframework.boot 14 | spring-boot-starter-parent 15 | 2.5.8 16 | 17 | 18 | 19 | 3.6.1 20 | 2.10 21 | UTF-8 22 | UTF-8 23 | 1.8 24 | 2020.0.5-SNAPSHOT 25 | 26 | 27 | 28 | 29 | org.springframework.cloud 30 | spring-cloud-dependencies 31 | ${spring-cloud.version} 32 | pom 33 | import 34 | 35 | 36 | 37 | 38 | spring-cloud-circuitbreaker-demo-resilience4j 39 | spring-cloud-circuitbreaker-demo-reactive-resilience4j 40 | spring-cloud-circuitbreaker-demo-reactive 41 | 42 | 43 | 44 | 45 | org.apache.maven.plugins 46 | maven-eclipse-plugin 47 | ${maven-eclipse-plugin.version} 48 | 49 | false 50 | 51 | 52 | .settings/org.eclipse.jdt.ui.prefs 53 | ${maven.multiModuleProjectDirectory}/eclipse/org.eclipse.jdt.ui.prefs 54 | 55 | 56 | .settings/org.eclipse.jdt.core.prefs 57 | ${maven.multiModuleProjectDirectory}/eclipse/org.eclipse.jdt.core.prefs 58 | 59 | 60 | 61 | 62 | 63 | maven-compiler-plugin 64 | ${maven-compiler-plugin.version} 65 | 66 | 1.8 67 | 1.8 68 | 69 | 70 | 71 | 72 | 73 | 74 | spring 75 | 76 | 77 | spring-snapshots 78 | Spring Snapshots 79 | https://repo.spring.io/libs-snapshot-local 80 | 81 | true 82 | 83 | 84 | false 85 | 86 | 87 | 88 | spring-milestones 89 | Spring Milestones 90 | https://repo.spring.io/libs-milestone-local 91 | 92 | false 93 | 94 | 95 | 96 | spring-releases 97 | Spring Releases 98 | https://repo.spring.io/release 99 | 100 | false 101 | 102 | 103 | 104 | 105 | 106 | spring-snapshots 107 | Spring Snapshots 108 | https://repo.spring.io/libs-snapshot-local 109 | 110 | true 111 | 112 | 113 | false 114 | 115 | 116 | 117 | spring-milestones 118 | Spring Milestones 119 | https://repo.spring.io/libs-milestone-local 120 | 121 | false 122 | 123 | 124 | 125 | spring-releases 126 | Spring Releases 127 | https://repo.spring.io/libs-release-local 128 | 129 | false 130 | 131 | 132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /spring-cloud-circuitbreaker-demo-reactive-resilience4j/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /spring-cloud-circuitbreaker-demo-reactive-resilience4j/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.cloud 7 | spring-cloud-circuitbreaker-demo-reactive-resilience4j 8 | jar 9 | 10 | spring-cloud-circuitbreaker-demo-reactive-resilience4j 11 | Demo Project Reative Resilience4J Circuit Breakers 12 | 13 | 14 | org.springframework.cloud 15 | spring-cloud-circuitbreaker-demo 16 | 0.0.1.SNAPSHOT 17 | 18 | 19 | 20 | UTF-8 21 | UTF-8 22 | 1.8 23 | 24 | 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-webflux 29 | 30 | 31 | org.springframework.cloud 32 | spring-cloud-starter-circuitbreaker-reactor-resilience4j 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-actuator 37 | 38 | 39 | io.github.resilience4j 40 | resilience4j-micrometer 41 | 42 | 43 | io.micrometer 44 | micrometer-registry-prometheus 45 | 46 | 47 | 48 | 49 | org.springframework.boot 50 | spring-boot-starter-test 51 | test 52 | 53 | 54 | io.projectreactor 55 | reactor-test 56 | test 57 | 58 | 59 | 60 | 61 | 62 | 63 | org.springframework.boot 64 | spring-boot-maven-plugin 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /spring-cloud-circuitbreaker-demo-reactive-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/demo/reactiveresilience4jcircuitbreakerdemo/DemoController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.cloud.circuitbreaker.demo.reactiveresilience4jcircuitbreakerdemo; 17 | 18 | import reactor.core.publisher.Flux; 19 | import reactor.core.publisher.Mono; 20 | 21 | import java.util.HashMap; 22 | import java.util.Map; 23 | import org.slf4j.Logger; 24 | import org.slf4j.LoggerFactory; 25 | import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreakerFactory; 26 | import org.springframework.web.bind.annotation.GetMapping; 27 | import org.springframework.web.bind.annotation.PathVariable; 28 | import org.springframework.web.bind.annotation.RestController; 29 | 30 | /** 31 | * @author Ryan Baxter 32 | */ 33 | @RestController 34 | public class DemoController { 35 | 36 | Logger LOG = LoggerFactory.getLogger(DemoController.class); 37 | 38 | private ReactiveCircuitBreakerFactory circuitBreakerFactory; 39 | private HttpBinService httpBin; 40 | 41 | public DemoController(ReactiveCircuitBreakerFactory circuitBreakerFactory, HttpBinService httpBinService) { 42 | this.circuitBreakerFactory = circuitBreakerFactory; 43 | this.httpBin = httpBinService; 44 | } 45 | 46 | @GetMapping("/get") 47 | public Mono get() { 48 | return httpBin.get(); 49 | } 50 | 51 | @GetMapping("/delay/{seconds}") 52 | public Mono delay(@PathVariable int seconds) { 53 | return circuitBreakerFactory.create("delay").run(httpBin.delay(seconds), t -> { 54 | LOG.warn("delay call failed error", t); 55 | Map fallback = new HashMap<>(); 56 | fallback.put("hello", "world"); 57 | return Mono.just(fallback); 58 | }); 59 | } 60 | 61 | @GetMapping("/fluxdelay/{seconds}") 62 | public Flux fluxDelay(@PathVariable int seconds) { 63 | return circuitBreakerFactory.create("delay").run(httpBin.fluxDelay(seconds), t -> { 64 | LOG.warn("delay call failed error", t); 65 | return Flux.just("hello", "world"); 66 | }); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /spring-cloud-circuitbreaker-demo-reactive-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/demo/reactiveresilience4jcircuitbreakerdemo/HttpBinService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.cloud.circuitbreaker.demo.reactiveresilience4jcircuitbreakerdemo; 17 | 18 | import reactor.core.publisher.Flux; 19 | import reactor.core.publisher.Mono; 20 | 21 | import java.time.Duration; 22 | import java.util.Map; 23 | import java.util.function.Supplier; 24 | import org.springframework.stereotype.Service; 25 | import org.springframework.web.client.RestTemplate; 26 | import org.springframework.web.reactive.function.client.WebClient; 27 | 28 | /** 29 | * @author Ryan Baxter 30 | */ 31 | @Service 32 | public class HttpBinService { 33 | 34 | private WebClient rest; 35 | 36 | public HttpBinService(WebClient.Builder builder) { 37 | this.rest = builder.baseUrl("https://httpbin.org").build(); 38 | } 39 | 40 | public Mono get() { 41 | return rest.get().uri("/get").retrieve().bodyToMono(Map.class); 42 | } 43 | 44 | public Mono delay(int seconds) { 45 | return rest.get().uri("/delay/{seconds}", seconds).retrieve().bodyToMono(Map.class); 46 | } 47 | 48 | public Supplier> delaySuppplier(int seconds) { 49 | return () -> this.delay(seconds); 50 | } 51 | 52 | public Flux fluxDelay(int seconds) { 53 | return Flux.just("1", "2", "3").delayElements(Duration.ofSeconds(seconds)); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /spring-cloud-circuitbreaker-demo-reactive-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/demo/reactiveresilience4jcircuitbreakerdemo/ReactiveResilience4JCircuitbreakerDemoApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.cloud.circuitbreaker.demo.reactiveresilience4jcircuitbreakerdemo; 17 | 18 | import io.github.resilience4j.circuitbreaker.CircuitBreakerConfig; 19 | import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry; 20 | import io.github.resilience4j.timelimiter.TimeLimiterConfig; 21 | 22 | import java.time.Duration; 23 | import org.springframework.boot.SpringApplication; 24 | import org.springframework.boot.autoconfigure.SpringBootApplication; 25 | import org.springframework.cloud.circuitbreaker.resilience4j.ReactiveResilience4JCircuitBreakerFactory; 26 | import org.springframework.cloud.circuitbreaker.resilience4j.Resilience4JConfigBuilder; 27 | import org.springframework.cloud.client.circuitbreaker.Customizer; 28 | import org.springframework.context.annotation.Bean; 29 | import org.springframework.web.reactive.function.client.WebClient; 30 | 31 | @SpringBootApplication 32 | public class ReactiveResilience4JCircuitbreakerDemoApplication { 33 | 34 | public static void main(String[] args) { 35 | SpringApplication.run(ReactiveResilience4JCircuitbreakerDemoApplication.class, args); 36 | } 37 | 38 | @Bean 39 | public WebClient.Builder webClientBuilder() { 40 | return WebClient.builder(); 41 | } 42 | 43 | @Bean 44 | public Customizer defaultCustomizer() { 45 | CircuitBreakerRegistry cbr = CircuitBreakerRegistry.ofDefaults(); 46 | return factory -> { 47 | factory.configureDefault(id -> new Resilience4JConfigBuilder(id) 48 | .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()) 49 | .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(3)).build()) 50 | .circuitBreakerConfig(CircuitBreakerConfig.custom().failureRateThreshold(10) 51 | .slowCallRateThreshold(5).slowCallRateThreshold(2).build()).build()); 52 | }; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /spring-cloud-circuitbreaker-demo-reactive-resilience4j/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | management: 2 | endpoints: 3 | web: 4 | exposure: 5 | include: "*" -------------------------------------------------------------------------------- /spring-cloud-circuitbreaker-demo-reactive-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/demo/reactiveresilience4jcircuitbreakerdemo/ReactiveResilience4JCircuitbreakerDemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.springframework.cloud.circuitbreaker.demo.reactiveresilience4jcircuitbreakerdemo; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @SpringBootTest 9 | public class ReactiveResilience4JCircuitbreakerDemoApplicationTests { 10 | 11 | @Test 12 | public void contextLoads() { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /spring-cloud-circuitbreaker-demo-reactive/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /spring-cloud-circuitbreaker-demo-reactive/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.cloud 7 | spring-cloud-circuitbreaker-demo 8 | 0.0.1.SNAPSHOT 9 | 10 | spring-cloud-circuitbreaker-demo-reactive 11 | spring-cloud-circuitbreaker-demo-reactive 12 | Demo project for Spring Boot 13 | 14 | 15 | 1.8 16 | 2.27 17 | 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter 23 | 24 | 25 | org.glassfish.jersey.core 26 | jersey-client 27 | ${jersey.version} 28 | 29 | 30 | org.glassfish.jersey.inject 31 | jersey-hk2 32 | ${jersey.version} 33 | 34 | 35 | org.glassfish.jersey.ext.rx 36 | jersey-rx-client-rxjava 37 | ${jersey.version} 38 | 39 | 40 | org.glassfish.jersey.ext.rx 41 | jersey-rx-client-rxjava2 42 | ${jersey.version} 43 | 44 | 45 | org.glassfish.jersey.media 46 | jersey-media-json-jackson 47 | ${jersey.version} 48 | 49 | 50 | org.springframework.boot 51 | spring-boot-starter-webflux 52 | 53 | 54 | io.projectreactor.addons 55 | reactor-adapter 56 | 57 | 58 | org.springframework.cloud 59 | spring-cloud-starter-circuitbreaker-reactor-resilience4j 60 | 61 | 62 | 63 | org.springframework.boot 64 | spring-boot-starter-test 65 | test 66 | 67 | 68 | 69 | 70 | 71 | 72 | org.springframework.boot 73 | spring-boot-maven-plugin 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /spring-cloud-circuitbreaker-demo-reactive/src/main/java/org/springframework/cloud/circuitbreaker/demo/reactive/CompletableFutureDemoController.java: -------------------------------------------------------------------------------- 1 | package org.springframework.cloud.circuitbreaker.demo.reactive; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import reactor.core.publisher.Mono; 9 | 10 | import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreakerFactory; 11 | import org.springframework.web.bind.annotation.GetMapping; 12 | import org.springframework.web.bind.annotation.PathVariable; 13 | import org.springframework.web.bind.annotation.RestController; 14 | 15 | /** 16 | * @author Ryan Baxter 17 | */ 18 | @RestController 19 | public class CompletableFutureDemoController { 20 | 21 | Logger LOG = LoggerFactory.getLogger(CompletableFutureDemoController.class); 22 | 23 | private CompletableFutureHttpBinService httpBin; 24 | private ReactiveCircuitBreakerFactory reactiveCircuitBreakerFactory; 25 | 26 | public CompletableFutureDemoController(CompletableFutureHttpBinService httpBin, ReactiveCircuitBreakerFactory reactiveCircuitBreakerFactory) { 27 | this.httpBin = httpBin; 28 | this.reactiveCircuitBreakerFactory = reactiveCircuitBreakerFactory; 29 | } 30 | 31 | @GetMapping("/completablefuture/get") 32 | public Mono get() { 33 | return Mono.fromFuture(httpBin.get()); 34 | } 35 | 36 | @GetMapping("/completablefuture/delay/{seconds}") 37 | public Mono delay(@PathVariable int seconds) { 38 | return reactiveCircuitBreakerFactory.create("completablefuturedelay").run(Mono.fromFuture(httpBin.delay(seconds)), t -> { 39 | LOG.warn("delay call failed error", t); 40 | Map fallback = new HashMap(); 41 | fallback.put("hello", "world"); 42 | return Mono.just(fallback); 43 | }); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /spring-cloud-circuitbreaker-demo-reactive/src/main/java/org/springframework/cloud/circuitbreaker/demo/reactive/CompletableFutureHttpBinService.java: -------------------------------------------------------------------------------- 1 | package org.springframework.cloud.circuitbreaker.demo.reactive; 2 | 3 | import java.util.Map; 4 | import java.util.concurrent.CompletableFuture; 5 | 6 | import javax.ws.rs.client.Client; 7 | import javax.ws.rs.client.ClientBuilder; 8 | import javax.ws.rs.client.WebTarget; 9 | import javax.ws.rs.core.MediaType; 10 | 11 | import org.springframework.stereotype.Service; 12 | 13 | /** 14 | * @author Ryan Baxter 15 | */ 16 | @Service 17 | public class CompletableFutureHttpBinService { 18 | 19 | private Client client; 20 | 21 | public CompletableFutureHttpBinService() { 22 | this.client = ClientBuilder.newClient(); 23 | } 24 | 25 | public CompletableFuture get() { 26 | WebTarget getService = client.target("http://httpbin.org/get"); 27 | return getService.request().accept(MediaType.APPLICATION_JSON) 28 | .rx().get(Map.class).toCompletableFuture(); 29 | 30 | } 31 | 32 | public CompletableFuture delay(int seconds) { 33 | WebTarget delayService = client.target("http://httpbin.org/delay/" + seconds); 34 | return delayService.request().rx().get(Map.class).toCompletableFuture(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /spring-cloud-circuitbreaker-demo-reactive/src/main/java/org/springframework/cloud/circuitbreaker/demo/reactive/RxJava2DemoController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.cloud.circuitbreaker.demo.reactive; 17 | 18 | import java.util.HashMap; 19 | import java.util.Map; 20 | 21 | import org.slf4j.Logger; 22 | import org.slf4j.LoggerFactory; 23 | import reactor.adapter.rxjava.RxJava2Adapter; 24 | import reactor.core.publisher.Flux; 25 | 26 | import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreakerFactory; 27 | import org.springframework.web.bind.annotation.GetMapping; 28 | import org.springframework.web.bind.annotation.PathVariable; 29 | import org.springframework.web.bind.annotation.RestController; 30 | 31 | /** 32 | * @author Ryan Baxter 33 | */ 34 | @RestController 35 | public class RxJava2DemoController { 36 | 37 | Logger LOG = LoggerFactory.getLogger(RxJava2DemoController.class); 38 | 39 | private ReactiveCircuitBreakerFactory circuitBreakerFactory; 40 | private RxJava2HttpBinService httpBin; 41 | 42 | public RxJava2DemoController(ReactiveCircuitBreakerFactory circuitBreakerFactory, RxJava2HttpBinService rxJava2HttpBinService) { 43 | this.circuitBreakerFactory = circuitBreakerFactory; 44 | this.httpBin = rxJava2HttpBinService; 45 | } 46 | 47 | @GetMapping("/rxjava2/get") 48 | public Flux get() { 49 | return RxJava2Adapter.flowableToFlux(httpBin.get()); 50 | } 51 | 52 | @GetMapping("/rxjava2/delay/{seconds}") 53 | public Flux delay(@PathVariable int seconds) { 54 | return circuitBreakerFactory.create("rxjava2delay").run(RxJava2Adapter.flowableToFlux(httpBin.delay(seconds)), t -> { 55 | LOG.warn("delay call failed error", t); 56 | Map fallback = new HashMap<>(); 57 | fallback.put("hello", "world"); 58 | return Flux.just(fallback); 59 | }); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /spring-cloud-circuitbreaker-demo-reactive/src/main/java/org/springframework/cloud/circuitbreaker/demo/reactive/RxJava2HttpBinService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.cloud.circuitbreaker.demo.reactive; 17 | 18 | import java.util.Map; 19 | 20 | import javax.ws.rs.client.Client; 21 | import javax.ws.rs.client.ClientBuilder; 22 | import javax.ws.rs.client.WebTarget; 23 | import javax.ws.rs.core.MediaType; 24 | 25 | import io.reactivex.Flowable; 26 | import org.glassfish.jersey.client.rx.rxjava.RxObservableInvokerProvider; 27 | import org.glassfish.jersey.client.rx.rxjava2.RxFlowableInvoker; 28 | import org.glassfish.jersey.client.rx.rxjava2.RxFlowableInvokerProvider; 29 | 30 | import org.springframework.stereotype.Service; 31 | /** 32 | * @author Ryan Baxter 33 | */ 34 | @Service 35 | public class RxJava2HttpBinService { 36 | 37 | private Client client; 38 | 39 | public RxJava2HttpBinService() { 40 | this.client = ClientBuilder.newClient(); 41 | this.client.register(RxObservableInvokerProvider.class); 42 | this.client.register(RxFlowableInvokerProvider.class); 43 | } 44 | 45 | public Flowable get() { 46 | WebTarget getService = client.target("http://httpbin.org/get"); 47 | return getService.request().accept(MediaType.APPLICATION_JSON) 48 | .rx(RxFlowableInvoker.class).get(Map.class); 49 | 50 | } 51 | 52 | public Flowable delay(int seconds) { 53 | WebTarget delayService = client.target("http://httpbin.org/delay/" + seconds); 54 | return delayService.request().rx(RxFlowableInvoker.class).get(Map.class); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /spring-cloud-circuitbreaker-demo-reactive/src/main/java/org/springframework/cloud/circuitbreaker/demo/reactive/SpringCloudCircuitbreakerDemoReactiveApplication.java: -------------------------------------------------------------------------------- 1 | package org.springframework.cloud.circuitbreaker.demo.reactive; 2 | 3 | import java.time.Duration; 4 | 5 | import io.github.resilience4j.circuitbreaker.CircuitBreakerConfig; 6 | import io.github.resilience4j.timelimiter.TimeLimiterConfig; 7 | 8 | import org.springframework.boot.SpringApplication; 9 | import org.springframework.boot.autoconfigure.SpringBootApplication; 10 | import org.springframework.cloud.circuitbreaker.resilience4j.ReactiveResilience4JCircuitBreakerFactory; 11 | import org.springframework.cloud.circuitbreaker.resilience4j.Resilience4JConfigBuilder; 12 | import org.springframework.cloud.client.circuitbreaker.Customizer; 13 | import org.springframework.context.annotation.Bean; 14 | 15 | @SpringBootApplication 16 | public class SpringCloudCircuitbreakerDemoReactiveApplication { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(SpringCloudCircuitbreakerDemoReactiveApplication.class, args); 20 | } 21 | 22 | @Bean 23 | public Customizer defaultCustomizer() { 24 | return factory -> factory.configureDefault(id -> new Resilience4JConfigBuilder(id) 25 | .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()) 26 | .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(3)).build()).build()); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /spring-cloud-circuitbreaker-demo-reactive/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /spring-cloud-circuitbreaker-demo-reactive/src/test/java/org/springframework/cloud/circuitbreaker/demo/reactive/SpringCloudCircuitbreakerDemoReactiveApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.springframework.cloud.circuitbreaker.demo.reactive; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | import org.springframework.test.context.junit4.SpringRunner; 6 | 7 | @SpringBootTest 8 | public class SpringCloudCircuitbreakerDemoReactiveApplicationTests { 9 | 10 | @Test 11 | public void contextLoads() { 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /spring-cloud-circuitbreaker-demo-resilience4j/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /spring-cloud-circuitbreaker-demo-resilience4j/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframeworkd.cloud 7 | spring-cloud-circuitbreaker-demo-resilience4j 8 | jar 9 | 10 | spring-cloud-circuitbreaker-demo-resilience4j 11 | Resilience4J Circuit Breaker Demo 12 | 13 | 14 | org.springframework.cloud 15 | spring-cloud-circuitbreaker-demo 16 | 0.0.1.SNAPSHOT 17 | 18 | 19 | 20 | UTF-8 21 | UTF-8 22 | 1.8 23 | 24 | 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-web 29 | 30 | 31 | 32 | org.springframework.cloud 33 | spring-cloud-starter-circuitbreaker-resilience4j 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter-actuator 38 | 39 | 40 | io.micrometer 41 | micrometer-core 42 | 43 | 44 | io.github.resilience4j 45 | resilience4j-micrometer 46 | 1.1.0 47 | 48 | 49 | io.micrometer 50 | micrometer-registry-prometheus 51 | 52 | 53 | 54 | org.springframework.boot 55 | spring-boot-starter-test 56 | test 57 | 58 | 59 | 60 | 61 | 62 | 63 | org.springframework.boot 64 | spring-boot-maven-plugin 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /spring-cloud-circuitbreaker-demo-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/demo/resilience4jcircuitbreakerdemo/DemoController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.cloud.circuitbreaker.demo.resilience4jcircuitbreakerdemo; 17 | 18 | import java.util.HashMap; 19 | import java.util.Map; 20 | import org.slf4j.Logger; 21 | import org.slf4j.LoggerFactory; 22 | 23 | import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory; 24 | import org.springframework.web.bind.annotation.GetMapping; 25 | import org.springframework.web.bind.annotation.PathVariable; 26 | import org.springframework.web.bind.annotation.RestController; 27 | 28 | /** 29 | * @author Ryan Baxter 30 | */ 31 | @RestController 32 | public class DemoController { 33 | 34 | Logger LOG = LoggerFactory.getLogger(DemoController.class); 35 | 36 | private CircuitBreakerFactory circuitBreakerFactory; 37 | private HttpBinService httpBin; 38 | 39 | public DemoController(CircuitBreakerFactory circuitBreakerFactory, HttpBinService httpBinService) { 40 | this.circuitBreakerFactory = circuitBreakerFactory; 41 | this.httpBin = httpBinService; 42 | } 43 | 44 | @GetMapping("/get") 45 | public Map get() { 46 | return httpBin.get(); 47 | } 48 | 49 | @GetMapping("/delay/{seconds}") 50 | public Map delay(@PathVariable int seconds) { 51 | return circuitBreakerFactory.create("delay").run(httpBin.delaySuppplier(seconds), t -> { 52 | LOG.warn("delay call failed error", t); 53 | Map fallback = new HashMap<>(); 54 | fallback.put("hello", "world"); 55 | return fallback; 56 | }); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /spring-cloud-circuitbreaker-demo-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/demo/resilience4jcircuitbreakerdemo/HttpBinService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.cloud.circuitbreaker.demo.resilience4jcircuitbreakerdemo; 17 | 18 | import java.util.Map; 19 | import java.util.function.Supplier; 20 | import org.springframework.stereotype.Service; 21 | import org.springframework.web.client.RestTemplate; 22 | 23 | /** 24 | * @author Ryan Baxter 25 | */ 26 | @Service 27 | public class HttpBinService { 28 | 29 | private RestTemplate rest; 30 | 31 | public HttpBinService(RestTemplate rest) { 32 | this.rest = rest; 33 | } 34 | 35 | public Map get() { 36 | return rest.getForObject("https://httpbin.org/get", Map.class); 37 | 38 | } 39 | 40 | public Map delay(int seconds) { 41 | return rest.getForObject("https://httpbin.org/delay/" + seconds, Map.class); 42 | } 43 | 44 | public Supplier delaySuppplier(int seconds) { 45 | return () -> this.delay(seconds); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /spring-cloud-circuitbreaker-demo-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/demo/resilience4jcircuitbreakerdemo/Resilience4JCircuitbreakerDemoApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.cloud.circuitbreaker.demo.resilience4jcircuitbreakerdemo; 17 | 18 | import io.github.resilience4j.circuitbreaker.CircuitBreakerConfig; 19 | import io.github.resilience4j.timelimiter.TimeLimiterConfig; 20 | 21 | import java.time.Duration; 22 | import org.springframework.boot.SpringApplication; 23 | import org.springframework.boot.autoconfigure.SpringBootApplication; 24 | import org.springframework.boot.web.client.RestTemplateBuilder; 25 | import org.springframework.cloud.circuitbreaker.resilience4j.Resilience4JCircuitBreakerFactory; 26 | import org.springframework.cloud.circuitbreaker.resilience4j.Resilience4JConfigBuilder; 27 | import org.springframework.cloud.client.circuitbreaker.Customizer; 28 | import org.springframework.context.annotation.Bean; 29 | import org.springframework.web.client.RestTemplate; 30 | 31 | @SpringBootApplication 32 | public class Resilience4JCircuitbreakerDemoApplication { 33 | 34 | public static void main(String[] args) { 35 | SpringApplication.run(Resilience4JCircuitbreakerDemoApplication.class, args); 36 | } 37 | 38 | @Bean 39 | public RestTemplate restTemplate() { 40 | return new RestTemplateBuilder().build(); 41 | } 42 | 43 | @Bean 44 | public Customizer defaultCustomizer() { 45 | return factory -> factory.configureDefault(id -> new Resilience4JConfigBuilder(id) 46 | .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(3)).build()) 47 | .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()) 48 | .build()); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /spring-cloud-circuitbreaker-demo-resilience4j/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | management: 2 | endpoints: 3 | web: 4 | exposure: 5 | include: "*" -------------------------------------------------------------------------------- /spring-cloud-circuitbreaker-demo-resilience4j/src/test/java/org/springframework/cloud/circuitbreaker/demo/resilience4jcircuitbreakerdemo/Resilience4JCircuitbreakerDemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.springframework.cloud.circuitbreaker.demo.resilience4jcircuitbreakerdemo; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | 7 | @SpringBootTest 8 | public class Resilience4JCircuitbreakerDemoApplicationTests { 9 | 10 | @Test 11 | public void contextLoads() { 12 | } 13 | 14 | } 15 | --------------------------------------------------------------------------------