Skip to content

Commit 8ee5fc0

Browse files
authored
Modified the contents
Modified the contents ref - Piyush Gputa
1 parent 25ec6b2 commit 8ee5fc0

File tree

1 file changed

+57
-16
lines changed

1 file changed

+57
-16
lines changed

articles/hdinsight/kafka/apache-kafka-mirror-maker-2.md

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,22 @@ description: Learn how to use Use MirrorMaker 2 to replicate Apache Kafka topics
44
ms.service: hdinsight
55
ms.topic: how-to
66
ms.custom: hdinsightactive
7-
ms.date: 03/10/2023
7+
ms.date: 04/28/2023
88
---
99

10-
# Use MirrorMaker 2 to replicate Apache Kafka topics with Kafka on HDInsight
10+
# Use MirrorMaker 2 to migrate HDInsight Kafka for different HDI (Azure HDInsight) versions
1111

1212
Learn how to use Apache Kafka's mirroring feature to replicate topics to a secondary cluster. You can run mirroring as a continuous process, or intermittently, to migrate data from one cluster to another.
1313

1414
In this article, you use mirroring to replicate topics between two HDInsight clusters. These clusters are in different virtual networks in different datacenters.
1515

16-
> [!WARNING]
17-
> Don't use mirroring as a means to achieve fault-tolerance. The offset to items within a topic are different between the primary and secondary clusters, so clients can't use the two interchangeably. If you are concerned about fault tolerance, you should set replication for the topics within your cluster. For more information, see [Get started with Apache Kafka on HDInsight](apache-kafka-get-started.md).
16+
> [!NOTE]
17+
> We can use mirroring cluster as a fault tolerance.
18+
> This is valid only is primary cluster HDI Kafka 2.4.1, 3.2.0 and secondary cluster is HDI Kafka 3.2.0 versions.
19+
> Secondary cluster would work seamlessly if your primary cluster went down.
20+
> Consumer group offsets will be automatically translated to secondary cluster.
21+
> Just point your primary cluster consumers to secondary cluster with same consumer group and your consumer group will start consuming from the offset where it left in primary cluster.
22+
> The only difference would be that the topic name in backup cluster will change from TOPIC_NAME to primary-cluster-name.TOPIC_NAME.
1823
1924
## How Apache Kafka mirroring works
2025

@@ -73,10 +78,10 @@ This architecture features two clusters in different resource groups and virtual
7378

7479
1. Create two new Kafka clusters:
7580

76-
| Cluster name | Resource group | Virtual network | Storage account |
81+
| Cluster name |HDInsight version| Resource group | Virtual network | Storage account |
7782
|---|---|---|---|
78-
| primary-kafka-cluster | kafka-primary-rg | kafka-primary-vnet | kafkaprimarystorage |
79-
| secondary-kafka-cluster | kafka-secondary-rg | kafka-secondary-vnet | kafkasecondarystorage |
83+
| primary-kafka-cluster | 5.0|kafka-primary-rg | kafka-primary-vnet | kafkaprimarystorage |
84+
| secondary-kafka-cluster |5.1|kafka-secondary-rg | kafka-secondary-vnet | kafkasecondarystorage |
8085

8186
> [!NOTE]
8287
> From now onwards we will use `primary-kafka-cluster` as `PRIMARYCLUSTER` and `secondary-kafka-cluster` as `SECONDARYCLUSTER`.
@@ -172,6 +177,23 @@ This architecture features two clusters in different resource groups and virtual
172177
destination->source.enabled=true
173178
destination->source.topics = .*
174179
```
180+
1. For automated consumer offset sync, we need to enable replication and control the sync duration too. Below property will sync offset every 30 second. For active-active scenario we need to do it both ways
181+
```
182+
groups=.*
183+
184+
emit.checkpoints.enabled = true
185+
source->destination.sync.group.offsets.enabled = true
186+
source->destination.sync.group.offsets.interval.ms=30000
187+
188+
destination->source.sync.group.offsets.enabled = true
189+
destination->source.sync.group.offsets.interval.ms=30000
190+
```
191+
1. If we don’t want to replicate internal topics across clusters, then use following property
192+
193+
```
194+
topics.blacklist="*.internal,__.*"
195+
```
196+
175197
1. Final Configuration file after changes should look like this
176198
```
177199
# specify any number of cluster aliases
@@ -194,6 +216,11 @@ This architecture features two clusters in different resource groups and virtual
194216
secondary-kafka-cluster->primary-kafka-cluster.topics = .*
195217
196218
groups=.*
219+
emit.checkpoints.enabled = true
220+
primary-kafka-cluster->secondary-kafka-cluster.sync.group.offsets.enabled=true
221+
primary-kafka-cluster->secondary-kafka- cluster.sync.group.offsets.interval.ms=30000
222+
secondary-kafka-cluster->primary-kafka-cluster.sync.group.offsets.enabled = true
223+
secondary-kafka-cluster->primary-kafka- cluster.sync.group.offsets.interval.ms=30000
197224
topics.blacklist="*.internal,__.*"
198225
199226
# Setting replication factor of newly created remote topics
@@ -220,19 +247,33 @@ This architecture features two clusters in different resource groups and virtual
220247
export clusterName='primary-kafka-cluster'
221248
export TOPICNAME='TestMirrorMakerTopic'
222249
export KAFKABROKERS='wn0-primar:9092'
223-
export KAFKAZKHOSTS='zk0-primar:2181'
224-
250+
export KAFKAZKHOSTS='zk0-primar:2181'
251+
225252
//Start Producer
253+
For Kafka 2.4
254+
bash /usr/hdp/current/kafka-broker/bin/kafka-console-producer.sh --zookeeper $KAFKAZKHOSTS --topic $TOPICNAME
255+
For Kafka 3.2
226256
bash /usr/hdp/current/kafka-broker/bin/kafka-console-producer.sh --broker-list $KAFKABROKERS --topic $TOPICNAME
227257
```
228-
1. Now start consumer in `SECONDARYCLUSTER`
229-
258+
1. Now start the consumer in PRIMARYCLUSTER with a consumer group
259+
```
260+
//Start Consumer
261+
For Kafka 2.4
262+
bash /usr/hdp/current/kafka-broker/bin/kafka-console-consumer.sh --zookeeper $KAFKAZKHOSTS --topic $TOPICNAME -–group my-group –-from- beginning
263+
264+
For Kafka 3.2
265+
bash /usr/hdp/current/kafka-broker/bin/kafka-console-producer.sh --broker-list $KAFKABROKERS --topic $TOPICNAME -–group my-group –-from-beginning
230266
```
231-
export clusterName='secondary-kafka-cluster'
232-
export TOPICNAME='TestMirrorMakerTopic'
233-
export KAFKABROKERS='wn0-second:9092'
234-
export KAFKAZKHOSTS='zk0-second:2181'
235-
267+
1. Now stop the consumer in PRIMARYCONSUMER and start consumer in SECONDARYCLUSTER with same consumer group
268+
```
269+
export clusterName='secondary-kafka-cluster'
270+
271+
export TOPICNAME='primary-kafka-cluster.TestMirrorMakerTopic'
272+
273+
export KAFKABROKERS='wn0-second:9092'
274+
275+
export KAFKAZKHOSTS='zk0-second:2181'
276+
236277
# List all the topics whether they are replicated or not
237278
bash /usr/hdp/current/kafka-broker/bin/kafka-topics.sh --zookeeper $KAFKAZKHOSTS --list
238279

0 commit comments

Comments
 (0)