0Pricing
Apache Kafka & Stream Processing Fundamentals · Lekcja

Single Message Transforms (SMTs)

Dowiedzą się Państwo, jak Single Message Transforms w Kafka Connect przekształcają rekordy w locie między konektorami a Kafka bez konieczności pisania procesora strumieniowego.

Single Message Transforms (SMTs) to bezpłatna lekcja Apache Kafka & Stream Processing Fundamentals na CoddyKit. To lekcja 4 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Apache Kafka & Stream Processing Fundamentals, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Apache Kafka & Stream Processing Fundamentals zawiera 4 lekcji w sumie.

Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.

What Are SMTs?

Single Message Transforms (SMTs) are lightweight functions applied to each record as it flows through a Kafka Connect connector.

They let you tweak data — rename fields, add metadata, route topics — without a separate processing job.

Where SMTs Run

SMTs run inside the connector worker:

  • For a source connector, after reading from the system and before writing to Kafka.
  • For a sink connector, after reading from Kafka and before writing to the target.

Configuring a Transform

Transforms are configured declaratively in the connector's JSON or properties. You name the chain, then configure each transform.

{
  "transforms": "addTs",
  "transforms.addTs.type":
    "org.apache.kafka.connect.transforms.InsertField$Value",
  "transforms.addTs.timestamp.field": "ingestedAt"
}

Common Built-in SMTs

Kafka Connect ships many useful transforms:

  • InsertField — add a static or metadata field.
  • ReplaceField — rename or drop fields.
  • MaskField — redact sensitive values.
  • ExtractField — pull one field up as the whole value.

Routing with RegexRouter

RegexRouter rewrites the destination topic name, handy for adding prefixes when ingesting many tables.

{
  "transforms": "route",
  "transforms.route.type":
    "org.apache.kafka.connect.transforms.RegexRouter",
  "transforms.route.regex": "(.*)",
  "transforms.route.replacement": "db_$1"
}

Chaining Transforms

List multiple transforms separated by commas; they run in order, each receiving the previous one's output.

{
  "transforms": "mask,route",
  "transforms.mask.type":
    "org.apache.kafka.connect.transforms.MaskField$Value",
  "transforms.mask.fields": "ssn,creditCard",
  "transforms.route.type":
    "org.apache.kafka.connect.transforms.RegexRouter",
  "transforms.route.regex": "(.*)",
  "transforms.route.replacement": "secure_$1"
}

Key vs. Value Variants

Many SMTs come in two forms, suffixed with $Key or $Value, so you can target the record's key or value independently.

For example InsertField$Key versus InsertField$Value.

Predicates

Predicates let a transform apply conditionally — for example, only to tombstone records or to a specific topic.

{
  "predicates": "isTomb",
  "predicates.isTomb.type":
    "org.apache.kafka.connect.transforms.predicates.RecordIsTombstone",
  "transforms.drop.predicate": "isTomb"
}

When NOT to Use SMTs

SMTs operate on one record at a time. They cannot:

  • Join across records or topics.
  • Aggregate or window.
  • Call external services efficiently.

For those, use Kafka Streams or ksqlDB instead.

Custom SMTs

You can implement your own by writing a class that implements the Transformation interface, packaging it as a JAR, and placing it on the worker plugin path.

public class UppercaseField
    implements Transformation<SourceRecord> {
  public SourceRecord apply(SourceRecord record) {
    // reshape and return the record
    return record;
  }
}

Best Practices

Use SMTs wisely:

  • Keep chains short and readable.
  • Mask sensitive data as early as possible.
  • Prefer predicates over per-topic connectors when filtering.
  • Move heavy logic to a stream processor.

Quick Check

Test your understanding of SMTs.

Recap

You learned about Single Message Transforms.

  • SMTs reshape each record inline within a connector.
  • Use built-ins like InsertField, ReplaceField, MaskField, RegexRouter.
  • Chain them and gate with predicates.
  • For joins, aggregations, or windows, use a stream processor instead.

Często zadawane pytania

Czy lekcja „Single Message Transforms (SMTs)” jest bezpłatna?

Tak — pełny tekst „Single Message Transforms (SMTs)” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Apache Kafka & Stream Processing Fundamentals, przejdź na CoddyKit PRO. Kurs Apache Kafka & Stream Processing Fundamentals zawiera 4 lekcji w sumie.

Co nauczysz się w „Single Message Transforms (SMTs)”?

Dowiedzą się Państwo, jak Single Message Transforms w Kafka Connect przekształcają rekordy w locie między konektorami a Kafka bez konieczności pisania procesora strumieniowego. Ćwiczysz Apache Kafka & Stream Processing Fundamentals z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.

Czy potrzebuję doświadczenia, aby zacząć Apache Kafka & Stream Processing Fundamentals?

Nie wymagamy żadnego doświadczenia. Apache Kafka & Stream Processing Fundamentals w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 4 z 4.

Ile czasu zajmuje lekcja „Single Message Transforms (SMTs)”?

Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.

Czy mogę pisać i uruchamiać kod w tej lekcji Apache Kafka & Stream Processing Fundamentals?

Tak. Każda lekcja Apache Kafka & Stream Processing Fundamentals zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.

Wszystkie lekcje w tym kursie

  1. Wprowadzenie do Kafka Connect
  2. Source Connectors do pozyskiwania danych
  3. Sink Connectors do eksportowania danych
  4. Single Message Transforms (SMTs)
← Powrót do Apache Kafka & Stream Processing Fundamentals