kafka icon indicating copy to clipboard operation
kafka copied to clipboard

KafkaStreams needs to be gracefully shutdown but has Autoclosable interface.

Open kartius opened this issue 3 years ago • 1 comments

I implemented a kafka streams application. And by the confluent example created a shutdown hook for the gracefully shutdown.

        final Topology topology = buildTopology();
        KafkaStreams kafkaStreams = new KafkaStreams(topology, properties);
        kafkaStreams.start();
        Runtime.getRuntime().addShutdownHook(new Thread(kafkaStreams::close));

This is working good. But from the other side I have a sonar cube complaining for the issue that I should create KafkaStreams using try-with-resources. But in this case kafka streams closed and isn't listening events. As I now in prevoious versions KafkaStreams didn't implement Autoclosable interface. What could you suggest to use gracefully shutdown and to avoid a sonar complaining? Or should I use gracefully shutdown and try-with-resources both?

kartius avatar Jun 16 '21 13:06 kartius

I am also facing this issue. Any update?

hitenny avatar Feb 24 '24 18:02 hitenny