Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added functionality to support copying both key and value between different topics #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ repositories {
}

ext {
set('connectApi', '2.8.0')
set('slf4jSimple', '1.7.30')
set('jsonPath', '2.6.0')
set('connectApi', '3.8.0')
set('slf4jSimple', '2.0.16')
set('jsonPath', '2.9.0')
}

dependencies {
Expand Down
15 changes: 9 additions & 6 deletions src/main/java/com/kakao/connector/kafka/KafkaSinkTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,12 @@ public void put(Collection<SinkRecord> records) {
if (record.value() != null) {
try {
String value = record.value().toString();
String key = record.key() != null ? record.key().toString() : null;
boolean samplingCondition = Math.random() < samplingPercentage;
if (samplingCondition
&& isFilteringMatch(value)
) {
sendRecord(value);
sendRecord(key,value);
}
} catch (Exception e) {
log.error(e.getMessage() + " / " + connectorName, e);
Expand All @@ -106,8 +107,9 @@ && isFilteringMatch(value)
if (record.value() != null) {
try {
String value = record.value().toString();
String key = record.key() != null ? record.key().toString() : null;
if (isFilteringMatch(value)) {
sendRecord(value);
sendRecord(key,value);
}
} catch (Exception e) {
log.error(e.getMessage() + " / " + connectorName, e);
Expand All @@ -117,13 +119,14 @@ && isFilteringMatch(value)
}
}

private void sendRecord(String value) {
ProducerRecord<String, String> sendRecord = getSinkRecord(value);
private void sendRecord(String key , String value) {
ProducerRecord<String, String> sendRecord = getSinkRecord(key,value);
producer.send(sendRecord, new ProducerCallback());
}

private ProducerRecord<String, String> getSinkRecord(String value) {
String messageKey = keyParsingEnabled ? parsingMessageKey(value) : null;
private ProducerRecord<String, String> getSinkRecord(String key , String value) {
String messageKey = (keyParsingEnabled && key == null) ? parsingMessageKey(value) : key;

if (timestampParsingEnabled) {
return new ProducerRecord<>(sinkTopic, null, parsingTimestamp(value), messageKey, value);
} else {
Expand Down