MirrorMaker 2 concept in Kafka - Commands & Configuration
clusters = source, target source.bootstrap.servers = source-kafka:9092 target.bootstrap.servers = target-kafka:9092 # Replication policy replication.policy.class = org.apache.kafka.connect.mirror.DefaultReplicationPolicy # Topics to replicate topics = .* # replicate all topics # Consumer and producer configs consumer.auto.offset.reset = earliest producer.acks = all # Enable heartbeats and offsets sync emit.heartbeats.enabled = true sync.topic.acls.enabled = true # Group ID for MirrorMaker 2 group.id = mirror-maker-group # Internal topics replication internal.topics = __consumer_offsets,__transaction_state # Number of tasks tasks.max = 1
This file configures MirrorMaker 2 to connect two Kafka clusters named 'source' and 'target'.
clusters: lists the cluster aliases.
source.bootstrap.servers and target.bootstrap.servers: specify the Kafka servers for each cluster.
replication.policy.class: defines how topic names are mapped during replication.
topics: regex to select which topics to replicate (here all topics).
consumer.auto.offset.reset and producer.acks: set consumer and producer reliability.
emit.heartbeats.enabled and sync.topic.acls.enabled: enable internal syncing features.
group.id: consumer group for MirrorMaker 2 tasks.
internal.topics: internal Kafka topics to replicate for consistency.
tasks.max: number of parallel tasks to run.
connect-mirror-maker.sh connect-mirror-maker.properties
kafka-topics.sh --bootstrap-server target-kafka:9092 --list--bootstrap-server - Specifies the Kafka server to connect to--list - Lists all topics on the clusterkafka-consumer-groups.sh --bootstrap-server target-kafka:9092 --describe --group mirror-maker-group--bootstrap-server - Specifies the Kafka server to connect to--describe - Shows detailed info about the consumer group--group - Specifies the consumer group to describeIf you remember nothing else from this pattern, remember: MirrorMaker 2 automatically copies Kafka topics between clusters to keep data in sync without manual effort.
Practice
Solution
Step 1: Understand MirrorMaker 2 role
MirrorMaker 2 is designed to replicate data from one Kafka cluster to another to ensure data safety and availability.Step 2: Compare options with MirrorMaker 2 function
Only To copy data between Kafka clusters for backup and availability describes copying data between clusters, which matches MirrorMaker 2's purpose.Final Answer:
To copy data between Kafka clusters for backup and availability -> Option AQuick Check:
MirrorMaker 2 purpose = Data replication [OK]
- Confusing MirrorMaker 2 with monitoring tools
- Thinking it creates topics automatically
- Assuming it compresses messages
Solution
Step 1: Identify source cluster connection
MirrorMaker 2 uses consumer configs to read from the source Kafka cluster.Step 2: Match config key to source cluster
The correct config key for source cluster is consumer.bootstrap.servers, which tells MirrorMaker 2 where to consume data from.Final Answer:
consumer.bootstrap.servers -> Option DQuick Check:
Source cluster = consumer.bootstrap.servers [OK]
- Using producer.bootstrap.servers for source cluster
- Confusing config keys with mirror.bootstrap.servers
- Assuming replica.bootstrap.servers is valid
{
"source.cluster.bootstrap.servers": "source:9092",
"target.cluster.bootstrap.servers": "target:9092",
"topics": "topicA,topicB",
"num.streams": 3
}How many parallel streams will MirrorMaker 2 use to copy data?
Solution
Step 1: Locate num.streams setting
The config sets "num.streams" to 3, which controls how many parallel streams MirrorMaker 2 uses.Step 2: Understand effect of num.streams
More streams mean more parallelism in copying data, so MirrorMaker 2 will use 3 streams here.Final Answer:
3 -> Option AQuick Check:
num.streams = 3 [OK]
- Assuming default 1 stream if not read carefully
- Confusing topics count with streams count
- Ignoring num.streams config
topics = "topic1,topic2" num.streams = 0
What is the problem with this configuration?
Solution
Step 1: Check num.streams value validity
num.streams controls parallel streams and must be at least 1 to work properly.Step 2: Identify error in config
Setting num.streams to 0 disables streams, causing MirrorMaker 2 to fail or not copy data.Final Answer:
num.streams cannot be zero; it must be at least 1 -> Option BQuick Check:
num.streams ≥ 1 required [OK]
- Thinking topics must be single only
- Assuming num.streams can be zero
- Believing num.streams must be even
Solution
Step 1: Understand topic filtering in MirrorMaker 2
MirrorMaker 2 supports filtering topics by regex using the "topics.regex" config.Step 2: Match regex to desired pattern
To match all topics starting with "logs-", the regex "logs-.*" correctly matches any topic beginning with "logs-".Step 3: Compare options
"topics": "logs-*" uses "topics" with wildcard which is not supported; "topics": "logs-" matches exact topic name; "topics.regex": "^logs$" matches only "logs" exactly.Final Answer:
"topics.regex": "logs-.*" -> Option CQuick Check:
Use topics.regex with proper regex for filtering [OK]
- Using wildcard * in topics instead of regex
- Confusing exact match with regex match
- Using incorrect regex that matches wrong topics
Ready to prove it?
Pass the test and this pattern moves unknown
