Tutorial: Deploy a Spring Boot app connected to Apache Kafka on Confluent Cloud with Service Connector in Azure Spring Apps
Learn how to access Apache Kafka on Confluent Cloud for a Spring Boot application running on Azure Spring Apps. In this tutorial, you complete the following tasks:
- Create Apache Kafka on Confluent Cloud
- Create a Spring Cloud application
- Build and deploy the Spring Boot app
- Connect Apache Kafka on Confluent Cloud to Azure Spring Apps using Service Connector
Set up your initial environment
- Have an Azure account with an active subscription. Create an account for free.
- Install Java 8 or 11.
- Install the Azure CLI 2.18.0 or higher, with which you run commands in any shell to provision and configure Azure resources.
Clone or download the sample app
Clone the sample repository:
git clone https://github.com/Azure-Samples/serviceconnector-springcloud-confluent-springboot/
Navigate into that folder:
cd serviceconnector-springcloud-confluent-springboot
Prepare cloud services
Create an instance of Apache Kafka for Confluent Cloud
Create an instance of Apache Kafka for Confluent Cloud by following this guidance.
Create Kafka cluster and schema registry on Confluent Cloud
Sign in to Confluent Cloud using the SSO provided by Azure
Use the default environment or create a new one
Create a Kafka cluster with the following information
- Cluster type: Standard
- Region/zones: eastus(Virginia), Single Zone
- Cluster name:
cluster_1
or any other name.
In Cluster overview -> Cluster settings, get the Kafka bootstrap server url and take note it down.
Create API keys for the cluster in Data integration -> API Keys -> + Add Key with Global access. Note down the key and secret.
Create a topic named
test
with partitions 6 in Topics -> + Add topicUnder default environment, select the Schema Registry tab. Enable the Schema Registry and note down the API endpoint.
Create API keys for schema registry. Save the key and secret.
Create an Azure Spring Apps instance
Create an instance of Azure Spring Apps by following the Azure Spring Apps quickstart in Java. Make sure your Azure Spring Apps instance is created in the region that has Service Connector support.
Build and deploy the app
Build the sample app and create a new spring app
Sign in to Azure and choose your subscription.
az login az account set --subscription <Name or ID of your subscription>
Build the project using gradle
./gradlew build
Create the app with a public endpoint assigned. If you selected Java version 11 when generating the Spring Cloud project, include the
--runtime-version=Java_11
switch.az spring-cloud app create -n hellospring -s <service-instance-name> -g <your-resource-group-name> --assign-endpoint true
Create service connection using Service Connector
Run the following command to connect your Apache Kafka on Confluent Cloud to your spring cloud app.
az spring-cloud connection create confluent-cloud -g <your-spring-cloud-resource-group> --service <your-spring-cloud-service> --app <your-spring-cloud-app> --deployment <your-spring-cloud-deployment> --bootstrap-server <kafka-bootstrap-server-url> --kafka-key <cluster-api-key> --kafka-secret <cluster-api-secret> --schema-registry <kafka-schema-registry-endpoint> --schema-key <registry-api-key> --schema-secret <registry-api-secret>
Replace the following placeholder texts with your own data:
- Replace
<your-resource-group-name>
with the resource group name that you created for your Apps Spring Apps instance. - Replace
<kafka-bootstrap-server-url>
with your kafka bootstrap server url (the value should be likepkc-xxxx.eastus.azure.confluent.cloud:9092
) - Replace
<cluster-api-key>
and<cluster-api-secret>
with your cluster API key and secret. - Replace
<kafka-schema-registry-endpoint>
with your kafka Schema Registry endpoint (the value should be likehttps://psrc-xxxx.westus2.azure.confluent.cloud
) - Replace
<registry-api-key>
and<registry-api-secret>
with your kafka Schema Registry API key and secret.
Note
If you see the error message "The subscription is not registered to use Microsoft.ServiceLinker", please run az provider register -n Microsoft.ServiceLinker
to register the Service Connector resource provider and run the connection command again.
Deploy the JAR file
Run the following command to upload the JAR file (build/libs/java-springboot-0.0.1-SNAPSHOT.jar
) to your Spring Cloud app.
az spring-cloud app deploy -n hellospring -s <service-instance-name> -g <your-resource-group-name> --artifact-path build/libs/java-springboot-0.0.1-SNAPSHOT.jar
Validate the Kafka data ingestion
Navigate to your Spring Cloud app's endpoint from the Azure portal and select the application URL. You'll see "10 messages were produced to topic test".
Then go to the Confluent portal and the topic's page will show production throughput.
Next steps
Follow the tutorials listed below to learn more about Service Connector.
Feedback
Submit and view feedback for