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
- 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, and module-spring-kafka-examples-3.6.1-h0.cbu.mrs.351.r1.jar is found in the target folder.
- 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.
- 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.
- For a Windows OS, use the CLI to run the following command in the D:\Spring directory:
- 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.

- For a Windows OS, run the curl command to produce data to the broker. as shown in the following figure.
- 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
What is your overall rating for this page?
Thank 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