Skip to main content
AutoMQ for Kafka is a cloud-native version of Kafka redesigned for cloud environments. AutoMQ Kafka is open source and fully compatible with the Kafka protocol, fully leveraging cloud benefits. Compared to self-managed Apache Kafka, AutoMQ Kafka, with its cloud-native architecture, offers features like capacity auto scaling, self-balancing of network traffic, move partition in seconds. These features contribute to a significantly lower Total Cost of Ownership (TCO) for users. Use the database’s built-in Routine Load to continuously consume messages from AutoMQ Kafka topics. See Load data with Routine Load for configuration and how it works.

Prepare Environment

Prepare the database and test data

Ensure you have a running cluster. Creating a database and a Primary Key table for testing:


Note If a cluster in a staging environment contains only one BE, the number of replicas can be set to 1 in the PROPERTIES clause, such as PROPERTIES( "replication_num" = "1" ). The default number of replicas is 3, which is also the number recommended for production clusters. If you want to use the default number, you do not need to configure the replication_num parameter.

Prepare AutoMQ Kafka and test data

To prepare your AutoMQ Kafka environment and test data, follow the AutoMQ Quick Start guide to deploy your AutoMQ Kafka cluster. Ensure that the database can directly connect to your AutoMQ Kafka server. To quickly create a topic named example_topic in AutoMQ Kafka and write a test JSON data into it, follow these steps:

Create a topic

Use Kafka’s command-line tools to create a topic. Ensure you have access to the Kafka environment and the Kafka service is running. Here is the command to create a topic:
Note: Replace topic and bootstrap-server with your Kafka server address.
To check the result of the topic creation, use this command:

Generate test data

Generate a simple JSON format test data

Write Test Data

Use Kafka’s command-line tools or programming methods to write test data into example_topic. Here is an example using command-line tools:
Note: Replace topic and bootstrap-server with your Kafka server address.
To view the recently written topic data, use the following command:

Creating a Routine Load Task

In the database command line, create a Routine Load task to continuously import data from the AutoMQ Kafka topic:
Note: Replace kafka_broker_list with your Kafka server address.

Explanation of Parameters

Data Format

Specify the data format as JSON in the “format” = “json” of the PROPERTIES clause.

Data Extraction and Transformation

To specify the mapping and transformation relationship between the source data and the target table, configure the COLUMNS and jsonpaths parameters. The column names in COLUMNS correspond to the column names of the target table, and their order corresponds to the column order in the source data. The jsonpaths parameter is used to extract the required field data from JSON data, similar to newly generated CSV data. Then the COLUMNS parameter temporarily names the fields in jsonpaths in order. For more explanations on data transformation, please see Data Transformation during Import.
Note: If each JSON object per line has key names and quantities (order is not required) that correspond to the columns of the target table, there is no need to configure COLUMNS.

Verifying Data Import

First, we check the Routine Load import job and confirm the Routine Load import task status is in RUNNING status.
Then, querying the corresponding table in the database, we can observe that the data has been successfully imported.