Course: Spring Framework and Apache Kafka®

Hands On: Introduction to Spring Boot for Confluent Cloud

6 min
Viktor GamovDeveloper Advocate (Course Presenter)

Hands On: Introduction to Spring Boot for Confluent Cloud

This exercise sets up a new Spring Boot project with Spring for Apache Kafka and connects it with Confluent Cloud.

Set Up and Download a Project from Spring Initializr

  1. Go to start.spring.io and add a new project, selecting Gradle, Java, and the default version of Spring Boot.
  2. Add your project’s metadata as Group: ”io.confluent.developer,” Artifact: “spring-ccloud,” Description: “Demo project for Spring Boot with Confluent Cloud,” and Package Name: “io.confluent.developer.spring.”

    Select Jar packaging and Java 11.

  3. Click the Add Dependencies button and add Spring for Apache Kafka, Spring for Apache Kafka Streams, Cloud Stream, Lombok, and Spring Reactive Web.

spring-initializr

  1. Click Generate to download a ZIP archive. In your terminal, unzip the file:

    unzip spring-ccloud.zip

    Then open the spring-ccloud directory in your IDE.

Set Up Confluent Cloud

  1. Now, open a browser and navigate to Confluent Cloud (if you don’t have an account, you can sign up for a free trial and use the promo code SPRING101 for an additional $101 of free usage).
  2. In the default environment, go to Add Cluster, then create a standard cluster, and click Begin configuration.

create-cluster

  1. Select Google Cloud, a close region, and single zone availability. Name your cluster and click Launch cluster.

cluster-create

  1. To get your Spring Boot config, go to Clients on the left menu and select Spring Boot. Underneath the config, select Create Kafka cluster API key & secret. Add the description spring kafka lesson, select I have saved my API key and secret and am ready to continue, and click Continue to populate your credentials.

create-an-api-key

Add Confluent Cloud Credentials to Spring

  1. Copy the “#Kafka” section of your config, click Done, and then go back to your IDE with Spring.

    ---
    # Kafka
    spring.kafka.properties.sasl.mechanism=PLAIN
    spring.kafka.properties.bootstrap.servers=pkc-lzvrd.us-west4.gcp.confluent.cloud:9092
    spring.kafka.properties.sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule   required username='{{ CLUSTER_API_KEY }}'   password='{{ CLUSTER_API_SECRET }}';
    spring.kafka.properties.security.protocol=SASL_SSL
  2. Under src/main/resources/application.properties, paste the config.

Use the promo code SPRING101 to get $101 of free Confluent Cloud usage

Be the first to get updates and new content

We will only share developer content and updates, including notifications when new content is added. We will never send you sales emails. 🙂 By subscribing, you understand we will process your personal information in accordance with our Privacy Statement.