fix: keep jt808 raw history consumer current
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package com.lingniu.ingest.api.consumer;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public final class EnvelopeConsumerProcessor {
|
||||
@@ -32,13 +34,40 @@ public final class EnvelopeConsumerProcessor {
|
||||
if (record == null) {
|
||||
throw new IllegalArgumentException("record must not be null");
|
||||
}
|
||||
EnvelopeIngestResult result = ingestor.tryIngest(record.payload());
|
||||
EnvelopeIngestResult result = processAll(List.of(record)).getFirst();
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<EnvelopeIngestResult> processAll(List<EnvelopeConsumerRecord> records) {
|
||||
if (records == null) {
|
||||
throw new IllegalArgumentException("records must not be null");
|
||||
}
|
||||
if (records.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
List<byte[]> payloads = new ArrayList<>(records.size());
|
||||
for (EnvelopeConsumerRecord record : records) {
|
||||
if (record == null) {
|
||||
throw new IllegalArgumentException("record must not be null");
|
||||
}
|
||||
payloads.add(record.payload());
|
||||
}
|
||||
List<EnvelopeIngestResult> results = ingestor.tryIngestAll(payloads);
|
||||
if (results.size() != records.size()) {
|
||||
throw new IllegalStateException("ingestor result count does not match record count");
|
||||
}
|
||||
for (int i = 0; i < records.size(); i++) {
|
||||
publishDeadLetterIfNeeded(records.get(i), results.get(i));
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private void publishDeadLetterIfNeeded(EnvelopeConsumerRecord record, EnvelopeIngestResult result) {
|
||||
// 派生消费者不在这里抛出业务异常给 Kafka worker;坏消息统一进入 DLQ,
|
||||
// worker 看到 process 正常返回后才能提交 offset,避免同一坏消息无限阻塞消费组。
|
||||
if (DEAD_LETTER_STATUSES.contains(result.status())) {
|
||||
deadLetterSink.publish(toDeadLetter(record, result));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private EnvelopeDeadLetterRecord toDeadLetter(EnvelopeConsumerRecord record, EnvelopeIngestResult result) {
|
||||
|
||||
@@ -1,6 +1,20 @@
|
||||
package com.lingniu.ingest.api.consumer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface EnvelopeIngestor {
|
||||
EnvelopeIngestResult tryIngest(byte[] kafkaValue);
|
||||
|
||||
default List<EnvelopeIngestResult> tryIngestAll(List<byte[]> kafkaValues) {
|
||||
if (kafkaValues == null || kafkaValues.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
List<EnvelopeIngestResult> results = new ArrayList<>(kafkaValues.size());
|
||||
for (byte[] kafkaValue : kafkaValues) {
|
||||
results.add(tryIngest(kafkaValue));
|
||||
}
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user