Cross-datacenter replication in Kafka - Commands & Configuration
bootstrap.servers=source-kafka1:9092,source-kafka2:9092 replication.factor=3 group.id=replicator-group key.converter=org.apache.kafka.connect.converters.ByteArrayConverter value.converter=org.apache.kafka.connect.converters.ByteArrayConverter config.storage.topic=replicator-configs offset.storage.topic=replicator-offsets status.storage.topic=replicator-status # Destination cluster bootstrap servers producer.bootstrap.servers=dest-kafka1:9092,dest-kafka2:9092 # Topics to replicate topics=important-topic,logs-topic # Replication policy replication.policy.class=org.apache.kafka.connect.mirror.DefaultReplicationPolicy # Enable replication tasks.max=1
This configuration file sets up Kafka MirrorMaker 2 for cross-datacenter replication.
bootstrap.servers: Connects to the source Kafka cluster.
producer.bootstrap.servers: Connects to the destination Kafka cluster.
topics: Lists the topics to replicate.
replication.policy.class: Defines how topic names are mapped between clusters.
tasks.max: Number of parallel replication tasks.
connect-mirror-maker replicator.properties
kafka-topics --bootstrap-server dest-kafka1:9092 --list--bootstrap-server - Specifies the Kafka cluster to connect to--list - Lists all topics in the clusterkafka-consumer-groups --bootstrap-server dest-kafka1:9092 --describe --group replicator-group--bootstrap-server - Connects to the Kafka cluster--describe - Shows detailed information about the consumer group--group - Specifies the consumer group to describeIf you remember nothing else from this pattern, remember: Kafka MirrorMaker 2 uses a connector configuration to continuously copy topics between clusters, keeping data in sync across data centers.
Practice
What is the main purpose of cross-datacenter replication in Kafka?
Solution
Step 1: Understand the concept of cross-datacenter replication
Cross-datacenter replication means copying data from one Kafka cluster to another in a different location.Step 2: Identify the main goal of this replication
The goal is to keep data safe and available even if one cluster fails.Final Answer:
To copy Kafka topics between clusters for data safety and availability -> Option AQuick Check:
Replication = Data safety and availability [OK]
- Confusing replication with compression
- Thinking replication encrypts data
- Assuming replication deletes data
Which of the following is the correct way to specify the source cluster's bootstrap servers in Kafka MirrorMaker configuration?
consumer.bootstrap.servers = ?Solution
Step 1: Identify the role of consumer.bootstrap.servers
This property tells MirrorMaker where to read data from, so it must point to the source Kafka cluster.Step 2: Choose the correct server address for the source cluster
The source cluster's Kafka broker address is usually in the form host:port, like "source.kafka.cluster:9092".Final Answer:
"source.kafka.cluster:9092" -> Option AQuick Check:
consumer.bootstrap.servers = source cluster address [OK]
- Using target cluster address for consumer.bootstrap.servers
- Using ZooKeeper address instead of Kafka broker
- Confusing consumer and producer properties
Given the following MirrorMaker configuration snippet, what will be the value of producer.bootstrap.servers?
consumer.bootstrap.servers=source1.kafka:9092,source2.kafka:9092
producer.bootstrap.servers=target.kafka:9092Solution
Step 1: Read the configuration lines carefully
The snippet shows two properties: consumer.bootstrap.servers and producer.bootstrap.servers with their values.Step 2: Identify the value assigned to producer.bootstrap.servers
It is explicitly set to "target.kafka:9092" in the second line.Final Answer:
"target.kafka:9092" -> Option BQuick Check:
producer.bootstrap.servers = target cluster address [OK]
- Mixing consumer and producer server addresses
- Assuming producer uses source cluster address
- Ignoring explicit configuration values
Identify the error in this MirrorMaker consumer configuration:
consumer.bootstrap.servers=target.kafka:9092
consumer.group.id=mirror-groupSolution
Step 1: Understand the role of consumer.bootstrap.servers
This property must point to the source Kafka cluster to read data for replication.Step 2: Check the given value
It incorrectly points to "target.kafka:9092", which is the destination cluster, not the source.Final Answer:
consumer.bootstrap.servers should point to the source cluster, not target -> Option CQuick Check:
Consumer connects to source cluster [OK]
- Using target cluster address for consumer.bootstrap.servers
- Confusing ZooKeeper port with Kafka broker port
- Assuming group.id is missing when it is present
You want to replicate only topics starting with logs- from the source cluster to the target cluster using MirrorMaker. Which configuration property should you set to filter these topics?
Solution
Step 1: Identify the property to filter topics in MirrorMaker
MirrorMaker uses consumer.topic.whitelist to specify which topics to consume from the source cluster.Step 2: Match the pattern for topics starting with 'logs-'
The pattern "logs-*" matches all topics starting with "logs-".Final Answer:
consumer.topic.whitelist=logs-* -> Option DQuick Check:
Use consumer.topic.whitelist to filter topics [OK]
- Using producer.topic.filter which does not exist
- Confusing mirror.topic.prefix with filtering
- Using consumer.topic.filter instead of whitelist
Ready to prove it?
Pass the test and this pattern moves unknown
