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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With