spring-cloud / spring-cloud-circuitbreaker

Spring Cloud Circuit Breaker API and Implementations
Apache License 2.0
335 stars 110 forks source link

Annotation based Spring Cloud Circuit breaker #84

Open patpatpat123 opened 3 years ago

patpatpat123 commented 3 years ago

Is your feature request related to a problem? Please describe. Problem: This project is amazing. However, currently, the application layer have to have code tied with the business logic to perform circuit breaker. The Spring Boot Starter Resilience4J project offers a very interesting set of annotations where methods can be annotated, and the decoration pattern will apply, making the code and understand of overall classes much clearer.

Describe the solution you'd like A possibility to have annotations @CircuitBreaker @Retry @Timeout like Spring Boot Starter Resilience4J project, but for Spring-Cloud-CircuitBreaker. It is a very clean and nice feature

Describe alternatives you've considered Well, right now, it is just a lot of code within the classes.

ryanjbaxter commented 3 years ago

Could you not just use those annotations directly?

spring-projects-issues commented 3 years ago

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

patpatpat123 commented 3 years ago

Hello @ryanjbaxter,

Just tried for the last couple of days. Updated to the latest SpringBoot 2.4.1 with the latest Ilford M6, and the Spring Cloud Circuit Breaker.

It seems the annotations @timed @count etc... are just from

    <dependency>
            <groupId>io.github.resilience4j</groupId>
            <artifactId>resilience4j-micrometer</artifactId>
        </dependency>
        <dependency>
            <groupId>io.github.resilience4j</groupId>
            <artifactId>resilience4j-reactor</artifactId>
        </dependency>
        <dependency>
            <groupId>io.github.resilience4j</groupId>
            <artifactId>resilience4j-spring-boot2</artifactId>
        </dependency>

The Spring Cloud Circuit breaker itself does not have the annotations (or am I using the wrong ones?)

And if I combine the jars (have the resilience4j ones and spring cloud circuit breaker, the resilience4j ones works, but yield the same behavior as if only resilience4j jars, with no circuit breaker).

ryanjbaxter commented 3 years ago

If you are just going to use the Resilience4J annotations why would you include the spring cloud circuitbreaker jars?

patpatpat123 commented 3 years ago

That's pretty much the purpose of this request for enhancement 😅

Is it possible to use spring cloud circuit breaker jar, without resilience4j, but still have the annotations?

Currently, if I exclude resilience4j jars, just using spring cloud circuit breaker jars, there are no annotations at all (reason of this enhancement request)

ryanjbaxter commented 3 years ago

Yeah not currently we dont have annotations. The topic has come up before, I thought there was already an issue open for this but I can't seem to find it, so maybe it was just conversations we have had.

Anyways we were waiting to see if there was enough demand from the community before actually adding any annotations.

patpatpat123 commented 3 years ago

many thanks! Hope to see it one day

camproto commented 2 years ago

I would also vote for annottations. Auto-Wiring the CircuitBreakerFactory and the replace the original method with factory.create().run() code is repeating over and over again, especiall when your are coming from @HystrixCommand. If you are going for an annotation, please add the configuration for all the exceptions (ignored) directly into the annotation and not in the application.properties, because this can cause easily refactoring issues (@hystrixCommand did this for ignored exceptions, good job!)

mehdikhelif commented 2 years ago

This would be definitively a great improvement. I think this would help a lot people who are migrating from hystrix-javanica.