0Pricing
Apache Kafka & Stream Processing Fundamentals · درس

تحويلات الرسائل المفردة (SMTs)

تعلّم كيف تعيد Kafka Connect تشكيل السجلات مباشرةً بين الموصلات وKafka باستخدام تحويلات الرسائل المفردة، من دون كتابة معالج تدفق.

تحويلات الرسائل المفردة (SMTs) درس مجاني في Apache Kafka & Stream Processing Fundamentals على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في 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.

الأسئلة الشائعة

هل درس «تحويلات الرسائل المفردة (SMTs)» مجاني؟

نعم — نص درس «تحويلات الرسائل المفردة (SMTs)» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Apache Kafka & Stream Processing Fundamentals، انتقل إلى CoddyKit PRO. تتضمن دورة Apache Kafka & Stream Processing Fundamentals 4 دروس في المجموع.

ماذا ستتعلم في «تحويلات الرسائل المفردة (SMTs)»؟

تعلّم كيف تعيد Kafka Connect تشكيل السجلات مباشرةً بين الموصلات وKafka باستخدام تحويلات الرسائل المفردة، من دون كتابة معالج تدفق. تتمرن على Apache Kafka & Stream Processing Fundamentals مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Apache Kafka & Stream Processing Fundamentals؟

لا تُشترط خبرة سابقة. Apache Kafka & Stream Processing Fundamentals على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.

كم من الوقت يستغرق درس «تحويلات الرسائل المفردة (SMTs)»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Apache Kafka & Stream Processing Fundamentals هذا؟

نعم. كل درس في Apache Kafka & Stream Processing Fundamentals يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. مقدمة إلى Kafka Connect
  2. موصلات المصدر لاستيعاب البيانات
  3. موصلات الوجهة لتصدير البيانات
  4. تحويلات الرسائل المفردة (SMTs)
← العودة إلى Apache Kafka & Stream Processing Fundamentals