If an exception occurs when an instance is running, you can perform a health check on the instance. This topic describes how to perform a health check.

Prerequisites

Test network connectivity

  1. Obtain an endpoint.
    1. Log on to the Message Queue for Apache Kafka console.
    2. In the Resource Distribution section of the Overview page, select the region where your instance is deployed.
    3. On the Instances page, click the name of the instance that you want to manage.
    4. On the Instance Details page, obtain an endpoint of the instance in the Endpoint Information section.
      endpoint
      Note For more information about the differences among endpoints, see Comparison among endpoints.
  2. In the directory where the self-check tool is located, run the system terminal executor and run the java -jar KafkaChecker.jar telnet -s endpoint command to check whether you can connect to Message Queue for Apache Kafka.
    For example, if you are connecting to Message Queue for Apache Kafka by using the default endpoint over a VPC, run the java -jar KafkaChecker.jar telnet -s alikafka-pre-cn-zv**********-1-vpc.alikafka.aliyuncs.com:9092,alikafka-pre-cn-zv**********-2-vpc.alikafka.aliyuncs.com:9092,alikafka-pre-cn-zv**********-3-vpc.alikafka.aliyuncs.com:9092 command.
    If information similar to the output shown in the following figure is returned, the network connection is normal. VPC
    If information similar to the output shown in the following figure is returned, the IP addresses have not been added to the whitelist of the endpoint of the Message Queue for Apache Kafka instance. For more information, see Configure a whitelist. WhiteList

Test message sending

Note If a message is sent, real test data is generated. Therefore, you must create a topic specifically for the test to avoid affecting your business.
Run a command according to the network access mode to send messages.
  • If you are connected over a VPC to the default endpoint by using port 9092, run the java -jar KafkaChecker.jar send -s domain name of the endpoint:9092 --topic topic name command.

    Example: java -jar KafkaChecker.jar send -s alikafka-pre-cn-zv**********-1-vpc.alikafka.aliyuncs.com:9092 --topic test

  • If you are connected over the Internet to the SSL endpoint by using port 9093, SASL allows you to use the PLAIN or SCRAM-SHA-256 mechanism for identity authentication. You must run a command according to the identity authentication mechanism to send messages.
    Note On the Internet, the default SASL user of a Message Queue for Apache Kafka instance uses the PLAIN mechanism for identity authentication. When you create an SASL user to implement fine-grained permission control, you can set the identity authentication mechanism to PLAIN or SCRAM-SHA-256. For more information, see Grant permissions to SASL users. You must run the command that corresponds to the identity authentication mechanism to send messages.
    • For the PLAIN mechanism, run the java -jar KafkaChecker.jar send -sm PLAIN -ss true -u username-psw password -s domain name of the endpoint:9093 --topic topic name command.

      Example: java -jar KafkaChecker.jar send -sm PLAIN -ss true -u test -psw test**** -s alikafka-pre-cn-zv**********-1.alikafka.aliyuncs.com:9093 --topic test

    • For the SCRAM-SHA-256 mechanism, run the java -jar KafkaChecker.jar send -sm SCRAM-SHA-256 -ss true -u username -psw password -s domain name of the endpoint:9093 --topic topic name command.

      Example: java -jar KafkaChecker.jar send -sm SCRAM-SHA-256 -ss true -u test -psw test**** -s alikafka-pre-cn-zv**********-1.alikafka.aliyuncs.com:9093 --topic test

  • If you are connected over a VPC to the SASL endpoint by using port 9094, SASL allows you to use the PLAIN or SCRAM-SHA-256 mechanism for identity authentication. You must run a command according to the identity authentication mechanism to send messages.
    • For the PLAIN mechanism, run the java -jar KafkaChecker.jar send -sm PLAIN -sp true -u username -psw password -s domain name of the endpoint:9094 --topic topic name command.

      Example: java -jar KafkaChecker.jar send -sm PLAIN -sp true -u test -psw test**** -s alikafka-pre-cn-zv**********-1-vpc.alikafka.aliyuncs.com:9094 --topic test

    • For the SCRAM-SHA-256 mechanism, run the java -jar KafkaChecker.jar send -sm SCRAM-SHA-256 -ss true -u username -psw password -s IP address of the endpoint:9094 --topic topic name command.

      Example: java -jar KafkaChecker.jar send -sm SCRAM-SHA-256 -sp true -u test -psw test**** -s alikafka-pre-cn-zv**********-1-vpc.alikafka.aliyuncs.com:9094 --topic test

If information similar to the output shown in the following figure is returned, the messages are sent. result

Test message consumption

Run a command according to the network access mode to consume messages.
  • If you are connected over a VPC to the default endpoint by using port 9092, run the java -jar KafkaChecker.jar pull -s domain name of the endpoint:9092 --topic topic name --group group name --partition 0 --offset 0 --count 10 command.

    Example: java -jar KafkaChecker.jar pull -s alikafka-pre-cn-zv**********-1-vpc.alikafka.aliyuncs.com:9092 --topic test --group test --partition 0 --offset 0 --count 10

  • If you are connected over the Internet to the SSL endpoint by using port 9093, SASL allows you to use the PLAIN or SCRAM-SHA-256 mechanism for identity authentication. You must run a command according to the identity authentication mechanism to consume messages.
    Note On the Internet, the default SASL user of a Message Queue for Apache Kafka instance uses the PLAIN mechanism for identity authentication. When you create an SASL user to implement fine-grained permission control, you can set the identity authentication mechanism to PLAIN or SCRAM-SHA-256. For more information, see Grant permissions to SASL users. You must run the command that corresponds to the identity authentication mechanism to consume messages.
    • For the PLAIN mechanism, run the java -jar KafkaChecker.jar pull -sm PLAIN -ss true -u username -psw password -s domain name of the endpoint:9093 --topic topic name --group group name --partition 0 --offset 0 --count 10 command.

      Example: java -jar KafkaChecker.jar pull -s alikafka-pre-cn-zv**********-1-vpc.alikafka.aliyuncs.com:9093 --topic test --group test --partition 0 --offset 0 --count 10

    • For the SCRAM-SHA-256 mechanism, run the java -jar KafkaChecker.jar pull -sm SCRAM-SHA-256 -ss true -u username -psw password -s domain name of the endpoint:9093 --topic topic name --group group name --partition 0 --offset 0 --count 10 command.

      Example: java -jar KafkaChecker.jar pull -sm SCRAM-SHA-256 -ss true -u test -psw test**** -s alikafka-pre-cn-zv**********-1.alikafka.aliyuncs.com:9093 --topic test --group test --partition 0 --offset 0 --count 10

  • If you are connected over a VPC to the SASL endpoint by using port 9094, SASL allows you to use the PLAIN or SCRAM-SHA-256 mechanism for identity authentication. You must run a command according to the identity authentication mechanism to consume messages.
    • For the PLAIN mechanism, run the java -jar KafkaChecker.jar pull -sm PLAIN -ss true -u username -psw password -s domain name of the endpoint:9094 --topic topic name --group group name --partition 0 --offset 0 --count 10 command.

      Example: java -jar KafkaChecker.jar pull -sm PLAIN -sp true -u test -psw test**** -s alikafka-pre-cn-zv**********-1-vpc.alikafka.aliyuncs.com:9094 --topic test --group test --partition 0 --offset 0 --count 10

    • For the SCRAM-SHA-256 mechanism, run the java -jar KafkaChecker.jar pull -sm SCRAM-SHA-256 -ss true -u username -psw password -s domain name of the endpoint:9094 --topic topic name --group group name --partition 0 --offset 0 --count 10 command.

      Example: java -jar KafkaChecker.jar pull -sm SCRAM-SHA-256 -sp true -u test -psw test**** -s alikafka-pre-cn-zv**********-1-vpc.alikafka.aliyuncs.com:9094 --topic test --group test --partition 0 --offset 0 --count 10

If information similar to the output shown in the following figure is returned, the messages are consumed. consumer

Verify the demo

If the preceding tests are successful, use the demo to send and consume messages to troubleshoot any issue in your client code. Download the code package of your development language as required. For more information, see Overview.