|
|
@ -1,5 +1,5 @@
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright 2012-2018 the original author or authors.
|
|
|
|
* Copyright 2012-2019 the original author or authors.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.kafka;
|
|
|
|
import org.springframework.beans.factory.ObjectProvider;
|
|
|
|
import org.springframework.beans.factory.ObjectProvider;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
|
|
|
|
|
|
|
import org.springframework.boot.autoconfigure.kafka.KafkaProperties.Listener.Type;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.kafka.annotation.EnableKafka;
|
|
|
|
import org.springframework.kafka.annotation.EnableKafka;
|
|
|
@ -28,6 +29,9 @@ import org.springframework.kafka.core.ConsumerFactory;
|
|
|
|
import org.springframework.kafka.core.KafkaTemplate;
|
|
|
|
import org.springframework.kafka.core.KafkaTemplate;
|
|
|
|
import org.springframework.kafka.listener.AfterRollbackProcessor;
|
|
|
|
import org.springframework.kafka.listener.AfterRollbackProcessor;
|
|
|
|
import org.springframework.kafka.listener.ErrorHandler;
|
|
|
|
import org.springframework.kafka.listener.ErrorHandler;
|
|
|
|
|
|
|
|
import org.springframework.kafka.support.converter.BatchMessageConverter;
|
|
|
|
|
|
|
|
import org.springframework.kafka.support.converter.BatchMessagingMessageConverter;
|
|
|
|
|
|
|
|
import org.springframework.kafka.support.converter.MessageConverter;
|
|
|
|
import org.springframework.kafka.support.converter.RecordMessageConverter;
|
|
|
|
import org.springframework.kafka.support.converter.RecordMessageConverter;
|
|
|
|
import org.springframework.kafka.transaction.KafkaAwareTransactionManager;
|
|
|
|
import org.springframework.kafka.transaction.KafkaAwareTransactionManager;
|
|
|
|
|
|
|
|
|
|
|
@ -46,6 +50,8 @@ class KafkaAnnotationDrivenConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
private final RecordMessageConverter messageConverter;
|
|
|
|
private final RecordMessageConverter messageConverter;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final BatchMessageConverter batchMessageConverter;
|
|
|
|
|
|
|
|
|
|
|
|
private final KafkaTemplate<Object, Object> kafkaTemplate;
|
|
|
|
private final KafkaTemplate<Object, Object> kafkaTemplate;
|
|
|
|
|
|
|
|
|
|
|
|
private final KafkaAwareTransactionManager<Object, Object> transactionManager;
|
|
|
|
private final KafkaAwareTransactionManager<Object, Object> transactionManager;
|
|
|
@ -56,12 +62,15 @@ class KafkaAnnotationDrivenConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
KafkaAnnotationDrivenConfiguration(KafkaProperties properties,
|
|
|
|
KafkaAnnotationDrivenConfiguration(KafkaProperties properties,
|
|
|
|
ObjectProvider<RecordMessageConverter> messageConverter,
|
|
|
|
ObjectProvider<RecordMessageConverter> messageConverter,
|
|
|
|
|
|
|
|
ObjectProvider<BatchMessageConverter> batchMessageConverter,
|
|
|
|
ObjectProvider<KafkaTemplate<Object, Object>> kafkaTemplate,
|
|
|
|
ObjectProvider<KafkaTemplate<Object, Object>> kafkaTemplate,
|
|
|
|
ObjectProvider<KafkaAwareTransactionManager<Object, Object>> kafkaTransactionManager,
|
|
|
|
ObjectProvider<KafkaAwareTransactionManager<Object, Object>> kafkaTransactionManager,
|
|
|
|
ObjectProvider<ErrorHandler> errorHandler,
|
|
|
|
ObjectProvider<ErrorHandler> errorHandler,
|
|
|
|
ObjectProvider<AfterRollbackProcessor<Object, Object>> afterRollbackProcessor) {
|
|
|
|
ObjectProvider<AfterRollbackProcessor<Object, Object>> afterRollbackProcessor) {
|
|
|
|
this.properties = properties;
|
|
|
|
this.properties = properties;
|
|
|
|
this.messageConverter = messageConverter.getIfUnique();
|
|
|
|
this.messageConverter = messageConverter.getIfUnique();
|
|
|
|
|
|
|
|
this.batchMessageConverter = batchMessageConverter.getIfUnique(
|
|
|
|
|
|
|
|
() -> new BatchMessagingMessageConverter(this.messageConverter));
|
|
|
|
this.kafkaTemplate = kafkaTemplate.getIfUnique();
|
|
|
|
this.kafkaTemplate = kafkaTemplate.getIfUnique();
|
|
|
|
this.transactionManager = kafkaTransactionManager.getIfUnique();
|
|
|
|
this.transactionManager = kafkaTransactionManager.getIfUnique();
|
|
|
|
this.errorHandler = errorHandler.getIfUnique();
|
|
|
|
this.errorHandler = errorHandler.getIfUnique();
|
|
|
@ -73,7 +82,9 @@ class KafkaAnnotationDrivenConfiguration {
|
|
|
|
public ConcurrentKafkaListenerContainerFactoryConfigurer kafkaListenerContainerFactoryConfigurer() {
|
|
|
|
public ConcurrentKafkaListenerContainerFactoryConfigurer kafkaListenerContainerFactoryConfigurer() {
|
|
|
|
ConcurrentKafkaListenerContainerFactoryConfigurer configurer = new ConcurrentKafkaListenerContainerFactoryConfigurer();
|
|
|
|
ConcurrentKafkaListenerContainerFactoryConfigurer configurer = new ConcurrentKafkaListenerContainerFactoryConfigurer();
|
|
|
|
configurer.setKafkaProperties(this.properties);
|
|
|
|
configurer.setKafkaProperties(this.properties);
|
|
|
|
configurer.setMessageConverter(this.messageConverter);
|
|
|
|
MessageConverter messageConverterToUse = (this.properties.getListener().getType()
|
|
|
|
|
|
|
|
.equals(Type.BATCH)) ? this.batchMessageConverter : this.messageConverter;
|
|
|
|
|
|
|
|
configurer.setMessageConverter(messageConverterToUse);
|
|
|
|
configurer.setReplyTemplate(this.kafkaTemplate);
|
|
|
|
configurer.setReplyTemplate(this.kafkaTemplate);
|
|
|
|
configurer.setTransactionManager(this.transactionManager);
|
|
|
|
configurer.setTransactionManager(this.transactionManager);
|
|
|
|
configurer.setErrorHandler(this.errorHandler);
|
|
|
|
configurer.setErrorHandler(this.errorHandler);
|
|
|
|