Search code examples
javaapache-kafkabrokerkafka-topic

Where to set parameters min.insync.replicas and acks in Java?


I need to set two parameters min.insync.replicas and acks. The official documentation says that the parameter min.insync.replicas is the broker's parameter. Do I understand correctly that for all topics it should be specified inside the server.properties file? And for one - using the command kafka.config.sh. Acks parameter can only be set when configuring the producer, for example, from the app? Changes to the file producer.properties won't help?


Solution

  • Topic-related properties defined in server.properties are effective for all the topics (assuming you don't modify any configuration when creating the topic).


    Now if for any reason you want to modify one property for a specific topic, you can overwrite the global configuration by providing the new config for that topic. For example,

    bin/kafka-configs.sh \
        --zookeeper localhost:2181 \
        --alter \
        --entity-type topics \
        --entity-name yourTopicName \
        --add-config min.insync.replicas=2
    

    Alternatively, if you want to create a topic with different configuration to the one defined in server.properties you can use:

    bin/kafka-topics.sh \
        --zookeeper localhost:2181 \
        --create \
        --topic yourTopicName \
        --partitions 1  \
        --replication-factor 3 \
        --config min.insync.replicas=2
    

    Finally, if you want to verify that the configuration is effective, you can simply describe the topic and the added configurations will be shown to the output of (Configs on the top right corner):

    bin/kafka-topics \
        --zookeeper localhost:2181 \
        --describe  \
        --topic yourTopicName