I'm using a KafkaIteamReader in a batch job using spring batch.
I can configure how much time it will listen to the topic until the job end (https://docs.spring.io/spring-batch/docs/current/api/org/springframework/batch/item/kafka/KafkaItemReader.html#setPollTimeout-java.time.Duration-)
But what i want, is that when i launch my job, i want it to listen to the kafka topic until i stop it. Kind of pollTimeout("infinity") :D. Is there a way to achieve that? Thanks.
CodePudding user response:
The default is 30 seconds for KafkaItemReader polling timeout, even if you do not specify any.
The implementation of the setPollTimeout is below:
/**
* Set a timeout for the consumer topic polling duration. Default to 30 seconds.
* @param pollTimeout for the consumer poll operation
*/
public void setPollTimeout(Duration pollTimeout) {
Assert.notNull(pollTimeout, "pollTimeout must not be null");
Assert.isTrue(!pollTimeout.isZero(), "pollTimeout must not be zero");
Assert.isTrue(!pollTimeout.isNegative(), "pollTimeout must not be negative");
this.pollTimeout = pollTimeout;
}
Generally frameworks would reserve 0 or -1 to specify forever however as you can see, you cant use 0, or -N therefore, there does not seem to be a way to set the KafkaItemTeader to poll indefinitely.
CodePudding user response:
On one hand, what pollTimeOut function does is setting a timeout for the consumer topic polling duration.
On the other hand, what you want to do is set no time out. So, what I would do, if it's possible, is just don't use the SetPollTimeOut function. If that's is impossible, I would try to use a very long time as a timeout, so it seems like it's almost "infinity", as you need.
As I said, I'm not sure if it's possible to don't use the function at all, but about what you need, making it an infinity time, I'm pretty sure it's not possible at all because the default value of the function is 30 seconds, so that means that pollTimeOut(0), would be equal to 30 seconds.