io.quarkus.kafka.client.runtime.devui.model.converter.KafkaModelConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quarkus-kafka-client Show documentation
Show all versions of quarkus-kafka-client Show documentation
Connect to Apache Kafka with its native API
package io.quarkus.kafka.client.runtime.devui.model.converter;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.common.header.Header;
import org.apache.kafka.common.utils.Bytes;
import io.quarkus.kafka.client.runtime.devui.model.response.KafkaMessage;
public class KafkaModelConverter {
public KafkaMessage convert(ConsumerRecord message) {
return new KafkaMessage(
message.topic(),
message.partition(),
message.offset(),
message.timestamp(),
Optional.ofNullable(message.key()).map((t) -> {
return new String(t.get(), StandardCharsets.UTF_8);
}).orElse(null),
Optional.ofNullable(message.value()).map((t) -> {
return new String(t.get(), StandardCharsets.UTF_8);
}).orElse(null),
headers(message));
}
private static Map headers(ConsumerRecord message) {
return StreamSupport.stream(message.headers().spliterator(), false)
.collect(Collectors.toMap(Header::key, header -> new String(header.value(), StandardCharsets.UTF_8)));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy