From: Kai Moritz Date: Mon, 6 Jun 2022 16:49:21 +0000 (+0200) Subject: "Fixed" the bug by adding a default-handler X-Git-Tag: default-handler-as-fix X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=aa59bc37304588ef413dead0a0dd4a653b4a139e;p=demos%2Fkafka%2Fkafkahandler "Fixed" the bug by adding a default-handler * The default-handler is _NOT_ necessary, if the handler-methods only consume the message itself. * This looks like a bug in the automatic configuration: * Without the addtional parameter of type `ConsumerRecordMetaData`, the automatically created resolvers are able to consume the payload. * After the addition of the `consumerRecordMetaData`-parameter, the automatically created resolvers are empty and fail to resolve the payload. * After the addition of the default-handler, the required resolvers are availabe again. --- diff --git a/src/main/java/de/juplo/kafka/MultiMessageConsumer.java b/src/main/java/de/juplo/kafka/MultiMessageConsumer.java index e6179e1..f0b12ef 100644 --- a/src/main/java/de/juplo/kafka/MultiMessageConsumer.java +++ b/src/main/java/de/juplo/kafka/MultiMessageConsumer.java @@ -51,4 +51,17 @@ public class MultiMessageConsumer metadata.offset()); bars.add(bar); } + + @KafkaHandler(isDefault = true) + void handleUnknown( + @Payload Object unknown, + @Header(KafkaHeaders.RECORD_METADATA) ConsumerRecordMetadata metadata) + { + log.info( + "Received an unknown message: {}", + unknown, + metadata.topic(), + metadata.partition(), + metadata.offset()); + } }