Partition assignment
Route Kafka records to specific partition.
Found an issue? Feed it back to us at Github, on Slack, Ask Marios or email.
To execute K2K, you must agree to the EULA and secure a free license.
Accept the EULA by setting license.acceptEula
to true
.
Secure a free license by:
emailing [email protected] to receive a token within seconds
setting
license.token
with the received token
K2K offers two ways to map source cluster topics to destination partitions:
Preserve Source Cluster Partition: Use the same partition as the source topic.
Kafka Producer-Based Routing: Use a producer configured routing strategy. Useful e.g when the target topic's partitions differ from the source to accommodate varying partition structures.
This guide covers these options to optimize your mapping strategy.
Requirements
This tutorial assumes the following files exist (See Setting up for more details):
name: "my-first-replication"
features:
autoCreateControlTopics: enabled
autoCreateTopics: enabled
source:
kafka:
common:
"bootstrap.servers": "kafka-source:9092"
consumer:
"group.id": "k2k.my-first-k2k"
target:
kafka:
common:
"bootstrap.servers": "kafka-target:9092"
replication:
- source:
topic: ".*"
- sink:
topic: source
partition: source
To ensure a clean start, execute this command to reset any prior configurations from earlier tutorials.
docker compose down
Preserving the original topic partition
To retain the original record partition during copying, set the sink partition property to "source".
replication:
- source:
...
- sink:
topic: source
partition: source
Producer defined partition
Another option is to write records using the producer's default partitioning strategy. If chosen, the Kafka Producer determines the target partition based on its configured partition assignment strategy.
Choose this configuration when replicating a topic with a different partition count than the target topic.
target:
kafka:
producer:
"partitioner.class": "org.apache.kafka.clients.producer.RoundRobinPartitione"
replication:
- source:
...
- sink:
topic: source
partition: producer
Last updated
Was this helpful?