|
@@ -1,28 +1,26 @@
|
|
|
package com.provectus.kafka.ui.emitter;
|
|
|
|
|
|
import com.provectus.kafka.ui.model.ConsumerPosition;
|
|
|
-import com.provectus.kafka.ui.model.TopicMessageDTO;
|
|
|
import com.provectus.kafka.ui.model.TopicMessageEventDTO;
|
|
|
import com.provectus.kafka.ui.serdes.ConsumerRecordDeserializer;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.function.Predicate;
|
|
|
import java.util.function.Supplier;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.kafka.clients.consumer.KafkaConsumer;
|
|
|
import org.apache.kafka.common.errors.InterruptException;
|
|
|
+import org.apache.kafka.common.utils.Bytes;
|
|
|
import reactor.core.publisher.FluxSink;
|
|
|
|
|
|
@Slf4j
|
|
|
public class TailingEmitter extends AbstractEmitter {
|
|
|
|
|
|
- private final Supplier<EnhancedConsumer> consumerSupplier;
|
|
|
+ private final Supplier<KafkaConsumer<Bytes, Bytes>> consumerSupplier;
|
|
|
private final ConsumerPosition consumerPosition;
|
|
|
|
|
|
- public TailingEmitter(Supplier<EnhancedConsumer> consumerSupplier,
|
|
|
+ public TailingEmitter(Supplier<KafkaConsumer<Bytes, Bytes>> consumerSupplier,
|
|
|
ConsumerPosition consumerPosition,
|
|
|
- ConsumerRecordDeserializer deserializer,
|
|
|
- Predicate<TopicMessageDTO> filter,
|
|
|
+ ConsumerRecordDeserializer recordDeserializer,
|
|
|
PollingSettings pollingSettings) {
|
|
|
- super(new MessagesProcessing(deserializer, filter, false, null), pollingSettings);
|
|
|
+ super(recordDeserializer, pollingSettings);
|
|
|
this.consumerSupplier = consumerSupplier;
|
|
|
this.consumerPosition = consumerPosition;
|
|
|
}
|
|
@@ -30,12 +28,13 @@ public class TailingEmitter extends AbstractEmitter {
|
|
|
@Override
|
|
|
public void accept(FluxSink<TopicMessageEventDTO> sink) {
|
|
|
log.debug("Starting tailing polling for {}", consumerPosition);
|
|
|
- try (EnhancedConsumer consumer = consumerSupplier.get()) {
|
|
|
- assignAndSeek(consumer);
|
|
|
+ try (KafkaConsumer<Bytes, Bytes> consumer = consumerSupplier.get()) {
|
|
|
+ SeekOperations.create(consumer, consumerPosition)
|
|
|
+ .assignAndSeek();
|
|
|
while (!sink.isCancelled()) {
|
|
|
sendPhase(sink, "Polling");
|
|
|
var polled = poll(sink, consumer);
|
|
|
- send(sink, polled);
|
|
|
+ polled.forEach(r -> sendMessage(sink, r));
|
|
|
}
|
|
|
sink.complete();
|
|
|
log.debug("Tailing finished");
|
|
@@ -48,12 +47,4 @@ public class TailingEmitter extends AbstractEmitter {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void assignAndSeek(EnhancedConsumer consumer) {
|
|
|
- var seekOperations = SeekOperations.create(consumer, consumerPosition);
|
|
|
- var seekOffsets = new HashMap<>(seekOperations.getEndOffsets()); // defaulting offsets to topic end
|
|
|
- seekOffsets.putAll(seekOperations.getOffsetsForSeek()); // this will only set non-empty partitions
|
|
|
- consumer.assign(seekOffsets.keySet());
|
|
|
- seekOffsets.forEach(consumer::seek);
|
|
|
- }
|
|
|
-
|
|
|
}
|