Search code examples
apache-kafkaapache-kafka-streams

Is it possible to dynamically adjust the num.stream.threads configuration of kafka stream while the program is running?


I am running multiple instances of kafka stream in a service. I want to dynamically adjust the num.stream.threads configuration to control the priority of each instance while the program is running.

I didn't find a related method on the KafkaStream class.

I wonder if there is any other way?


Solution

  • it's not possible to update KafkaStreams configuration at runtime when you already created it (it relates not just to property num.stream.threads, but also for others as well).

    as a workaround, you could recreate a specific KafkaStreams by stopping existing one and creating and starting a new one without stopping other streams and without restarting your application. it depends on your specific use case whether it fits your needs or not.

    this could be achieved by several options. one of them - update configs (like num.stream.threads) in database per specific kafka stream flow, and from each instance of your application fetch data from database (e.g. every 10 minutes by cron expression), and if any updates found - stop existing and start a new KafkaStream that has desired updated configs. if you have a single instance of application, it could be achieved much easier via REST.


    Update since kafka-streams 2.8.0

    since kafka-streams 2.8.0, you have the ability to add and remove stream threads at runtime, without recreating stream (API to Start and Shut Down Stream Threads)

    kafkaStreams.addStreamThread();
    kafkaStreams.removeStreamThread();