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
- 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.
- 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.
- 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
- For a Windows OS, open the CLI in the D:\Spring directory and run the following command:
- 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
- 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.
- 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
- 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.
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