From 88556566168d3c93cced15f2eff063c48be715bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Vi=C3=B1as=20Alcon?= Date: Fri, 1 Dec 2023 11:25:21 +0100 Subject: [PATCH] Spring Boot 3.x (#27) --- .github/workflows/gradle.yml | 2 +- README.md | 10 +++++----- build.gradle.kts | 12 ++++++------ .../stream/functional/MyStreamEventProducer.kt | 2 +- .../com/rogervinas/stream/shared/MyContainers.kt | 4 ++-- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index f3a3d7c..6854a96 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -16,7 +16,7 @@ jobs: - name: Set up Java uses: actions/setup-java@v3 with: - java-version: '17' + java-version: '21' distribution: 'temurin' - name: Gradle cache uses: actions/cache@v3 diff --git a/README.md b/README.md index f465afa..7e90f3b 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ ![CI](https://github.com/rogervinas/spring-cloud-stream-kafka-step-by-step/actions/workflows/gradle.yml/badge.svg) -![Java](https://img.shields.io/badge/Java-17-blue?labelColor=black) +![Java](https://img.shields.io/badge/Java-21-blue?labelColor=black) ![Kotlin](https://img.shields.io/badge/Kotlin-1.9.21-blue?labelColor=black) -![SpringBoot](https://img.shields.io/badge/SpringBoot-2.7.8-blue?labelColor=black) -![SpringCloud](https://img.shields.io/badge/SpringCloud-2021.0.8-blue?labelColor=black) +![SpringBoot](https://img.shields.io/badge/SpringBoot-3.2.0-blue?labelColor=black) +![SpringCloud](https://img.shields.io/badge/SpringCloud-2023.0.0_RC1-blue?labelColor=black) # Spring Cloud Stream & Kafka binder step by step @@ -244,14 +244,14 @@ When a message is sent to a topic, Kafka chooses randomly the destination partit This is important on the consumer side, because **chronological order of messages is only guaranteed within the same partition**, so if we need to consume some messages in the order they were produced, we should use the same key for all of them (i.e. for messages of a *user*, we use the *user* id as the message key). -To specify the message key in `MyStreamEventProducer` we can produce `Message` instead of `MyEventPayload` and inform the `KafkaHeaders.MESSAGE_KEY` header: +To specify the message key in `MyStreamEventProducer` we can produce `Message` instead of `MyEventPayload` and inform the `KafkaHeaders.KEY` header: ```kotlin class MyStreamEventProducer : () -> Flux>, MyEventProducer { // ... override fun produce(event: MyEvent) { val message = MessageBuilder .withPayload(MyEventPayload(event.text, event.text.length)) - .setHeader(KafkaHeaders.MESSAGE_KEY, "key-${event.text.length}") + .setHeader(KafkaHeaders.KEY, "key-${event.text.length}") .build() sink.emitNext(message, FAIL_FAST) } diff --git a/build.gradle.kts b/build.gradle.kts index e1a0bb1..e62334c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,23 +3,23 @@ import org.gradle.api.tasks.testing.logging.TestLogEvent.* import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { - id("org.springframework.boot") version "2.7.8" - id("io.spring.dependency-management") version "1.0.15.RELEASE" + id("org.springframework.boot") version "3.2.0" + id("io.spring.dependency-management") version "1.1.4" kotlin("jvm") version "1.9.21" kotlin("plugin.spring") version "1.9.21" } group = "com.rogervinas" version = "0.0.1-SNAPSHOT" -java.sourceCompatibility = JavaVersion.VERSION_17 -java.targetCompatibility = JavaVersion.VERSION_17 +java.sourceCompatibility = JavaVersion.VERSION_21 +java.targetCompatibility = JavaVersion.VERSION_21 repositories { mavenCentral() maven { url = uri("https://repo.spring.io/milestone") } } -val springCloudVersion = "2021.0.8" +val springCloudVersion = "2023.0.0-RC1" dependencies { implementation("org.springframework.boot:spring-boot-starter-web") @@ -45,7 +45,7 @@ dependencyManagement { tasks.withType { kotlinOptions { freeCompilerArgs = listOf("-Xjsr305=strict") - jvmTarget = "17" + jvmTarget = "21" } } diff --git a/src/main/kotlin/com/rogervinas/stream/functional/MyStreamEventProducer.kt b/src/main/kotlin/com/rogervinas/stream/functional/MyStreamEventProducer.kt index 0f98a18..12d69d0 100644 --- a/src/main/kotlin/com/rogervinas/stream/functional/MyStreamEventProducer.kt +++ b/src/main/kotlin/com/rogervinas/stream/functional/MyStreamEventProducer.kt @@ -17,7 +17,7 @@ class MyStreamEventProducer : () -> Flux>, MyEventProduc override fun produce(event: MyEvent) { val message = MessageBuilder .withPayload(toPayload(event)) - .setHeader(KafkaHeaders.MESSAGE_KEY, toKey(event)) + .setHeader(KafkaHeaders.KEY, toKey(event)) .build() sink.emitNext(message, FAIL_FAST) } diff --git a/src/main/kotlin/com/rogervinas/stream/shared/MyContainers.kt b/src/main/kotlin/com/rogervinas/stream/shared/MyContainers.kt index 0a9bfde..8f270b6 100644 --- a/src/main/kotlin/com/rogervinas/stream/shared/MyContainers.kt +++ b/src/main/kotlin/com/rogervinas/stream/shared/MyContainers.kt @@ -1,7 +1,7 @@ package com.rogervinas.stream.shared -import javax.annotation.PostConstruct -import javax.annotation.PreDestroy +import jakarta.annotation.PostConstruct +import jakarta.annotation.PreDestroy import org.springframework.context.annotation.Profile import org.springframework.stereotype.Component import org.testcontainers.containers.ComposeContainer