Kafka MirrorMaker
MirrorMaker 2.0 (MM2) simplifies the mirroring or replication of topics between Kafka clusters using the Kafka Connect framework for easier configuration and scaling. It dynamically detects topic changes and synchronizes source and target topic properties, including offsets and partitions.
Cluster-to-Cluster Mirroring: MM2 replicates topics between Kafka clusters, useful for disaster recovery, data aggregation, and cloud migration.
Active-Active Replication: MM2 supports bidirectional replication, allowing both clusters to produce and consume records while MM2 manages synchronization.
Topic Configuration Synchronization: MM2 replicates topic configurations, ensuring that target cluster topics match the source configurations.
Consumer Group Offset Synchronization: It synchronizes consumer offsets between clusters, allowing consumers to continue from their last read point when switching clusters.
Prerequisites:
- An environment with at least two Kafka clusters.
- Kafka version higher than 2.4.x.
- The source cluster should have data points and topics to test various MM2 replication features.
Required Deployment Configuration
The connect-mirror-maker.sh script, bundled with the Kafka library, implements a distributed MirrorMaker 2 (MM2) cluster, managing the Connect workers internally based on a configuration file. The MirrorMaker driver internally creates and handles pairs of connectors: MirrorSourceConnector, MirrorSinkConnector, MirrorCheckpointConnector, and MirrorHeartbeatConnector.
Adding JMX Configurations
Add JMX configurations in the connect-mirror-maker.sh script before the exec statement:
path_to_kafka/bin/connect-mirror-maker.sh
Example port: 9998
Export KAFKA_JMX_OPTS in connect-mirror-maker.sh file:
export KAFKA_JMX_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9998 -Dcom.sun.management.jmxremote.rmi.port=9998 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
exec $(dirname $0)/kafka-run-class.sh $EXTRA_ARGS org.apache.kafka.connect.mirror.MirrorMaker "$@"
For Kerberos-enabled clusters, the JAAS configuration must be exported to KAFKA_OPTS or specified in the MM2 configuration file:
export KAFKA_OPTS="-Djava.security.auth.login.config=<path-to-jaas.conf>"
Adding mm2.properties File
Place the mm2.properties file under path_to_kafka/config.
Example mm2.properties file:
# Kafka datacenters
clusters=clusterA,clusterB
# Define the bootstrap servers for the two Kafka clusters, comma separated brokers
clusterA.bootstrap.servers=brokerA:9092
clusterB.bootstrap.servers=brokerB:9093
# ClusterA and ClusterB configurations
# Replication factor should not be greater than available brokers
clusterA.config.storage.replication.factor=1
clusterB.config.storage.replication.factor=1
clusterA.offset.storage.replication.factor=1
clusterB.offset.storage.replication.factor=1
clusterA.status.storage.replication.factor=1
clusterB.status.storage.replication.factor=1
clusterA->clusterB.enabled=true
clusterB->clusterA.enabled=true
# MirrorMaker configuration
offset-syncs.topic.replication.factor=3
heartbeats.topic.replication.factor=3
checkpoints.topic.replication.factor=3
topics=.*
groups=.*
tasks.max=2
replication.factor=3
refresh.topics.enabled=true
sync.topic.configs.enabled=true
refresh.topics.interval.seconds=30
topics.blacklist=.*[\-\.]internal,.*\.replica,__consumer_offsets
groups.blacklist=console-consumer-.*,connect-.*,__.*
clusterA->clusterB.emit.heartbeats.enabled=true
clusterA->clusterB.emit.checkpoints.enabled=true
clusterB->clusterA.emit.heartbeats.enabled=true
clusterB->clusterA.emit.checkpoints.enabled=true
Starting MirrorMaker 2
Start MirrorMaker 2 by specifying the mm2.properties file:
./connect-mirror-maker.sh /path_to_config/mm2.properties
Once you have completed the server configuration, you must answer a few questions to view Kafka MM2 on the UI. Follow the prompts to confirm monitoring, provide the Kafka MirrorMaker node details, verify the hostnames, and enter the JMX port. Here’s an example of the questions you will encounter:
Do you want to monitor KafkaMM2 [y/n]: y
Enter the Kafka MirrorMaker nodes (comma separated hosts e.g. mm2kafka1,mm2kafka2): 10.90.5.97
The Kafka MM2 hostnames are: [odpcp02.acceldata.dvl]
Is the above Kafka MM2 hostname information correct? [y/n]: y
Enter the Kafka MirrorMaker JMX Port (Ex: 9998): 9998
Kafka Mirror Maker on Pulse UI
To view the Kafka Mirror Maker dashboard, navigate to the left navigation menu and select Kafka > MirrorMaker. The dashboard will be displayed. Use the global calendar to select a time period (e.g., Today, Last 12 hours, Last 3 Months) or choose a custom time period and click Apply to view the charts with data for that period. Additionally, use the HostName filter to display data for selected host names only.

The following charts are displayed on the Kafka MirrorMaker dashboard:
Name | Description |
---|---|
Source -> Destination | Displays the source and destination clusters involved in the mirroring process. |
Last Rebalance | Shows the time elapsed since the last rebalance of the Kafka clusters. |
Completed Rebalance | Indicates the total number of rebalances completed. |
Throughput/Sec | Measures the throughput in messages per second. |
Topics Synced | Shows the number of topics that have been synchronized between clusters. |
Bytes Transferred | Displays the total amount of data transferred in bytes. |
Replication Latency | Indicates the latency in milliseconds for replication between the source and target clusters. |
Message Count | A line graph showing the message count over time with legends for cluster details. |
Topics Throughput/Sec | A line chart displaying the throughput per second for topics over time. |
Topics Bytes Transferred | A table listing nodes, synced topics, and bytes transferred for each topic. |
Topics Replication Latency | A table showing nodes, synced topics, and the replication latency for each topic. |
Task Error Metrics | A table with columns for connector, task, total record errors, failures, and retries. |
Synced Topics | A table listing nodes and their corresponding topics that have been synchronized. |
Source Task Metrics | A table with columns for connector, task, source active record count, poll total, and write total. |
Connector Task Metrics | A table including connector, task, offset commit success/failure percentages, and other metrics. |
Connect Worker Metrics | A table displaying metrics like total tasks, destroyed tasks, paused tasks, restarting tasks, etc. |