単一メッセージ変換(SMT)
Kafka ConnectのSingle Message Transformsが、ストリームプロセッサーを書かずにコネクターとKafkaの間でレコードをインライン変換する方法を学びます。
「単一メッセージ変換(SMT)」はCoddyKit上の無料Apache Kafka & Stream Processing Fundamentalsレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはApache Kafka & Stream Processing Fundamentals学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Apache Kafka & Stream Processing Fundamentalsコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
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.
よくある質問
「単一メッセージ変換(SMT)」レッスンは無料ですか?
はい。「単一メッセージ変換(SMT)」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Apache Kafka & Stream Processing Fundamentalsコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Apache Kafka & Stream Processing Fundamentalsコースには全4レッスンが含まれています。
「単一メッセージ変換(SMT)」で何を学びますか?
Kafka ConnectのSingle Message Transformsが、ストリームプロセッサーを書かずにコネクターとKafkaの間でレコードをインライン変換する方法を学びます。 ブラウザで直接実行するハンズオンコードでApache Kafka & Stream Processing Fundamentalsを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Apache Kafka & Stream Processing Fundamentalsを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのApache Kafka & Stream Processing Fundamentalsは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「単一メッセージ変換(SMT)」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このApache Kafka & Stream Processing Fundamentalsレッスンでコードを書いて実行できますか?
はい。すべてのApache Kafka & Stream Processing Fundamentalsレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。