Skip to content

Configure Project to use resilience4j Circuit Breaker - Feign #13

Description

@hazartilirot

Hi there.

Actually, you almost don't need resilience4j. I have seen the latest Sergey's implementation, but I decided to stick to what I had seen in the video with Hystrix

pom.xml

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
            <version>4.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-circuitbreaker-resilience4j</artifactId>
        </dependency>

Then, you need to enable fallback as it is suggested in the video though it has slightly different parameters:

In the application.properties / application.yml of the PhotoAppApiUsers set the following:

spring:  
  cloud:
    openfeign:
      circuitbreaker:
        enabled: true

I would also suggest switching to the ERROR mode.

logging:
  level:
    com:
      appsdeveloperblog:
        photoapp:
          api:
            users:
              client:
                AlbumsServiceClient: ERROR

I couldn't have figured out as to why I see an exception. The result was completely different from what Sergey gets in the video.

Screenshot 2023-04-10 at 09 48 02

Finally, when I change the DEBUG to ERROR mode my console is clean now.

The last step is quite the same as you see in the video.

@FeignClient(name = "albums-ws", fallback = AlbumsFallback.class)
public interface AlbumsServiceClient {

    @GetMapping("/users/{id}/albums")
    List<AlbumResponseModel> getAlbums(@PathVariable String id);
}

@Component
class AlbumsFallback implements AlbumsServiceClient {

    @Override
    public List<AlbumResponseModel> getAlbums(String id) {
        return new ArrayList<>();
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions