I have a circuit breaker in my Spring Cloud Stream application. It is pausing/resuming stream very well when circuit is changing state and when my stream consumer is anonymous (not in a group).
When the consumer is belong to a group, pausing the stream works well, but resuming is being "ignored", which eventually ending with timeout and leaving the group. Any explanation why this inconsistent behavior occurs?
Spring cloud stream version is 3.0.8.RELEASE.
This is my circuit breaker state transition handler:
@Component
public class CircuitBreakerKafkaStream {
private final Logger log = LoggerFactory.getLogger(CircuitBreakerKafkaStream.class);
private List<InputBindingLifecycle> inputBindingLifecycles;
public CircuitBreakerKafkaStream(List<InputBindingLifecycle> inputBindingLifecycles) {
this.inputBindingLifecycles = inputBindingLifecycles;
}
@Override
// Pause or resume all of input bindings by the state of circuit breaker.
public void transitionHandler(CircuitBreaker.State toState) {
log.info("Circuit breaker is transitioning to {} state", toState.toString());
if (toState == CircuitBreaker.State.OPEN) {
log.info("Pausing kafka binder...");
gatherInputBindings().stream().forEach(binding -> binding.pause());
} else {
log.info("Resuming kafka binder...");
gatherInputBindings().stream().forEach(binding -> binding.resume());
}
}
private List<Binding<?>> gatherInputBindings() {
List<Binding<?>> inputBindings = new ArrayList<>();
for (InputBindingLifecycle inputBindingLifecycle : this.inputBindingLifecycles) {
Collection<Binding<?>> lifecycleInputBindings =
(Collection<Binding<?>>)
new DirectFieldAccessor(inputBindingLifecycle).getPropertyValue("inputBindings");
inputBindings.addAll(lifecycleInputBindings);
}
return inputBindings;
}
}
Update: I think that the problem is more specific. The circuit breaker have open
, half_open
and close
states. Once the circuit is closed and stream is resumed, it is consuming some amount of messages, and then for some reason it is stopping, until a poll timeout occurs.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…