Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.kafka.listener;

import java.lang.reflect.Array;
import java.nio.ByteBuffer;
import java.time.Duration;
import java.util.AbstractMap.SimpleEntry;
Expand Down Expand Up @@ -172,6 +173,7 @@
* @author Sanghyeok An
* @author Christian Fredriksson
* @author Timofey Barabanov
* @author Janek Lasocki-Biczysko
*/
public class KafkaMessageListenerContainer<K, V> // NOSONAR line count
extends AbstractMessageListenerContainer<K, V> implements ConsumerPauseResumeEventPublisher {
Expand Down Expand Up @@ -2238,11 +2240,14 @@ protected void doInTransactionWithoutResult(TransactionStatus status) {

private List<ConsumerRecord<K, V>> createRecordList(final ConsumerRecords<K, V> records) {
Iterator<ConsumerRecord<K, V>> iterator = records.iterator();
List<ConsumerRecord<K, V>> list = new LinkedList<>();
@SuppressWarnings("unchecked") ConsumerRecord<K, V>[] recordsArray =
(ConsumerRecord<K, V>[]) Array.newInstance(ConsumerRecord.class, records.count());
int index = 0;
while (iterator.hasNext()) {
list.add(iterator.next());
recordsArray[index] = iterator.next();
index += 1;
}
return list;
return Arrays.asList(recordsArray);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2024 the original author or authors.
* Copyright 2016-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,7 @@

package org.springframework.kafka.listener.adapter;

import java.util.Arrays;
import java.util.List;

import org.apache.kafka.clients.consumer.ConsumerRecord;
Expand All @@ -32,6 +33,7 @@
*
* @author Gary Russell
* @author Sanghyeok An
* @author Janek Lasocki-Biczysko
*/
public interface RecordFilterStrategy<K, V> {

Expand All @@ -49,9 +51,10 @@ public interface RecordFilterStrategy<K, V> {
* @return the filtered records.
* @since 2.8
*/
@SuppressWarnings("unchecked")
default List<ConsumerRecord<K, V>> filterBatch(List<ConsumerRecord<K, V>> records) {
records.removeIf(this::filter);
return records;
var recordsArray = records.stream().filter(record -> !this.filter(record)).toArray(ConsumerRecord[]::new);
return Arrays.asList(recordsArray);
}

/**
Expand Down