a0x8o / kafka

A high-throughput, distributed, publish-subscribe messaging system
Apache License 2.0
67 stars 172 forks source link

KafkaStreams needs to be gracefully shutdown but has Autoclosable interface. #20

Open kartius opened 3 years ago

kartius commented 3 years ago

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?

hitenny commented 9 months ago

I am also facing this issue. Any update?