0

I have successfully implemented some spring Integration Flow.

I am looking to have a circuit breaker either the same one for each endpoints or either at the flow level. I have already read this documentation https://docs.spring.io/spring-integration/reference/html/handler-advice.html, but I havent find my answer.

Should I use some AOP ?

Thanks

G.

ggr
  • 294
  • 1
  • 9

2 Answers2

1

I'm not sure what you have missed in the mentioned docs, but RequestHandlerCircuitBreakerAdvice is indeed over there: https://docs.spring.io/spring-integration/reference/html/handler-advice.html#circuit-breaker-advice

The advises like this should be applied in the Java DSL with this configuration option:

.transform(..., c -> c.advice(expressionAdvice()))

Pay attention to that advice(expressionAdvice()) call. The expressionAdvice() is a bean method. So, you can do something similar for the RequestHandlerCircuitBreakerAdvice and any your endpoints in the flow which need to be guarded by the circuit.

And yes, you can use only a single bean for the RequestHandlerCircuitBreakerAdvice. It does keep a state for any endpoint it is called against:

protected Object doInvoke(ExecutionCallback callback, Object target, Message<?> message) {
    AdvisedMetadata metadata = this.metadataMap.get(target);
    if (metadata == null) {
        this.metadataMap.putIfAbsent(target, new AdvisedMetadata());
        metadata = this.metadataMap.get(target);
    }
Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
0

Thanks for your answer @artem-bilan. I really appreciate that a spring integration team member anwsered to this.

After more thoughts, I have reformulated my problem.

Given an IntegrationFlow, with a specific error channel, if there are more than a given amount of errors in given span time (more than 10 errors in 10s), I want to stop polling the input channel.

So I redirect all the errors for this flow to the specific flow error channel. An error counter is incremented, and then if the threshold is reached in the given span time, I stop the poller.

I have a second flow that monitor "stopped" pollers, and it restart them after some time.

[UPDATE]

I do have use your recommendations. Mainly because I the framework dont solve your problem, your probably wrong. And I was wrong.

Thanks !

ggr
  • 294
  • 1
  • 9