-
Notifications
You must be signed in to change notification settings - Fork 301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pausing and resuming consumption #261
Comments
Pause/Resume are not currently supported in Spring Cloud Stream. You can pause() and seek() using Elmhurst (2.0) because the These features are available today if you use spring-kafka directly. |
Resolves spring-cloud#261 This facilitates pause/resume.
Hello @garyrussell, Thank you for your quick reply. I have seen the An event is called after Is there any way to resume(), only when some other service returns true, signalling resume(). |
See the pull request and the documentation update included therein. The interval is fixed but you don't always have to act on the idle event so, of course, you can call some other service to see if you actually want to resume - the idle event is emitted each time the interval elapses so you don't have to resume on the first call, you'll get another event later. I chose 30 seconds as the default interval. This is the application I used to test it... @SpringBootApplication
@EnableBinding(Sink.class)
public class KbGh261Application {
public static void main(String[] args) {
SpringApplication.run(KbGh261Application.class, args);
}
@StreamListener(Sink.INPUT)
public void in(String in, @Header(KafkaHeaders.CONSUMER) Consumer<?, ?> consumer) {
System.out.println(in);
consumer.pause(Collections.singleton(new TopicPartition("gh261", 0)));
}
@Bean
public ApplicationListener<ListenerContainerIdleEvent> idleListener() {
return event -> {
System.out.println(event + " paused:" + event.getConsumer().paused());
if (event.getConsumer().paused().size() > 0) {
event.getConsumer().resume(event.getConsumer().paused());
}
};
}
} And this is the result...
(See the |
@garyrussell, Thank you for the explanation. It seems perfect for my usecase. But, how can I use it? I'm using the 1.4.1.RELEASE of spring boot and I can see from the release info, Are the milestone releases stable for production use? If yes, How should I go about about updating the versions of all dependencies. |
It requires spring-kafka 2.0 or higher - earlier versions do not provide access the to the No, milestones are not suitable for production use. If you can't wait for the 2.0 release of spring cloud stream, you have no choice but to use spring-kafka 2.0.1.RELEASE directly. |
I extend the Is there any standard way to make this switch? |
@nitin02 Sorry for the delay in replying; I somehow missed the notification. It's not clear what you are asking; sorry. |
Is there a way to pause consumption of messages from kafka on API call (or some other way externally) and to resume whenever necessary. Also, To reset consumer offset to fetch latest messages, I can see the property being set but it seems like is there a way to do it in real-time?
I'm currently using Kafka (0.10+) with autoCommit currently and all defaults.
What would be the best way to acheive this? To pause/resume consumer from a external API call and to flush offset from a external API call.
The text was updated successfully, but these errors were encountered: