|
| 1 | += Spring Into Kafka with Kotlin and Confluent Cloud |
| 2 | +Sandon Jacobs <sjacobs@confluent.io> |
| 3 | +3.0, July 29, 2022: AsciiDoc article template |
| 4 | +:toc: |
| 5 | +:icons: font |
| 6 | +:url-quickref: https://docs.asciidoctor.org/asciidoc/latest/syntax-quick-reference/ |
| 7 | + |
| 8 | +This demo will exercise various ways to integrate Spring Boot applications with Apache Kafka(R), specifically Confluent Cloud. |
| 9 | + |
| 10 | +== The Spring and Kafka Friendship |
| 11 | + |
| 12 | +The Spring for Apache Kafka (spring-kafka) project applies core Spring concepts to the development of Kafka-based solutions. It provides a "template" as a high-level abstraction for sending messages. It also provides support for Message-driven POJOs with `@KafkaListener` annotations and a "listener container". These libraries promote the use of dependency injection and declarative programming. |
| 13 | + |
| 14 | +== Required Tools |
| 15 | + |
| 16 | +.For ths demo, you'll need a few things: |
| 17 | +* JDK 21 (I strongly suggest https://sdkman.io/[sdkman].) |
| 18 | +* https://www.terraform.io/[Terraform] |
| 19 | +* https://confluent.cloud[Confluent Cloud] account |
| 20 | +* https://docs.confluent.io/confluent-cli/current/overview.html[Confluent CLI] |
| 21 | +* https://jqlang.github.io/jq/[jq] |
| 22 | +* IDE of choice. For Kotlin, that is likely https://www.jetbrains.com/idea/[IntelliJ IDEA] (Community Edition will suffice). |
| 23 | + |
| 24 | +== Confluent Cloud |
| 25 | + |
| 26 | +Once you have registered for a Confluent Cloud account, we'll be ready create the infrastructure for this demo. Here we'll use the Confluent Terraform Provider to provision assets in Confluent Cloud. |
| 27 | + |
| 28 | +From your terminal, change into the `terraform` subdirectory and run the following commands: |
| 29 | + |
| 30 | +```shell |
| 31 | +terraform init |
| 32 | +terraform plan -out "tfplan" |
| 33 | +terraform apply "tfplan" |
| 34 | +``` |
| 35 | + |
| 36 | +You can validate your Confluent Cloud assets are provisioned via the Confluent Cloud Console or with Confluent CLI. Should you encounter an issue at of the steps above, please validate your Confluent CLI setup (specifically credentials) and `PATH` variables. |
| 37 | + |
| 38 | +The code in this demo relies on the assets you just provisioned, and the configuration of this Spring Boot application needs the credentials and endpoints we just provisioned. Let's export those to a properties file in the `USER_HOME` directory to later usage: |
| 39 | + |
| 40 | +```shell |
| 41 | +terraform output -json | jq -r 'to_entries[] | .key + "=" + (.value.value | tostring)' | while read -r line ; do echo "$line"; done > . ~/tools/spring-into-cc.properties |
| 42 | + |
| 43 | +cat ~/tools/spring-into-cc.properties |
| 44 | + |
| 45 | +CC_BROKER=<REDACTED>.confluent.cloud:9092 |
| 46 | +CC_BROKER_URL=https://<REDACTED>.confluent.cloud:443 |
| 47 | +CC_ENV_DISPLAY_NAME=spring-into-cc |
| 48 | +CC_ENV_ID=<REDACTED> |
| 49 | +CC_KAFKA_CLUSTER_ID=<REDACTED> |
| 50 | +CC_SCHEMA_REGISTRY_ID=<REDACTED> |
| 51 | +CC_SCHEMA_REGISTRY_URL=https://<REDACTED>.confluent.cloud |
| 52 | +KAFKA_KEY_ID=<REDACTED> |
| 53 | +KAFKA_KEY_SECRET=<REDACTED> |
| 54 | +SCHEMA_REGISTRY_KEY_ID=<REDACTED> |
| 55 | +SCHEMA_REGISTRY_KEY_SECRET=<REDACTED> |
| 56 | +``` |
| 57 | + |
| 58 | +== Run the Demos |
| 59 | + |
| 60 | +.Check out the documentation in each submodule for details on the code samples and how to execute them. |
| 61 | +* xref:./produce-consume/README.adoc[Producing and Consuming Events] |
| 62 | + |
| 63 | +== Confluent Cloud Cleanup |
| 64 | + |
| 65 | +Once you're done, you can destroy the Confluent Cloud environment using Terraform from the `terraform` directory as follows: |
| 66 | + |
| 67 | +```shell |
| 68 | +terraform destroy -auto-approve |
| 69 | +``` |
| 70 | + |
| 71 | +== Useful Resources |
| 72 | + |
| 73 | +.Here's a list resources you may find of use for this demo: |
| 74 | +* https://kotlinlang.org/[Kotlin Language] |
| 75 | +* https://spring.io/projects/spring-kafka[Spring-Kafka project] |
| 76 | +* https://spring.io/projects/spring-boot[Spring Boot] |
| 77 | +* https://gradle.org/[Gradle] |
0 commit comments