Help Center/ MapReduce Service/ Developer Guide (LTS)/ Kafka Development Guide (Security Mode)/ Commissioning Kafka Applications/ Running an Example Program for Spring Boot Accessing Kafka with Spring Kafka
Updated on 2026-06-29 GMT+08:00

Running an Example Program for Spring Boot Accessing Kafka with Spring Kafka

This section applies to MRS 3.6.0 and later versions.

The module-spring-kafka-examples sample code supports JDK 17 and JDK 21.

Procedure

  1. Enable Kafka Plain authentication.

    Log in to FusionInsight Manager, choose Cluster > Services > Kafka and choose Configurations > All Configurations. Search for sasl.enabled.mechanisms, set its value to GSSAPI,PLAIN, and click Save. Click the Dashboard tab of the Kafka service, choose More > Restart Service to apply the configuration changes.

  2. Obtain the module-spring-kafka-examples-3.6.1-h0.cbu.mrs.351.r1.jar package.

    Find the POM file in the springboot/kafka-examples/module-spring-kafka-examples directory of the example code, and use the Maven install tool to compile the Spring Boot example (by running the mvn clean install command) in the same directory as the POM file. The target folder is generated. Open the folder and obtain the module-spring-kafka-examples-3.6.1-h0.cbu.mrs.351.r1.jar file.

  3. Create a directory on Windows or Linux as the running directory.

    • For a Windows OS, create the D:\Spring directory and upload the module-spring-kafka-examples-3.6.1-h0.cbu.mrs.351.r1.jar and application.properties files to the directory.
    • For a Linux OS, create the /opt/spring directory and upload the module-spring-kafka-examples-3.6.1-h0.cbu.mrs.351.r1.jar and application.properties files to the directory.

  4. Start Spring Boot.

    • For a Windows OS, use the CLI to run the following command in the D:\Spring directory:

      java -jar module-spring-kafka-examples-3.6.1-h0.cbu.mrs.351.r1.jar

    • For a Linux OS, run the following command in the /opt/spring directory:

      java -jar module-spring-kafka-examples-3.6.1-h0.cbu.mrs.351.r1.jar

      The JDK version supports JDK 17 and JDK 21.

      In the Linux environment, the CLI tool provided by the Java runtime environment (JRE) of JDK 17 in the MRS cluster is stored in ${BIGDATA_HOME}/common/runtime/jdk-17.0.13/bin.

  5. Produce data.

    • For a Windows OS, run the curl command to produce data to the broker. as shown in the following figure.
      Figure 1 Producing data
    • For a Linux OS, run the curl command to access Spring Boot.

      curl http://IP address bound during Spring Boot startup:Port bound during Spring Boot startup/produce

    You can view the production data in the Windows cmd window or the Linux shell window.

  6. Consume data.

    You can define a method to listen to Kafka messages. When a message is sent to a specified topic, the method is automatically executed to consume data from the broker.

    You can view the consumption data in the Windows cmd window or the Linux shell window.

    Figure 2 Consuming data