Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.5k views
in Technique[技术] by (71.8m points)

Resume kafka stream when consumer is within a group

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...