Skip to content

Commit 791d468

Browse files
Apply review feedback: fix TopicPartition bucketing, empty batch commit path, error record selection, and docs typo
Agent-Logs-Url: https://github.com/micronaut-projects/micronaut-kafka/sessions/d513a696-a1bd-4396-a074-79da5f5ae36b Co-authored-by: graemerocher <66626+graemerocher@users.noreply.github.com>
1 parent bd2e407 commit 791d468

4 files changed

Lines changed: 8 additions & 5 deletions

File tree

kafka/src/main/java/io/micronaut/configuration/kafka/processor/ConsumerStateBatch.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ protected void processRecords(ConsumerRecords<?, ?> consumerRecords, @Nullable M
9292
}
9393
final ConsumerRecords<?, ?> interceptedConsumerRecords = kafkaConsumerProcessor.interceptRecords(info, consumerRecords);
9494
if (interceptedConsumerRecords.isEmpty()) {
95+
handleResult(normalizeResult(null), consumerRecords);
9596
failed = false;
9697
return;
9798
}

kafka/src/main/java/io/micronaut/configuration/kafka/processor/ConsumerStateSingle.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,16 @@ protected void processRecords(ConsumerRecords<?, ?> consumerRecords,
8888
Optional.ofNullable(info.seekArg).ifPresent(argument -> boundArguments.put(argument, seek));
8989
Optional.ofNullable(info.ackArg).ifPresent(argument -> boundArguments.put(argument, (KafkaAcknowledgement) () -> kafkaConsumer.commitSync(currentOffsets)));
9090

91+
ConsumerRecord<?, ?> interceptedConsumerRecord = null;
9192
try {
92-
ConsumerRecord<?, ?> interceptedConsumerRecord = kafkaConsumerProcessor.interceptRecord(info, consumerRecord);
93+
interceptedConsumerRecord = kafkaConsumerProcessor.interceptRecord(info, consumerRecord);
9394
if (interceptedConsumerRecord != null) {
9495
process(interceptedConsumerRecord, consumerRecords);
9596
}
9697
} catch (Exception e) {
97-
if (resolveWithErrorStrategy(consumerRecords, consumerRecord, e)) {
98-
resetTheFollowingPartitions(consumerRecord, iterator);
98+
final ConsumerRecord<?, ?> errorRecord = interceptedConsumerRecord != null ? interceptedConsumerRecord : consumerRecord;
99+
if (resolveWithErrorStrategy(consumerRecords, errorRecord, e)) {
100+
resetTheFollowingPartitions(errorRecord, iterator);
99101
failed = true;
100102
return;
101103
}

kafka/src/main/java/io/micronaut/configuration/kafka/processor/KafkaConsumerProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ <K, V> ConsumerRecords<K, V> interceptRecords(@NonNull ConsumerInfo consumerInfo
455455
for (ConsumerRecord<K, V> consumerRecord : consumerRecords) {
456456
ConsumerRecord<K, V> intercepted = interceptRecord(consumerInfo, consumerRecord);
457457
if (intercepted != null) {
458-
TopicPartition topicPartition = new TopicPartition(consumerRecord.topic(), consumerRecord.partition());
458+
TopicPartition topicPartition = new TopicPartition(intercepted.topic(), intercepted.partition());
459459
interceptedRecords.computeIfAbsent(topicPartition, ignored -> new ArrayList<>()).add(intercepted);
460460
}
461461
}

src/main/docs/guide/kafkaListener/kafkaListenerInterceptors.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
To inspect, filter, or wrap consumed records before Micronaut binds them to a ann:configuration.kafka.annotation.KafkaListener[] method, define a bean that implements api:configuration.kafka.ConsumerRecordInterceptor[].
1+
To inspect, filter, or wrap consumed records before Micronaut binds them to an ann:configuration.kafka.annotation.KafkaListener[] method, define a bean that implements api:configuration.kafka.ConsumerRecordInterceptor[].
22

33
Interceptors run before argument binding for single-record listeners and before Micronaut builds the batch arguments for batch listeners. If multiple interceptor beans are present, Micronaut applies them in order.
44

0 commit comments

Comments
 (0)