use of io.micronaut.core.annotation.AnnotationMetadata in project micronaut-kafka by micronaut-projects.
the class KafkaMessageHeaderBinder method bind.
@Override
public BindingResult<T> bind(ArgumentConversionContext<T> context, ConsumerRecord<?, ?> source) {
Headers headers = source.headers();
AnnotationMetadata annotationMetadata = context.getAnnotationMetadata();
// use deprecated versions as that is what is stored in metadata
String name = annotationMetadata.stringValue(MessageHeader.class, "name").orElseGet(() -> annotationMetadata.stringValue(MessageHeader.class).orElse(context.getArgument().getName()));
Iterable<org.apache.kafka.common.header.Header> value = headers.headers(name);
if (value.iterator().hasNext()) {
Optional<T> converted = ConversionService.SHARED.convert(value, context);
return () -> converted;
} else if (context.getArgument().getType() == Optional.class) {
// noinspection unchecked
return () -> (Optional<T>) Optional.of(Optional.empty());
} else {
// noinspection unchecked
return BindingResult.EMPTY;
}
}
Aggregations