Skip to content

Commit

Permalink
close consumer once completed
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Aguilera <[email protected]>
  • Loading branch information
jorgeaguileraseqera committed Oct 27, 2022
1 parent 5b31131 commit 9fd1844
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ class TopicHandler {

TopicHandler perform() {
createConsumer()
listening ? runAsync() : consume()
if( listening ) {
runAsync()
}else{
consume()
closeConsumer()
}
return this
}

Expand All @@ -92,6 +97,10 @@ class TopicHandler {
consumer
}

void closeConsumer(){
consumer.close()
}

void consume(){
try {
final records = consumer.poll(duration)
Expand All @@ -114,6 +123,8 @@ class TopicHandler {
log.trace "Closing $topic kafka thread"
}catch(Exception e){
log.error "Exception reading kafka topic $topic",e
}finally{
closeConsumer()
}
})
}
Expand Down

0 comments on commit 9fd1844

Please sign in to comment.