Kafka
Publishes each flushed WAL batch as a Kafka transaction. read_committed consumers never see a partial batch. A retry can publish the same complete transaction again, so consumers should be idempotent on event id. See Exactly-once delivery.
The source and this destination share one format. A Mfd Kafka source can consume what this destination produces.
Before you begin
You need:
- Network access to every broker in
brokers. - Permission to produce, and to use transactions (
transactional.id). - If the cluster uses SASL, a username and password for the
PLAINmechanism. - For
format: debezium_avro, a Schema Registry URL.
TLS is not available in current builds
Mfd connects with security_protocol PLAINTEXT or SASL_PLAINTEXT. Clusters that require TLS (SSL or SASL_SSL) can't be reached directly yet.
Configure
Store the SASL password in an environment variable.
export KAFKA_SASL_PASSWORD="your-password"from mfd import Config, DataSinkKafka, EnvRef, Pipeline
cfg = Config.discover()
out = cfg.data_sink(
"orders_bus",
DataSinkKafka(
brokers="broker-1:9092,broker-2:9092",
topic_prefix="dbserver1",
format="debezium_json",
security_protocol="SASL_PLAINTEXT",
sasl_mechanism="PLAIN",
sasl_username="mfd",
sasl_password=EnvRef("KAFKA_SASL_PASSWORD"),
),
)
cfg.pipeline("orders", Pipeline(data_source=cfg.get_data_source("orders"), data_sink=out))
cfg.save()mfd connect data-sink kafka \
--pipeline orders \
--name orders_bus \
--brokers broker-1:9092,broker-2:9092 \
--topic-prefix dbserver1 \
--format debezium_json \
--security-protocol SASL_PLAINTEXT \
--sasl-mechanism PLAIN \
--sasl-username mfd \
--sasl-password '${KAFKA_SASL_PASSWORD}'data_sinks:
orders_bus:
Kafka:
brokers: "broker-1:9092,broker-2:9092"
topic_prefix: dbserver1
format: debezium_json
security_protocol: SASL_PLAINTEXT
sasl_mechanism: PLAIN
sasl_username: mfd
sasl_password: "${KAFKA_SASL_PASSWORD}"For a local broker without authentication, set only brokers and format.
Options
| Key | Type | Default | Description |
|---|---|---|---|
brokers | string | Required | Comma-separated bootstrap servers. |
topic | string | — | Single topic for every namespace. When set, it replaces Debezium topic naming. |
topic_prefix | string | mfd | Debezium topics are <prefix>.<schema>.<table>. JSON and Avro topics are <prefix>.<namespace>. |
format | string | json | json, avro, debezium_json, or debezium_avro. Same values as the Kafka source (source also accepts csv and xml). |
schema_registry_url | string | — | Required for debezium_avro. Confluent Schema Registry base URL. |
security_protocol | string | PLAINTEXT | PLAINTEXT or SASL_PLAINTEXT. |
sasl_mechanism | string | — | PLAIN when the cluster uses SASL. |
sasl_username | string | — | SASL username. |
sasl_password | secret | — | SASL password as a ${NAME} reference. |
Producer batching is fixed in the connector (linger.ms 5, batch.size 1 MiB, lz4 for JSON and zstd for Avro). There is no env knob for those.
How data lands
Topics. With debezium_json or debezium_avro, a namespace public.orders and topic_prefix: dbserver1 publish to dbserver1.public.orders. That matches Debezium's default topic naming. With json or avro, the topic is <prefix>.<namespace> unless you set topic.
Keys and partitions. The message key is the primary key JSON (or the whole row when the source has no PK). Kafka hashes that key, so snapshot chunks of one table can run in parallel without breaking per-key order.
Envelope. Debezium formats emit before, after, source, op (c/u/d/r), and ts_ms. source.txId is the source transaction id when the plugin sent one, otherwise the WAL compaction id. json emits the row as JSON. avro emits one row as an Avro Object Container File. Headers include __debezium.source.table, __debezium.source.schema, and mfd.compaction_id.
Transactions. Each WAL commit is begin_transaction … produce … commit_transaction on a producer dedicated to that table. Kafka transactional.id is mfd.{sink}.{table}. Concurrent compact sessions for that table share the producer (a second init_transactions on the same id would fence it). Up to eight tables share the child (max_sessions_per_child = 8). A failed send aborts the transaction, so isolation.level=read_committed consumers do not see a partial commit.
Delivery. A crash after commit and before Mfd records the ack can republish the same complete transaction. Use the event id (or the Debezium envelope) to ignore duplicates.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
Errors mention SSL or SASL_SSL | Current builds don't include TLS for Kafka. | Use a PLAINTEXT or SASL_PLAINTEXT listener. |
debezium_avro requires schema_registry_url | Avro needs a registry id for Confluent framing. | Set schema_registry_url. |
Kafka sink requires a WAL compaction_id | The write path skipped grouped context. | Run through mfd sync; do not call the plugin without a compaction id. |
Compact fails with Broken pipe and the broker logs producer epoch bumps for mfd.{sink}.{table} | Two producers called init_transactions on the same transactional.id. | Current Mfd single-flights that open. Restart the sync; do not run a second producer with the same id. |
| Authentication fails | Wrong mechanism or credentials. | Set sasl_mechanism: PLAIN and check the password env var. |
Next steps
- Kafka source: consume the same
formatvalues. - Change data capture: how
opand before-images move through the WAL. - Exactly-once delivery: what a retry can duplicate.
