Search code examples
apache-kafkaspring-cloud-streamspring-cloud-stream-binder-kafka

Pause message consumption and resume after time interval


We are using spring-cloud-stream to work with kafka. And I need to add some interval between getting data by consumer from single topic. batch-node is already set as true , also fetch-max-wait, fetch-min-size, max-poll-records are already tuned.

Should I do something with idleEventInterval, or it's wrong way?


Solution

  • You can pause/resume the container as needed (avoiding a rebalance).

    See https://docs.spring.io/spring-cloud-stream/docs/3.2.1/reference/html/spring-cloud-stream.html#binding_visualization_control

    Since version 3.1 we expose org.springframework.cloud.stream.binding.BindingsLifecycleController which is registered as bean and once injected could be used to control the lifecycle of individual bindings

    If you only want to delay for a short time, you can set the container's idleBetweenPolls property, using a ListenerContainerCustomizer bean.