0

enter image description here

We communicate with a third-party server that eventually forwards our request to the respective servers (taking the serverName as a parameter). The available servers are stored in our service.

We want the circuit breaker pattern to be applied to each of these servers. Currently, we have two servers on the far right (two circuit breakers, applied to two different methods in our server). But later on the third-party server can add up more servers, and notify us of that change.

We want a new circuit breaker to be created for this new server.

We do not want to break the circuit for API-0. We want the circuit breakers to be created on the fly whenever a new server is introduced.

Say the api is of this form: GET API-0/{serverName}

then we want,

CircuitBreaker1 for API-0/SERVER-1

CircuitBreaker2 for API-0/SERVER-2

... and so on

We do not want to make code changes to the running services. We get a notification if a new server is introduced. Using that notification we want to create a new circuit breaker

CircuitBreaker3 for API-0/SERVER-3

This is what we currently have. The problem is, this only creates a single instance of circuit breaker and thus will get open if any of the servers(1, 2 or 3) is down.

@CircuitBreaker(name="api0")
public Response getData(String serverName, payload){
    return callThirdParty(serverName, payload);
}

We want to maintain separate circuit breakers for each server(using serverName). The servers can be created on runtime and thus we can not have seapate functions for each server.

Saif
  • 2,530
  • 3
  • 27
  • 45

1 Answers1

1

In Spring Boot the name of the CircuitBreaker can be a SpEL expression:

@CircuitBreaker(name="#root.args[0]")
public Response getData(String serverName, payload){
    return callThirdParty(serverName, payload);
}

This would use the first parameter of the method as the name of the CircuitBreaker. The CircuitBreaker instance is created on-the-fly and is using the default CircuitBreakerConfig defined in your application config file.

Robert Winkler
  • 1,734
  • 9
  • 8