add sink event type for logging (#14)

This commit is contained in:
Anatolii Karlov 2019-08-12 12:53:51 +03:00 committed by GitHub
parent a5b8a57a0f
commit 022ca11e83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View File

@ -13,7 +13,7 @@
<packaging>jar</packaging>
<artifactId>kafka-common-lib</artifactId>
<version>0.1.1</version>
<version>0.1.2</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@ -1,6 +1,7 @@
package com.rbkmoney.kafka.common.util;
import com.rbkmoney.machinegun.eventsink.MachineEvent;
import com.rbkmoney.machinegun.eventsink.SinkEvent;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
@ -30,7 +31,7 @@ public class LogUtil {
.collect(Collectors.joining(", "));
}
public static String toSummaryString(List<ConsumerRecord<String, MachineEvent>> records) {
public static <T> String toSummaryString(List<ConsumerRecord<String, T>> records) {
if (records.isEmpty()) {
return "empty";
}
@ -48,7 +49,7 @@ public class LogUtil {
);
}
public static String toSummaryString(ConsumerRecords<String, MachineEvent> records) {
public static <T> String toSummaryString(ConsumerRecords<String, T> records) {
if (records.isEmpty()) {
return "empty";
}
@ -62,10 +63,17 @@ public class LogUtil {
return stringBuilder.toString();
}
public static String toSummaryStringWithValues(List<ConsumerRecord<String, MachineEvent>> records) {
public static String toSummaryStringWithMachineEventValues(List<ConsumerRecord<String, MachineEvent>> records) {
String valueKeysString = records.stream().map(ConsumerRecord::value)
.map(value -> String.format("'%s.%d'", value.getSourceId(), value.getEventId()))
.collect(Collectors.joining(", "));
return String.format("%s, values={%s}", toSummaryString(records), valueKeysString);
}
public static String toSummaryStringWithSinkEventValues(List<ConsumerRecord<String, SinkEvent>> records) {
String valueKeysString = records.stream().map(ConsumerRecord::value)
.map(value -> String.format("'%s.%d'", value.getEvent().getSourceId(), value.getEvent().getEventId()))
.collect(Collectors.joining(", "));
return String.format("%s, values={%s}", toSummaryString(records), valueKeysString);
}
}