Distributed Message Service (Kafka)

Accessing a Kafka Instance Without SASL

2024-05-09 06:42:55

Before You Begin

l  Security group rules have been correctly configured.

l  The instance connection address has been obtained.

Description

For intra-VPC access, use port 8090. The instance connection address is displayed in the cluster information menu of the console.

descript

l  If automatic topic creation is not enabled for the Kafka instance, create a topic before connecting to the instance.

l  Kafka CLI v2.8.2 is available. Ensure that the Kafka instance and the CLI are of the same version.

l  An ECS has been created. For intra-VPC access, ensure that its VPC, subnet, and security group configurations are the same as those of the Kafka instance.

Accessing the Instance Using CLI

The following uses Linux as an example.

1. Decompress the Kafka CLI package.

Access the directory where the CLI package is stored and run the following command to decompress the package: tar -zxf [kafka_tar].

In the preceding command, [kafka_tar] indicates the name of the CLI package.

For example: tar -zxf kafka_2.13-2.8.2.tgz.

2. Access the /bin directory of the Kafka CLI. Note:

In Windows, you need to access the /bin/windows directory.

3. Run the following command to produce messages:


./kafka-console-producer.sh --broker-list ${connection address} --topic ${topic name} 


Description

l  Connection Address: the address obtained in Before You Begin.

l  Topic Name: the name of the topic created for the Kafka instance. If automatic topic creation has been enabled for the Kafka instance, set this parameter to the name of a created topic or a topic that has not been created.

The internal IP address for this Kafka instance here is 10.10.3.214:8090,10.10.3.126:8090. After running the preceding command, you can send a message to the Kafka instance by writing it and pressing Enter. Each line of content will be sent as a message.


[root@ctyun-kafka bin]# ./kafka-console-producer.sh --broker-list 10.10.3.214:8090,10.10.3.126:8090  --topic topic-demo

Hello

DMS

Kafka!

[root@ctyun-kafka bin]# 


To stop producing messages, press Ctrl+C to exit.

4. Run the following command to consume messages:


./kafka-console-consumer.sh --bootstrap-server ${connection address} --topic ${topic name} --group ${consumer group name} --from-beginning


Description

l  Connection Address: the address obtained in Before You Begin.

l  Topic Name: the name of the topic created for the Kafka instance.

l  Consumer Group Name: the consumer group name that is set based on your business requirements. If a consumer group name has been specified in the configuration file, ensure that you use the same name in the command line. Otherwise, consumption may fail. If a consumer group name starts with a special character, such as a number sign (#), the monitoring data cannot be displayed.

Example:

 

[root@ctyun-kafka bin]#  ./kafka-console-consumer.sh --bootstrap-server 10.10.3.214:8090,10.10.3.126:8090 --topic topic-demo --group order-test --from-beginning

Kafka!

DMS

Hello

Processed a total of 3 messages

[root@ctyun-kafka bin]#


To stop consuming messages, press Ctrl+C to exit.


9S0kq8XZ4tLK