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

fix: Outbox must skip dbz_signal #43

Merged
merged 1 commit into from
Jan 16, 2024
Merged
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: 6 additions & 0 deletions src/main/java/com/birdie/kafka/connect/smt/Outbox.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ public void configure(Map<String, ?> props) {
public SourceRecord apply(SourceRecord sourceRecord) {
LOGGER.debug("Received source record: {}", sourceRecord);

/* Skipping messages from incremental snapshots */
if (sourceRecord.topic().toLowerCase().contains("dbz_signal")){
LOGGER.debug("Skipping dbz_signal record: {}", sourceRecord);
return sourceRecord;
}

if (sourceRecord.value() == null) {
LOGGER.debug("Dropping debezium-generated tombstones with null partition_key: {}", sourceRecord);
return null;
Expand Down
30 changes: 29 additions & 1 deletion src/test/java/com/birdie/kafka/connect/smt/OutboxTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.junit.Before;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.*;

public class OutboxTest {
Expand All @@ -34,6 +33,13 @@ public void after(){
.field("payload", SchemaBuilder.string().name("io.debezium.data.Json").optional().build())
.build();

private final Schema schemaSignal = SchemaBuilder.struct()
.name("Value")
.field("key", SchemaBuilder.STRING_SCHEMA)
.field("type", SchemaBuilder.STRING_SCHEMA)
.field("data", SchemaBuilder.STRING_SCHEMA)
.build();

private final Schema schemaWithPartitionKey = SchemaBuilder.struct()
.name("Value")
.field("key", SchemaBuilder.STRING_SCHEMA)
Expand Down Expand Up @@ -95,6 +101,28 @@ public void sendsAMessageToCorrectPartitionNumber() {
assertEquals(Schema.Type.STRING, transformedRecord.valueSchema().type());
}

@Test
public void sendsSignalMessage() {
Struct value = new Struct(schemaSignal);
value.put("key", "ad-hoc");
value.put("type", "execute-snapshot");
value.put("data", "data-collections");

SourceRecord record = new SourceRecord(
null,
null,
"public.dbz_signal",
null,
SchemaBuilder.bytes().optional().build(),
"ad-hoc".getBytes(),
schemaSignal,
value
);

final SourceRecord transformedRecord = transformer.apply(record);
assertEquals("public.dbz_signal", transformedRecord.topic());
}

@Test
public void sendsAMessageWithStructHeaders() {
Struct headers = new Struct(headersStructSchema);
Expand Down
Loading