Welcome to another Spring Boot tutorial. Today let’s have a look on how to get started with Apache Kafka on Spring Boot. This tutorial is fully based on Getting Started with Apache Kafka and Spring Boot, while making it a bit better to follow. Hence all the credits goes to original authors. You need to have a Java 11 environment and Confluent account to follow along.
Head on to https://www.confluent.io and signup for an account or login if you have an existing one. Within the Confluent dashboard click on Add cluster button. In the create cluster wizard choose either basic or standard for cluster type. On the second step choose your preferred cloud service provider to provision the resources. Finally provide a name for the cluster and launch.
From dashboard navigate to Cluster overview -> Cluster settings and make a note of Bootstrap server URL. Then navigate to Data integration -> API Keys and create a new key with scope Global access. These values will be needed later when setting up the Spring Boot application. Finally navigate to Topics from the side pane and add a new topic named purchases with default values.
Now let’s headon to Spring Initializr for setting up a new Spring Boot project. Refer to the below screenshot and create a new project as instructed. Once done download and open it on your favourite IDE.
Navigate to src/main/resources folder and create a file named application.yaml. Make sure to replace the placeholders with actual values for Bootstrap Server URL, Cluster API Key and Cluster API Secret.
Then open the SpringBootWithKafkaApplication.java file and make changes to it referring to the below Gist.
After that create a new Java class called Producer under com.example.kafka package and add the below content into it.
Finally create another class called Consumer under com.example.kafka package and add the below content into it.
Run the below command to run the Spring Boot application as Producer.
./gradlew bootRun — args=’ — producer’
Run the below command to run the Spring Boot application as Consumer.
./gradlew bootRun — args=’ — consumer’
Happy Coding! Below is a DEV Community video I have published. Also, you might be interested to check my Medium story Writing unit tests in Spring Boot with JUnit 5.
- Adding a launch screen to an iOS app - DEV Community
Link to the story: https://medium.com/@mmafrar/adding-a-launch-screen-to-an-ios-app-ac197075b25b Get...
© 2022 Afrar Malakooth