Thomson Mathew
Thomson Mathew

Reputation: 439

Resilence4j 1.7.1 is not executing - jdk 17

I am not sure if this is a jdk compatibility issue or if I am missing something. I tried resilence4j git dependency as below:

implementation group: 'io.github.resilience4j', name: 'resilience4j-spring-boot2', version: '1.7.1'
implementation group: 'io.github.resilience4j', name: 'resilience4j-retry', version: '1.7.1'    
implementation group: 'io.github.resilience4j', name: 'resilience4j-bulkhead', version: '1.7.1'
implementation group: 'io.github.resilience4j', name: 'resilience4j-ratelimiter', version: '1.7.1'
implementation group: 'io.github.resilience4j', name: 'resilience4j-circuitbreaker', version: '1.7.1'

But I was getting error as;

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    io.github.resilience4j.circuitbreaker.configure.CircuitBreakerConfiguration.createCircuitBreakerRegistry(CircuitBreakerConfiguration.java:141)

The following method did not exist:

    io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry.of(Ljava/util/Map;Lio/github/resilience4j/core/registry/RegistryEventConsumer;Lio/vavr/collection/Map;)Lio/github/resilience4j/circuitbreaker/CircuitBreakerRegistry;

Finally I made spring boot dependency and the error is gone but it does not do anything as calls are getting failed like normal exception. I have an APi which calls another api. Even actuator health is not showing any resilence4j properties. Not sure what I am missing here. A help would be really appreciated. Here is what I did:

build.gradle

plugins {
    id 'org.springframework.boot' version '2.6.2'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'

repositories {
    mavenCentral()
}

ext {
    set('springCloudVersion', "2021.0.0")
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    runtimeOnly 'org.postgresql:postgresql' 
    
    implementation 'org.springframework.boot:spring-boot-starter-web'   
    implementation 'org.springframework.boot:spring-boot-starter-webflux'   
    
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-aop', version: '2.6.1'
    implementation 'org.springframework.cloud:spring-cloud-starter-circuitbreaker-resilience4j'
    
    implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.5.10'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'io.projectreactor:reactor-test'
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
    }
}

test {
    useJUnitPlatform()
}

Service class where @Circutebreaker is implemented;

...
import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;

@Service
public class UserInfoService {
    public static final Logger LOG = LogManager.getLogger(UserInfoService.class);
    
    @Autowired
    private AppConfiguration appConfig;
    
    
    @CircuitBreaker(name = "userInfoService",
            fallbackMethod = "testMethod")
    public GetUserOutputVO getUserInfoById(String id) {     
        LOG.info("--- Beginning of method UserInfoService.getUserInfoById()---");
                    
        return appConfig.getUserInfoWebclient().get()
                .uri("/users/id/" + id)
                .retrieve()
                /*.onStatus(httpStatus -> HttpStatus.NOT_FOUND.equals(httpStatus),
                        clientResponse -> Mono.empty())*/
                .bodyToMono(GetUserOutputVO.class)
                .block();
    }
    
    public GetUserOutputVO testMethod(String id) {
        GetUserOutputVO resp = new GetUserOutputVO();
        
        UserInfo userInfo = new UserInfo();
        userInfo.setFirstName("Its a test for fallback");
        resp.setUserInfo(userInfo);
        
        return resp;
    }
}

application.yml

server:
  port: 8097

spring:
  application:
    name: profile-mgmt-api  
  jpa:  
#    hibernate:  
#      ddl-auto: create  
    database-platform: org.hibernate.dialect.PostgreSQLDialect
    show-sql: true
        
  datasource:  
    url: "<url>"  
    username: username
    password: password

resilience4j.circuitbreaker:
  instances:
    userInfoService:
      registerHealthIndicator: true
      ringBufferSizeInClosedState: 5
      ringBufferSizeInHalfOpenState: 3
      waitDurationInOpenState: 10s
      failureRateThreshold: 50
      recordExceptions:
        - org.springframework.web.client.HttpServerErrorException
        - java.io.IOException
        - java.util.concurrent.TimeoutException
        - org.springframework.web.client.ResourceAccessException
        - java.net.ConnectException

management:
  endpoints:
    enabled-by-default: false
  endpoint.health:
    enabled: true
    show-details: always

Upvotes: 1

Views: 2374

Answers (2)

DeMo
DeMo

Reputation: 1

Downgrade resilience4j to 1.7.0, you're issue will be fix

Upvotes: -1

Thomson Mathew
Thomson Mathew

Reputation: 439

It turns out the issues was with 1.7.1 and it worked when I downgraded to 1.7.0 as suggested in the comment. Here are my dependencies.

implementation group: 'io.github.resilience4j', name: 'resilience4j-spring-boot2', version: '1.7.0'
implementation group: 'io.github.resilience4j', name: 'resilience4j-retry', version: '1.7.0'    
implementation group: 'io.github.resilience4j', name: 'resilience4j-bulkhead', version: '1.7.0'
implementation group: 'io.github.resilience4j', name: 'resilience4j-ratelimiter', version: '1.7.0'
implementation group: 'io.github.resilience4j', name: 'resilience4j-circuitbreaker', version: '1.7.0'
implementation group: 'io.github.resilience4j', name: 'resilience4j-timelimiter', version: '1.7.0'

Upvotes: 2

Related Questions