0070. Override Kafka Properties for Producer - dkkahm/study-kafka-with-spring GitHub Wiki
Configuration for ProducerFactory
@Configuration
public class KafkaConfig {
@Autowired
private KafkaProperties kafkaProperties;
@Bean
public ProducerFactory<Object, Object> producerFactory() {
var properties = kafkaProperties.buildProducerProperties();
properties.put(ProducerConfig.METADATA_MAX_AGE_CONFIG, "180000");
return new DefaultKafkaProducerFactory<Object, Object>(properties);
}
}
KafkaTemplate Bean๊น์ง ์ค์ ํ๋ ๊ฒฝ์ฐ๋ Generic์ ๋ ์์ธํ ์ค์ ํด์ผ ํจ
- <Object, Object> ์ฌ์ฉํ๋ฉด ์ค๋ฅ ๋ฐ์
@Configuration
public class KafkaConfig {
@Autowired
private KafkaProperties kafkaProperties;
@Bean
public ProducerFactory<String, String> producerFactory() {
var properties = kafkaProperties.buildProducerProperties();
properties.put(ProducerConfig.METADATA_MAX_AGE_CONFIG, "180000");
return new DefaultKafkaProducerFactory<String, String>(properties);
}
@Bean
public KafkaTemplate<String, String> kafkaTemplate() {
return new KafkaTemplate<String, String>(producerFactory());
}
}