Search in sources :

Example 1 with KafkaTemplate

use of org.springframework.kafka.core.KafkaTemplate in project SONG by overture-stack.

the class KafkaConfig method kafkaTemplate.

@Bean
public KafkaTemplate<String, String> kafkaTemplate() {
    val template = new KafkaTemplate<>(producerFactory());
    template.setDefaultTopic(defaultTopic);
    return template;
}
Also used : lombok.val(lombok.val) KafkaTemplate(org.springframework.kafka.core.KafkaTemplate) Bean(org.springframework.context.annotation.Bean)

Example 2 with KafkaTemplate

use of org.springframework.kafka.core.KafkaTemplate in project spring-boot by spring-projects.

the class KafkaAutoConfiguration method kafkaTemplate.

@Bean
@ConditionalOnMissingBean(KafkaTemplate.class)
public KafkaTemplate<?, ?> kafkaTemplate(ProducerFactory<Object, Object> kafkaProducerFactory, ProducerListener<Object, Object> kafkaProducerListener, ObjectProvider<RecordMessageConverter> messageConverter) {
    PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
    KafkaTemplate<Object, Object> kafkaTemplate = new KafkaTemplate<>(kafkaProducerFactory);
    messageConverter.ifUnique(kafkaTemplate::setMessageConverter);
    map.from(kafkaProducerListener).to(kafkaTemplate::setProducerListener);
    map.from(this.properties.getTemplate().getDefaultTopic()).to(kafkaTemplate::setDefaultTopic);
    map.from(this.properties.getTemplate().getTransactionIdPrefix()).to(kafkaTemplate::setTransactionIdPrefix);
    return kafkaTemplate;
}
Also used : KafkaTemplate(org.springframework.kafka.core.KafkaTemplate) PropertyMapper(org.springframework.boot.context.properties.PropertyMapper) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

Bean (org.springframework.context.annotation.Bean)2 KafkaTemplate (org.springframework.kafka.core.KafkaTemplate)2 lombok.val (lombok.val)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 PropertyMapper (org.springframework.boot.context.properties.PropertyMapper)1