Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Poll Interval for Kafka Connect SourceTask

I'm implementing a custom Source Connector using the Kafka-Connect API, that can be used to poll REST-APIs and sink the JSON response into a Kafka topic.

Now I'm wondering how to realize a polling interval for the SourceTask, how the JDBC Connector offers one. Somewhere I have to set the thread to sleep, but where do I have to do this?

like image 663
Mabi Avatar asked Apr 07 '17 14:04

Mabi


1 Answers

I solved this use case in my SourceTask implementation by adding a private field of type long to store a time stamp. At the first poll() invocation the field is not yet initialized, therefore the configured REST-APIs get polled. While this first invocation the mentioned long field get's initialized with the current time stamp. In all following poll() invocations this time stamp of the previous invocation get's checked. If the amount of elapsed milliseconds since the previous poll() is smaller than the configured interval between two polls, I send the thread to sleep since the configured milliseconds are elapsed.

like image 52
Mabi Avatar answered Oct 21 '22 10:10

Mabi