Skip to content

Commit

Permalink
Changed bulkhead to threadpool
Browse files Browse the repository at this point in the history
  • Loading branch information
jose luis sanchez romero committed Nov 17, 2023
1 parent 2e370d2 commit 5511f6c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 25 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<!-- <version>3.1.5</version>-->
<version>3.2.0-RC2</version>
<relativePath/>
<!-- lookup parent from repository -->
Expand All @@ -27,6 +26,7 @@

<properties>
<java.version>17</java.version>
<spring-framework.version>6.1.0</spring-framework.version>
<spring-cloud.version>2023.0.0-RC1</spring-cloud.version>
<fmt-plugin.version>2.21.1</fmt-plugin.version>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ public PortfolioResource(StockPriceService service, StatsResource stats) {

@GetMapping("/{user}")
public CompletableFuture<Portfolio> get(@PathVariable("user") String user) {
return getOrCreatePortfolioContent(user).thenApply(this::getStockPrices).thenApply(this::fillPortfolio);
return getOrCreatePortfolioContent(user)
.thenApply(this::getStockPrices)
.thenApply(this::fillPortfolio);
}

private CompletableFuture<List<String>> getOrCreatePortfolioContent(final String user) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package es.ing.spring.ftdemo.portfolio.resources;

import io.github.resilience4j.bulkhead.annotation.Bulkhead;
import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
import io.github.resilience4j.retry.annotation.Retry;
import io.github.resilience4j.timelimiter.annotation.TimeLimiter;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
Expand All @@ -22,12 +25,11 @@ public StockPriceService(StockPriceClientExchange stockPriceClientExchange, Stat

private final ConcurrentMap<String, StockPrice> cache = new ConcurrentHashMap<>();

// @Bulkhead(name = "bulk", type = Bulkhead.Type.THREADPOOL)
// @CircuitBreaker(name = "circuit")
// @Retry(name = "retry", fallbackMethod = "getPriceFallback")
// Retry ( CircuitBreaker ( RateLimiter ( TimeLimiter ( Bulkhead ( Function
@Retry(name = "retry")
// @TimeLimiter(name = "limiter", fallbackMethod = "getPriceFallback")
// @TimeLimiter(name = "limiter")
@TimeLimiter(name = "limiter")
@CircuitBreaker(name = "circuitbreaker")
@Bulkhead(name = "bulkhead", type = Bulkhead.Type.THREADPOOL)
public CompletableFuture<StockPrice> getPrice(String ticker) {
return CompletableFuture.supplyAsync(
() -> {
Expand Down
37 changes: 19 additions & 18 deletions portfolio/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,27 @@ management.endpoint.health.show-details=always
management.endpoints.web.exposure.include=*
management.health.circuitbreakers.enabled=true
management.health.ratelimiters.enabled=true
resilience4j.bulkhead.configs.default.max-concurrent-calls=50
resilience4j.bulkhead.configs.default.max-wait-duration=1s
#resilience4j.bulkhead.configs.default.max-concurrent-calls=30
#resilience4j.bulkhead.configs.default.max-wait-duration=1s
resilience4j.bulkhead.configs.default.writable-stack-trace-enabled=false
resilience4j.circuitbreaker.configs.default.automatic-transition-from-open-to-half-open-enabled=true
resilience4j.circuitbreaker.configs.default.event-consumer-buffer-size=10
resilience4j.circuitbreaker.configs.default.failure-rate-threshold=50
resilience4j.circuitbreaker.configs.default.minimum-number-of-calls=5
resilience4j.circuitbreaker.configs.default.permitted-number-of-calls-in-half-open-state=3
resilience4j.circuitbreaker.configs.default.recordExceptions=org.springframework.web.client.HttpServerErrorException,java.util.concurrent.TimeoutException,java.io.IOException,org.springframework.web.client.ResourceAccessException,java.util.concurrent.ExecutionException,java.nio.channels.ClosedChannelException
resilience4j.circuitbreaker.configs.default.registerHealthIndicator=true
resilience4j.circuitbreaker.configs.default.slidingWindowSize=10
#resilience4j.circuitbreaker.configs.default.automatic-transition-from-open-to-half-open-enabled=true
#resilience4j.circuitbreaker.configs.default.event-consumer-buffer-size=10
#resilience4j.circuitbreaker.configs.default.failure-rate-threshold=50
#resilience4j.circuitbreaker.configs.default.minimum-number-of-calls=5
#resilience4j.circuitbreaker.configs.default.permitted-number-of-calls-in-half-open-state=3
#resilience4j.circuitbreaker.configs.default.recordExceptions=org.springframework.web.client.HttpServerErrorException,java.util.concurrent.TimeoutException,java.io.IOException,org.springframework.web.client.ResourceAccessException,java.util.concurrent.ExecutionException,java.nio.channels.ClosedChannelException
#resilience4j.circuitbreaker.configs.default.registerHealthIndicator=true
#resilience4j.circuitbreaker.configs.default.slidingWindowSize=10
resilience4j.circuitbreaker.configs.default.wait-duration-in-open-state=5s
resilience4j.retry.configs.default.max-attempts=1
resilience4j.retry.configs.default.retryExceptions=org.springframework.web.client.HttpServerErrorException,java.util.concurrent.TimeoutException,java.io.IOException,org.springframework.web.client.ResourceAccessException,java.util.concurrent.ExecutionException,java.nio.channels.ClosedChannelException
resilience4j.retry.configs.default.wait-duration=2s
resilience4j.thread-pool-bulkhead.configs.default.core-thread-pool-size=10
resilience4j.thread-pool-bulkhead.configs.default.max-thread-pool-size=20
resilience4j.thread-pool-bulkhead.configs.default.queue-capacity=10
resilience4j.timelimiter.configs.limiter.cancel-running-future=true
resilience4j.timelimiter.configs.limiter.timeout-duration=1s
#resilience4j.circuitbreaker.configs.default.ignore-exceptions
#resilience4j.retry.configs.default.max-attempts=1
#resilience4j.retry.configs.default.retryExceptions=org.springframework.web.client.HttpServerErrorException,java.util.concurrent.TimeoutException,java.io.IOException,org.springframework.web.client.ResourceAccessException,java.util.concurrent.ExecutionException,java.nio.channels.ClosedChannelException
#resilience4j.retry.configs.default.wait-duration=2s
#resilience4j.thread-pool-bulkhead.configs.default.core-thread-pool-size=30
#resilience4j.thread-pool-bulkhead.configs.default.max-thread-pool-size=40
#resilience4j.thread-pool-bulkhead.configs.default.queue-capacity=10
#resilience4j.timelimiter.configs.limiter.cancel-running-future=true
#resilience4j.timelimiter.configs.limiter.timeout-duration=1s
server.port=7070
spring.application.name=ftdemo-portfolio
spring.devtools.livereload.port=35730
Expand Down

0 comments on commit 5511f6c

Please sign in to comment.