-
Notifications
You must be signed in to change notification settings - Fork 12
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
feat: stop and start consumers #77
Labels
enhancement
New feature or request
Comments
There is already a feature in kafka clients called pause/resume consumer. it will be good implement this feature in consumer mechanism. there are some good benefits except stopping/start consumer:
Resources: |
Currently, you can workaround this such as func main() {
consumerCfg := &kafka.ConsumerConfig{
Concurrency: 1,
Reader: kafka.ReaderConfig{
Brokers: []string{"localhost:29092"},
Topic: "standart-topic",
GroupID: "standart-cg",
},
RetryEnabled: false,
ConsumeFn: consumeFn,
}
consumer, _ := kafka.NewConsumer(consumerCfg)
consumer.Consume()
go func() {
fmt.Println("closing consumer")
consumer.Stop()
time.Sleep(10 * time.Second)
newConsumer, _ := kafka.NewConsumer(consumerCfg) // take a fresh instance
fmt.Println("start new fresh consumer")
newConsumer.Consume()
}()
fmt.Println("Consumer started...!")
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
<-c
}
func consumeFn(message *kafka.Message) error {
fmt.Printf("Message From %s with value %s", message.Topic, string(message.Value))
return nil
} |
cron.AddFunc(config.StartingTime, func() {
consumer, err := kafka.NewConsumer(config)
if err != nil {
panic("error initializing kafka consumer " + err.Error())
}
consumer.Consume()
time.AfterFunc(config.WorkingDuration, func() {
consumer.Stop()
})
}) |
Implemented in v2.1.9; thank you for all your support <3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Introduction
We may need to turn our consumers on and off while the application is running, depending on our needs. Currently, it is not possible to continue consuming again after consumer is closed.
The text was updated successfully, but these errors were encountered: