filter-circle-dollarSelecting topics

Choose which topics should/should not be replicated.

circle-exclamation

K2K enables simultaneous replication of multiple topics. This section details the configuration process for replicating more than one topic at a time. We'll cover two methods for selecting topics to replicate: using regex and a fixed list.

This tutorial assumes the following files exist (See Setting up for more details):

name: "my-first-replication"
features:
  autoCreateControlTopics: enabled
  autoCreateTopics: enabled
source:
  kafka:
    common:
      "bootstrap.servers": "kafka-source:9092"
    consumer:
      "group.id": "k2k.my-first-k2k"
target:
  kafka:
    common:
      "bootstrap.servers": "kafka-target:9092"
replication:
  - source:
      topic: ".*"
  - sink:
      topic: source
      partition: source

To ensure a clean start, execute this command to reset any prior configurations from earlier tutorials.

1

Start Kafka Clusters

2

Creating topics in the Source cluster

Run the following commands to create these topics: user-topic, transaction-topic, transfers-eu and transfers-us:

3

Select Replicated Topics Using Regex

To select multiple topics using a regex pattern, specify it for the property replication[0].source.topic as shown:

During replication, any topics that match the regular expression and are created after replication starts will be selected and replicated to the target.

circle-info

K2K uses a Kafka Consumer to read data from the source instance.

By default, the Consumer refreshes its metadata only after the interval specified by source.kafka.consumer.metadata.max.age.ms. To reduce this waiting time, set this property to a lower value.

4

Run K2K

Use the following command to run the K2K replicator app:

5

Validate the results

To verify that the expected topics were created in a running instance of K2K, use the following command:

Expected topics:

  • __k2k_consumer-offsets

  • transaction-topic

  • user-topic

6

Source topics as a list

When a regular expression isn't needed, you can use a fixed list of topics for replication. K2K provides the following configuration option for this purpose:

7

Restart the replicator

8

Validate the results

Confirm the successful creation of both topics in the target cluster.

Was this helpful?