Scenarios
After completing the configuration of instances, topics, and other resources in the console, you can also download and decompress the Kafka toolkit and perform simple message sending and receiving tests through the Kafka API.
Prerequisites
You have created the required TDMQ for CKafka (CKafka) resources.
You have completed the environment configuration by seeing Preparations. Operation Steps
2. Configure the access control list (ACL) policies locally.
2.1 In the ./config directory of the toolkit, add the following content at the end of producer.properties and consumer.properties files:
security.protocol=SASL_PLAINTEXT
sasl.mechanism=PLAIN
2.2 Create a file named ckafka_client_jaas.conf with the following content:
KafkaClient {
org.apache.kafka.common.security.plain.PlainLoginModule required
username="yourinstance#yourusername"
password="yourpassword";
};
Note:
username is in the format of instance ID + # + configured username, and password is the configured user password.
2.3 In the ./bin directory of the toolkit, add the JAAS file path declaration (using the full path) at the beginning of the kafka-console-producer.sh and kafka-console-consumer.sh files.
export KAFKA_OPTS="-Djava.security.auth.login.config=****/config/ckafka_client_jaas.conf"
3. Produce and consume messages using command-line interface (CLI) commands.
3.1 Open the terminal and start the consumer.
bash kafka-console-consumer.sh --bootstrap-server XXXX:port --topic XXXX --consumer.config ../config/consumer.properties
Note:
broker-list: Replace XXXX:port with the public network access domain name and port. You can obtain it in the Access Mode module on the instance details page in the console.
Topic: Replace XXXX with the topic name. You can obtain it from the Topic List page in the console.
3.2 Open another terminal window and start the producer.
bash kafka-console-producer.sh --broker-list XXXX:port --topic XXXX --producer.config ../config/producer.properties
Note:
broker-list: Replace XXXX:port with the public network access domain name and port. You can obtain it in the Access Mode module on the instance details page in the console.
Topic: Replace XXXX with the topic name. You can obtain it from the Topic List page in the console.
3.3 After you enter the message content and press Enter, the consumer receives the message almost simultaneously.
Produce messages:
Consume messages: