Connecting to an Instance Without SASL
This section describes how to connect to a Kafka instance in a private or public network using a CLI, without using SASL certificates.
Private network access and public network access differ only in the connection IP addresses and ports. For private network access, use port 9092. For public network access, use port 9094.
The following describes only the procedure for public network access. For private network access, replace the IP addresses with the actual ones.
Each Kafka broker allows a maximum of 1000 connections from each IP address by default. Excess connections will be rejected. You can change the limit by modifying the Kafka parameters.
Prerequisites
- You have correctly configured security group rules. For details, see Table 1.
- The instance connection address has been obtained.
- For intra-VPC access, use port 9092. Obtain the instance connection address in the Connection section of the Basic Information tab page.
Figure 1 Kafka instance connection addresses for intra-VPC access without SASL
- For public access, use port 9094. Obtain the instance connection address in the Connection section of the Basic Information tab page.
Figure 2 Kafka instance connection addresses for public access without SASL
- For intra-VPC access, use port 9092. Obtain the instance connection address in the Connection section of the Basic Information tab page.
- If automatic topic creation is not enabled for the Kafka instance, obtain the topic name.
You can obtain the name of the topic created in (Optional) Step 3: Create a Topic on the Topics tab page of the instance.
Figure 3 Viewing the topic name
- You have purchased an ECS, installed the JDK, configured the environment variables, and downloaded a Kafka client. For details, see Step 1: Prepare the Environment.
Creating Messages
Go to the /bin directory of the Kafka client file and run the following command to create messages:
./kafka-console-producer.sh --broker-list ${connection address} --topic ${topic name}
Parameter description:
- {connection-address}: the address obtained in Prerequisites
- {topic-name}: the name of the topic created for the Kafka instance
For example, 10.3.196.45:9094, 10.78.42.127:9094, and 10.4.49.103:9094 are the public access addresses of the Kafka instance..
After running the preceding command, you can send a message to the Kafka instance by entering the information as prompted and pressing Enter. Contents in each line are sent as a message.
[root@ecs-kafka bin]# ./kafka-console-producer.sh --broker-list 10.3.196.45:9094,10.78.42.127:9094,10.4.49.103:9094 --topic topic-demo >Hello >DMS >Kafka! >^C[root@ecs-kafka bin]#
To stop creating messages, press Ctrl+C to exit.
Retrieving Messages
Run the following command to retrieve messages:
./kafka-console-consumer.sh --bootstrap-server ${connection-address} --topic ${topic-name} --group ${consumer-group-name} --from-beginning
Parameter description:
- {connection-address}: the address obtained in Prerequisites
- {topic-name}: the name of the topic created for the Kafka instance
- {consumer-group-name}: the consumer group name set based on your service 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 an underscore (_) or a number sign (#), the monitoring data cannot be displayed.
The following is an example:
[root@ecs-kafka bin]# ./kafka-console-consumer.sh --bootstrap-server 10.3.196.45:9094,10.78.42.127:9094,10.4.49.103:9094 --topic topic-demo --group order-test --from-beginning Kafka! DMS Hello ^CProcessed a total of 3 messages [root@ecs-kafka bin]#
To stop retrieving messages, press Ctrl+C to exit.
Follow-Up Procedure
You can configure alarm rules for monitoring metrics to receive notifications in a timely manner when instances, brokers, or topics are abnormal.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot