ubuntu_noob
ubuntu_noob

Reputation: 2365

Can a consumer be accessed after it is closed?

I am closing the consumer after everytime it runs ( consumer1.close() ) hoping to avoid unnecessary running until I want the consumer to run again. I do want the same consumer to run again when I call it's run function. But obviously when I run the consumer1.poll() again, it says it is closed.

Is there a better way to handle the consumer to run it only when desired? I have also read about pause() and resume (), how effective is it in conserving resources?

Upvotes: 0

Views: 950

Answers (1)

Giorgos Myrianthous
Giorgos Myrianthous

Reputation: 39810

Every time you start your consumer make sure to use the same consumer group so that your consumer can continue consuming messages from the point that it was left before being closed down.


props.put("group.id", "my-consumer-group-id");
props.put("auto.offset.reset", "latest");

Upvotes: 1

Related Questions