Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Apache Kafka Connect MirrorMaker Script

From Leeroopedia


Knowledge Sources
Domains Kafka_Connect, Replication, CLI
Last Updated 2026-02-09 12:00 GMT

Overview

External Tool Doc for launching MirrorMaker 2 (MM2) via the connect-mirror-maker.sh shell script for cross-cluster Kafka replication.

Description

The connect-mirror-maker.sh script is the entry point for running MirrorMaker 2, Kafka's built-in tool for replicating data across Kafka clusters. It is a shell wrapper that configures Log4j2 logging defaults, JVM heap settings, and process naming before delegating to kafka-run-class.sh to launch the org.apache.kafka.connect.mirror.MirrorMaker Java class. MM2 is built on top of the Kafka Connect framework and supports multi-cluster topologies, automatic topic and consumer group offset synchronization, and active-active replication patterns.

Usage

Use this script to start MirrorMaker 2 for geo-replication, disaster recovery, or data migration scenarios where data needs to be replicated between Kafka clusters. The MM2 properties file defines source and target clusters, topic and group filters, and replication policies.

Code Reference

Source Location

Signature

#!/bin/bash
# Usage: connect-mirror-maker.sh [-daemon] mm2.properties

# Environment variables:
#   KAFKA_LOG4J_OPTS   - Log4j2 configuration (default: -Dlog4j2.configurationFile=.../config/connect-log4j2.yaml)
#   KAFKA_HEAP_OPTS    - JVM heap settings (default: -Xms256M -Xmx2G)
#   EXTRA_ARGS         - Additional arguments for kafka-run-class.sh

# Delegates to:
exec kafka-run-class.sh $EXTRA_ARGS org.apache.kafka.connect.mirror.MirrorMaker "$@"

Import

# No import required; invoke directly from the Kafka installation bin/ directory:
bin/connect-mirror-maker.sh mm2.properties

I/O Contract

Inputs

Name Type Required Description
mm2_properties File path Yes Path to the MirrorMaker 2 configuration file defining source/target clusters, topic filters, and replication policies
-daemon Flag No Run MirrorMaker 2 as a background daemon process
KAFKA_LOG4J_OPTS Env var No Custom Log4j2 configuration; defaults to connect-log4j2.yaml
KAFKA_HEAP_OPTS Env var No JVM heap settings; defaults to -Xms256M -Xmx2G

Outputs

Name Type Description
MirrorMaker process JVM process A running MM2 process replicating data between configured Kafka clusters
Log files Files Log output as configured by Log4j2 (connect-log4j2.yaml)

Usage Examples

Start MirrorMaker 2

# Start MirrorMaker 2 with a configuration file
bin/connect-mirror-maker.sh config/mm2.properties

Start as Daemon

# Start MirrorMaker 2 in the background
bin/connect-mirror-maker.sh -daemon config/mm2.properties

Custom Heap Settings

# Override heap for large replication workloads
export KAFKA_HEAP_OPTS="-Xms512M -Xmx4G"
bin/connect-mirror-maker.sh config/mm2.properties

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment