Create data subscription channels in pull and push modes.
Prerequisites
The IP addresses of your Lindorm client and Message Queue for Apache Kafka client are added to the whitelist of your Lindorm instance. For more information, see Configure a whitelist.
The source Lindorm instance and the destination Message Queue for Apache Kafka instance are connected to Lindorm Tunnel Service (LTS). For more information, see Establish network connections.
A LindormTable data source is created. For more information, see Add a LindormTable data source.
A Kafka data source is created. For more information, see Add a Kafka data source.
The data subscription or change tracking feature is enabled. For more information, see Enable data subscription or Enable change tracking.
Create a pull mode data subscription channel
Procedure
-
Go to the LTS page. In the left-side navigation pane, choose Change Tracking > Pull mode.
This takes you to the Subscription channel list page of Lindorm CDC. The Create data subscription channel button is in the upper-right corner. The list displays the subscription channel ID, Lindorm table name, topic name, and actions (Details and Delete) for existing channels.
-
Click Create data subscription channel and configure the following parameters.
Parameter
Description
Source cluster
Enter the Lindorm instance ID.
Lindorm table name
Select the Lindorm table that you want to subscribe to. Each channel can subscribe to only one table.
Topic name
The name of the data consumption topic.
Data expiration time (days)
The number of days to retain data. The default value is 7.
Number of topic partitions
The number of partitions for the topic. Multiple partitions enable concurrent data consumption. The default value is 4.
-
Click Submit.
-
(Optional) To view the details of a channel, find it in the list and click Details in the Operation column. You can view the channel details, consumption details, and storage details.
-
(Optional) Use the following code example with a Kafka client to consume the subscribed data.
import org.apache.hadoop.hbase.util.Bytes; import org.apache.kafka.clients.admin.AdminClientConfig; import org.apache.kafka.clients.consumer.ConsumerConfig; import org.apache.kafka.clients.consumer.ConsumerRecord; import org.apache.kafka.clients.consumer.ConsumerRecords; import org.apache.kafka.clients.consumer.KafkaConsumer; import org.apache.kafka.common.serialization.ByteArrayDeserializer; import java.time.Duration; import java.util.Arrays; import java.util.Properties; public class TestConsume { public static void main(String[] args) throws Exception { // The topic name that you specified when creating the data subscription channel. String topic = "test-topic"; // Properties for connecting to the endpoint. Properties props = new Properties(); // Specify the endpoint address. props.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, "ld-xxx:9092"); // The key deserializer. Do not change this value. props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, ByteArrayDeserializer.class.getName()); // The value deserializer. Do not change this value. props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, ByteArrayDeserializer.class.getName()); // The name of the consumer group. The group is automatically created during consumption. props.put(ConsumerConfig.GROUP_ID_CONFIG, "group-id-0"); // Create a consumer. KafkaConsumer<byte[], byte[]> consumer = new KafkaConsumer<>(props); // Subscribe to the topic. consumer.subscribe(Arrays.asList(topic)); // Pull data by using the consumer. ConsumerRecords<byte[], byte[]> records = consumer.poll(Duration.ofMillis(10000)); for (ConsumerRecord<byte[], byte[]> record : records) { // View the data content. System.out.println("key: " + Bytes.toString(record.key())); System.out.println("value: " + Bytes.toString(record.value())); } // Commit the current consumer offset. consumer.commitSync(); // Close the consumer. consumer.close(); } }NoteFor more information about the data consumption format, see Data consumption format.
Create a Push channel for data subscription
Process
The following figure shows how the messages of incremental data in a Lindorm table are pushed to Message Queue for Apache Kafka.
Create a Lindorm stream
-
Go to the Lindorm Tunnel Service (LTS) console. In the left-side navigation pane, choose Change Tracking > Push.
-
Click create and configure the parameters.
Parameter
Description
Lindorm Cluster
Select the created LindormTable data source.
Table Name
The name of the table for which you want to capture data changes. The format is
namespace.tablename.For example,
ns1.table1specifies that you want to capture data from thetable1table in thens1namespace.Blacklist table (Optional)
Specify tables whose incremental data should not be pushed. Changes in these tables are ignored.
MessageStorage Type
Select KAFKA.
Storage Datasource
Select the created Kafka data source.
MessageStorage Config
-
kafka_topic: Specify the name of the Kafka topic. -
kafka_ttl: Leave this empty. -
kafka_partition_num: Leave this empty.
ImportantIn push mode, you must create the topic in Kafka in advance.
MessageVersion
The message format. The default is DebeziumV2.
Message Config
-
old_image: Specifies whether the message includes the row values before a change. You must set this parameter totrue. Setting it tofalseis not supported. -
new_image: Specifies whether the message includes the row values after a change. You must set this parameter totrue. Setting it tofalseis not supported. -
with_schema: Specifies whether the message includes the table schema. Set this parameter tofalseto prevent oversized messages. -
ignore_family_prefix: Specifies whether to remove the column family prefix from the exported column names. For example, if the full column name isf:name, setting this parameter totrueresults in the exported column namename.
-
-
Click Submit.