Configurable Kafka Mirror with Partitioner support
Switch branches/tags
Nothing to show
Latest commit 181ddf8 Mar 20, 2013 Michal Harish Warn debug level for random partitioning notice.
Failed to load latest commit information.
src Warn debug level for random partitioning notice. Mar 20, 2013
.gitignore EDA-39 it stop consuming and sending when there is no broker listening Feb 25, 2013 Update Feb 2, 2013


This Kafka Mirror implementation gives control over output(producer) partitioner which is not supported by the mirroring functionality bundled into the kafka broker 0.7.x. Mirroring single source message onto multiple destination topics is also supported. See extract from the readme file below for more details about the message-to-destination mapping implementation.

It is written in Java and can be run out of the box, provided the resolver.class is found on the classpath, or may be embedded in a Java/Scala program that contains the resolver.class implementation via maven dependency.

See /doc/mirror-blueprint.svg for design overview.

About the MirrorResolver interface

MirrorResolver is the heart of the mirror decisions about where the incoming message should go and with what partition key.

All is done in a single method..

public List resolve(MessageAndMetadata metaMsg) { .. }

..which receives all messages from every configured consumer and is expected to return a list of MirrorDestination objects each of which is a pair of topic-hash while the hash is optional in which case null (and thus random partition) will be used.

The hash is in fact expected to be an integer value rather than any kind of hash so that the built-in partitioner can transparently use a simple hash % num_partitions.

Running the mirror out of the box

git clone git://
mvn package assembly:single    
java -cp src/test/resources/:target/kafka-mirror-0.7.2.jar co.gridport.kafka.Mirror [/etc/kafka/]

This will require [/etc/kafka/] to exist and properties as per example. The src/test/resources/: is added to the classpath to provide access to but may be replaced with custom ones.

Wrapping the Mirror in a java program

Properties properties = MyProgram.class.getResourceAsStream("");
Mirror myMirror = new Mirror(properties);

//EITHER - this will block and log stats every 10 seconds; 

//OR -this will only start mirror executors in the background and myMirror.shutdown();

The following snippet is the content from [src/test/resources/]. It is used in the embedded test [src/test/java/]

resolver.class = TestMirror$ExampleEncoder

producer.zk.connect = localhost:2181 = 10000
producer.producer.type = async
producer.queue.time = 100
producer.queue.size = 50
producer.compression.codec = 1

consumer.1.topics.whitelist = topic1,topic2
consumer.1.zk.connect =
consumer.1.groupid = example-mirror = 10000 = 250
consumer.2.zk.connect =
consumer.2.groupid = example-mirror
consumer.2.topics.whitelist = topic1,topic2 = 3000 = 250
  • The resolver section contains configuration destination resolver used by the single internal producer.
  • Producer section appears only once and contains the producer configuration for the destination cluster
  • There are multiple consumer(s) each for mirroring a particular remote cluster and its topics.


  • src/test/java/TestMirrorPartitioner
  • src/test/java/TestMirrorResolver
  • src/test/java/TestMirrorDestination
  • decide on unit-testing the MirrorExecutor ** brute force would be to launch two instances of kafka within the test ** elegant way would be to split executor into two classes with an interface in between, one for the kafka context and another for testable logic, then mock the context with serving complete messageAndMetadata objects.