org.zodiac.autoconfigure.kafka.KafkaConfigAutoConfiguration Maven / Gradle / Ivy
package org.zodiac.autoconfigure.kafka;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.core.annotation.Order;
import org.springframework.lang.NonNull;
import org.zodiac.commons.constants.SystemPropertiesConstants;
import org.zodiac.core.application.AppContext;
@SpringBootConfiguration
@EnableConfigurationProperties(value = {KafkaConfigProperties.class, KafkaAvailabilityProperties.class})
@ConditionalOnProperty(name = SystemPropertiesConstants.Zodiac.SPRING_KAFKA_ENABLED, havingValue = "true")
@ConditionalOnClass(name = {"org.apache.kafka.clients.KafkaClient", "org.springframework.kafka.core.KafkaAdmin", "org.zodic.kafka.KafkaConfigInfo"})
public class KafkaConfigAutoConfiguration implements ApplicationContextAware, InitializingBean, BeanPostProcessor {
private AppContext appContext;
private KafkaConfigProperties properties;
public KafkaConfigAutoConfiguration(AppContext appContext, KafkaConfigProperties properties) {
this.appContext = appContext;
this.properties = properties;
org.zodic.kafka.util.KafkaUtil.setKafkaProperties(properties);
}
@Override
public void setApplicationContext(@NonNull ApplicationContext applicationContext) throws BeansException {
org.zodic.kafka.util.KafkaUtil.setApplicationContext(applicationContext);
}
@Override
public void afterPropertiesSet() {
org.zodic.kafka.consumer.KafkaConsumerContainerFactory kafkaContainerFactory = new org.zodic.kafka.consumer.KafkaConsumerContainerFactory(appContext);
kafkaContainerFactory.setKafkaConfigInfo(properties);
kafkaContainerFactory.buildContainerFactory();
org.zodic.kafka.admin.KafkaAdminClientFactory kafkaAdminClientFactory = new org.zodic.kafka.admin.KafkaAdminClientFactory().setKafkaConfigInfo(properties);
kafkaAdminClientFactory.buildAdminClients();
}
@Order
@Bean
@ConditionalOnMissingBean
protected org.zodic.kafka.support.KafkaOpsTemplate kafkaOpsTemplate(org.zodic.kafka.KafkaConfigInfo properties) {
return new org.zodic.kafka.support.KafkaOpsTemplate(properties);
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnClass(value = {org.aspectj.lang.annotation.Pointcut.class})
protected org.zodic.kafka.aop.SwimlaneListenerInterceptor swimlaneListenerInterceptor() {
return new org.zodic.kafka.aop.SwimlaneListenerInterceptor().setKafkaConfigInfo(properties);
}
@Bean
@ConditionalOnClass(name = {"org.springframework.kafka.config.KafkaListenerEndpointRegistry"})
protected org.zodic.kafka.availability.KafkaAvailabilityEventListener kafkaAvailabilityEventListener(
org.springframework.kafka.config.KafkaListenerEndpointRegistry kafkaListenerEndpointRegistry,
KafkaAvailabilityProperties kafkaAvailabilityProperties) {
return new org.zodic.kafka.availability.KafkaAvailabilityEventListener(kafkaListenerEndpointRegistry, kafkaAvailabilityProperties);
}
}