Updated on 2026-06-29 GMT+08:00

Running an Example Program for Integrating Kafka with Spring Boot

This section applies to MRS 3.3.0 and later versions.

The kafka-springboot-examples sample code supports JDK 8, JDK 17.

Procedure

  1. Obtain the huawei-spring-boot-kafka-examples-*.jar package.

    Find the POM file in the springboot/kafka-examples/kafka-springboot-examples directory of the example code, and use the Maven install tool to compile the Spring Boot example in the same directory as the POM file. The target folder is generated, and huawei-spring-boot-kafka-examples-*.jar is found in the target folder.

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

    • For a Windows OS, create the D:\Spring directory and upload the huawei-spring-boot-kafka-examples-*.jar and application.properties files to the directory.
    • For a Linux OS, create the /opt/spring directory and upload the huawei-spring-boot-kafka-examples-*.jar and application.properties files to the directory.

  3. Start Spring Boot.

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

      java -jar huawei-spring-boot-kafka-examples-*.jar

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

      java -jar huawei-spring-boot-kafka-examples-*.jar

  4. Produce data.

    • For a Windows OS, use a browser to access http://IP address bound during Spring Boot startup:Port bound during Spring Boot startup/produce to produce data to 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

  5. Consume data.

    • For a Windows OS, use a browser to access http://IP address bound during Spring Boot startup:Port bound during Spring Boot startup/consume to consume data from broker, as shown in the following figure.
      Figure 2 Consuming 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/consume