[英]How to configure min.insync.replicas parameter on Spring Kafka Producer?
在 Java Spring 應用程序上,我正在配置生產者以使用Acks並且還必須設置min.insync.replicas參數。
我使用以下方法設置了 Acks:
configProps.put(ProducerConfig.ACKS_CONFIG, kafkaAcks);
但我在ProducerConfig
上找不到min.insync.replicas
屬性。 查看Kafka Spring Docs我沒有找到與min.insync.replicas
相關的屬性。
那么,我如何在 Kafka Spring 應用程序上配置min.insync.replicas
?
@Bean
public KafkaTemplate<String, GenericRecord> kafkaTemplate() {
return new KafkaTemplate<>(producerFactory());
}
public ProducerFactory<String, GenericRecord> producerFactory() {
return new DefaultKafkaProducerFactory<>(getProducerGenericRecordConfigurations());
}
private Map<String, Object> getProducerGenericRecordConfigurations() {
Map<String, Object> configProps = new HashMap<>();
configProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaBootstrapServerUrl);
configProps.put(KafkaAvroDeserializerConfig.SCHEMA_REGISTRY_URL_CONFIG, schemaRegistryURL);
configProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
configProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, KafkaAvroSerializer.class);
configProps.put(ProducerConfig.ACKS_CONFIG, kafkaAcks);
return configProps;
}
min.insync.replicas
不是生產者配置。 這是一個代理/主題設置。
您可以在您的代理的server.properties
文件中的代理級別設置它。
否則,您可以按主題設置它,無論是在創建時還是通過更改它。
要附加,對於Spring Kafka,你可以配置它
spring.kafka.admin.properties.min-in-sync-replicas=3
@Bean
public KafkaAdmin kafkaAdmin() {
Map<String, Object> configs = new HashMap<>();
configs.put("spring.kafka.admin.properties.min.insync.replicas", 3); //This will apply to all topics created by KafkaAdmin
此處使用經紀人的默認值 1。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.