use of io.micronaut.configuration.kafka.config.AbstractKafkaConsumerConfiguration in project micronaut-kafka by micronaut-projects.
the class KafkaConsumerProcessor method process.
@Override
public void process(BeanDefinition<?> beanDefinition, ExecutableMethod<?, ?> method) {
List<AnnotationValue<Topic>> topicAnnotations = method.getDeclaredAnnotationValuesByType(Topic.class);
final AnnotationValue<KafkaListener> consumerAnnotation = method.getAnnotation(KafkaListener.class);
if (CollectionUtils.isEmpty(topicAnnotations)) {
topicAnnotations = beanDefinition.getDeclaredAnnotationValuesByType(Topic.class);
}
if (consumerAnnotation == null || CollectionUtils.isEmpty(topicAnnotations)) {
// No topics to consume
return;
}
final Class<?> beanType = beanDefinition.getBeanType();
String groupId = consumerAnnotation.stringValue("groupId").filter(StringUtils::isNotEmpty).orElseGet(() -> applicationConfiguration.getName().orElse(beanType.getName()));
if (consumerAnnotation.isTrue("uniqueGroupId")) {
groupId = groupId + "_" + UUID.randomUUID();
}
final String clientId = consumerAnnotation.stringValue("clientId").filter(StringUtils::isNotEmpty).orElseGet(() -> applicationConfiguration.getName().map(s -> s + '-' + NameUtils.hyphenate(beanType.getSimpleName())).orElse(null));
final OffsetStrategy offsetStrategy = consumerAnnotation.enumValue("offsetStrategy", OffsetStrategy.class).orElse(OffsetStrategy.AUTO);
final AbstractKafkaConsumerConfiguration<?, ?> consumerConfigurationDefaults = beanContext.findBean(AbstractKafkaConsumerConfiguration.class, Qualifiers.byName(groupId)).orElse(defaultConsumerConfiguration);
final DefaultKafkaConsumerConfiguration<?, ?> consumerConfiguration = new DefaultKafkaConsumerConfiguration<>(consumerConfigurationDefaults);
final Properties properties = createConsumerProperties(consumerAnnotation, consumerConfiguration, clientId, groupId, offsetStrategy);
configureDeserializers(method, consumerConfiguration);
submitConsumerThreads(method, clientId, groupId, offsetStrategy, topicAnnotations, consumerAnnotation, consumerConfiguration, properties, beanType);
}
Aggregations