在反序列化之前有没有办法读取消息头?
我已经写了下面的代码,但我不得不在这里反序列化,有什么办法不反序列化?
while (true) {
ConsumerRecords<String, String> consumerRecords = consumer.poll(Duration.ofSeconds(1));
for (ConsumerRecord<String, String> consumerRecord : consumerRecords) {
for (Header header : consumerRecord.headers()) {
if (header.key().equals("my header")) {
String data = "\n New record received .. \n" +
" Value: " + consumerRecord.value() +
" Topic: " + consumerRecord.topic() +
" Header: " + header.key() +
" Partition: " + consumerRecord.partition();
logger.info(data);
}
}
}
}