Skip to content

Commit

Permalink
FDP-1736: Upgrade Gradle, Java and Spring Boot (#13)
Browse files Browse the repository at this point in the history
* FDP-1736: Upgrade Gradle, Java and Spring Boot

Signed-off-by: Jasper Kamerling <[email protected]>

* FDP-1736: Take loggers out of companion objects

Signed-off-by: Jasper Kamerling <[email protected]>

---------

Signed-off-by: Jasper Kamerling <[email protected]>
  • Loading branch information
jasperkamerling authored Jan 9, 2024
1 parent ecf47f9 commit 42f2dd8
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 73 deletions.
3 changes: 1 addition & 2 deletions application/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ dependencies {
implementation("org.springframework:spring-aspects")

runtimeOnly("io.micrometer:micrometer-registry-prometheus")
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
}

tasks.withType<org.springframework.boot.gradle.tasks.bundling.BootBuildImage> {
Expand All @@ -40,7 +39,7 @@ testing {
implementation(project())
implementation("org.springframework.boot:spring-boot-starter-test")
implementation("org.springframework.kafka:spring-kafka-test")
implementation("org.testcontainers:kafka:1.19.1")
implementation(integrationTestLibs.kafkaTestContainers)
}
}
}
Expand Down

This file was deleted.

16 changes: 8 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import io.spring.gradle.dependencymanagement.internal.dsl.StandardDependencyMana
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("org.springframework.boot") version "3.1.5" apply false
id("io.spring.dependency-management") version "1.1.3" apply false
kotlin("jvm") version "1.9.10" apply false
kotlin("plugin.spring") version "1.9.10" apply false
kotlin("plugin.jpa") version "1.9.10" apply false
id("com.github.davidmc24.gradle.plugin.avro") version "1.8.0" apply false
id("org.springframework.boot") version "3.2.1" apply false
id("io.spring.dependency-management") version "1.1.4" apply false
kotlin("jvm") version "1.9.22" apply false
kotlin("plugin.spring") version "1.9.22" apply false
kotlin("plugin.jpa") version "1.9.22" apply false
id("com.github.davidmc24.gradle.plugin.avro") version "1.9.1" apply false
id("org.sonarqube") version "4.4.1.3373"
id("eclipse")
}
Expand Down Expand Up @@ -50,7 +50,7 @@ subprojects {

extensions.configure<JavaPluginExtension> {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
languageVersion.set(JavaLanguageVersion.of(21))
}
}

Expand All @@ -63,7 +63,7 @@ subprojects {
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "17"
jvmTarget = "21"
}
}

Expand Down
2 changes: 1 addition & 1 deletion components/avro/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ plugins {
}

dependencies {
api("org.apache.avro:avro:1.11.3")
api(libs.avro)
}
6 changes: 3 additions & 3 deletions components/kafka/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ dependencies {
implementation(project(":components:avro"))

implementation("org.springframework.boot:spring-boot-autoconfigure")
implementation("org.springframework.boot:spring-boot-starter-logging")
implementation(libs.logging)

implementation("org.springframework:spring-aop")

implementation("org.springframework.kafka:spring-kafka")
implementation("com.gxf.utilities:kafka-avro:0.2")
implementation("com.gxf.utilities:kafka-azure-oauth:0.2")
implementation(libs.kafkaAvro)
implementation(libs.kafkaAzureOAuth)

testImplementation("org.springframework:spring-test")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@

package org.gxf.servicetemplate.kafka

import io.github.oshai.kotlinlogging.KotlinLogging
import org.gxf.service.Measurement
import io.micrometer.observation.annotation.Observed
import org.apache.kafka.clients.consumer.ConsumerRecord
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.kafka.annotation.KafkaListener
import org.springframework.kafka.annotation.RetryableTopic
import org.springframework.retry.annotation.Backoff
import org.springframework.stereotype.Service
import java.net.SocketTimeoutException
import java.time.LocalDateTime
Expand All @@ -20,21 +16,13 @@ import java.time.ZoneOffset
@Service
class GxfKafkaConsumer {

companion object {
private val logger: Logger = LoggerFactory.getLogger(this::class.java)
}
private val logger = KotlinLogging.logger { }

@Observed(name = "consumer.consumed")
@KafkaListener(topics = ["avroTopic"], id = "gxf-kafka-consumer")
@RetryableTopic(
backoff = Backoff(value = 3000L),
attempts = "2",
include = [SocketTimeoutException::class]
)
fun consume(record: ConsumerRecord<String, Measurement>) {
logger.info("Consuming: ${record.value().deviceId}")
logger.info { "Consuming: ${record.value().deviceId}" }
if ((LocalDateTime.now().toEpochSecond(ZoneOffset.UTC) % 2) == 0L) {
logger.info("Timeout!: ${record.value().deviceId}")
logger.info { "Timeout!: ${record.value().deviceId}" }
throw SocketTimeoutException()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

package org.gxf.servicetemplate.kafka

import io.github.oshai.kotlinlogging.KotlinLogging
import org.gxf.service.Measurement
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.kafka.core.KafkaTemplate
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Service
Expand All @@ -19,14 +18,12 @@ class GxfKafkaProducer(
private val measurementGenerator: MeasurementGenerator
) {

companion object {
private val logger: Logger = LoggerFactory.getLogger(this::class.java)
}
private val logger = KotlinLogging.logger { }

@Scheduled(cron = "* * * * * *")
fun producer() {
val deviceId = Random.nextLong()
logger.info("Producing: ${deviceId}")
logger.info { "Producing: ${deviceId}" }
kafkaTemplate.send("avroTopic", measurementGenerator.generateMeasurement(deviceId))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import org.gxf.service.Measurement
import org.apache.kafka.common.serialization.StringDeserializer
import org.apache.kafka.common.serialization.StringSerializer
import org.springframework.boot.autoconfigure.kafka.KafkaProperties
import org.springframework.boot.ssl.SslBundles
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory
import org.springframework.kafka.core.*


@Configuration
class KafkaConfiguration(val kafkaProperties: KafkaProperties) {
class KafkaConfiguration(val kafkaProperties: KafkaProperties, private val sslBundles: SslBundles) {

@Bean
fun kafkaListenerContainerFactory(consumerFactory: ConsumerFactory<String, Measurement>): ConcurrentKafkaListenerContainerFactory<String, Measurement> =
Expand All @@ -31,15 +32,15 @@ class KafkaConfiguration(val kafkaProperties: KafkaProperties) {
@Bean
fun consumerFactory(): ConsumerFactory<String, Measurement> =
DefaultKafkaConsumerFactory(
kafkaProperties.buildConsumerProperties(),
kafkaProperties.buildConsumerProperties(sslBundles),
StringDeserializer(),
AvroDeserializer(Measurement.getDecoder())
)

@Bean
fun producerFactory(): ProducerFactory<String, Measurement> =
DefaultKafkaProducerFactory(
kafkaProperties.buildProducerProperties(),
kafkaProperties.buildProducerProperties(sslBundles),
StringSerializer(),
AvroSerializer(Measurement.getEncoder())
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

package org.gxf.servicetemplate.kafka

import org.gxf.servicetemplate.kafka.MeasurementGenerator
import org.junit.jupiter.api.Assertions.*

import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class MeasurementGeneratorTest {
Expand Down
4 changes: 1 addition & 3 deletions components/mqtt/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
// SPDX-License-Identifier: Apache-2.0

dependencies {
implementation("org.springframework.boot:spring-boot-starter-logging")
implementation(libs.logging)

implementation("org.springframework.integration:spring-integration-mqtt")
// Fixes: https://github.com/spring-projects/spring-integration/issues/3051
implementation("org.springframework.integration:spring-integration-jmx")
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

package org.gxf.servicetemplate.mqtt

import org.slf4j.Logger
import org.slf4j.LoggerFactory
import io.github.oshai.kotlinlogging.KotlinLogging
import org.springframework.context.annotation.Bean
import org.springframework.integration.dsl.IntegrationFlow
import org.springframework.integration.dsl.integrationFlow
Expand All @@ -20,19 +19,17 @@ class MqttMessageConsumer(
private val clientFactory: MqttPahoClientFactory
) {

companion object {
val logger: Logger = LoggerFactory.getLogger(this::class.java)
}
private val logger = KotlinLogging.logger { }

// Test with: mosquitto_pub -h localhost -t topic1 -m 23 -u admin -P password
@Bean
fun messageSourceFlow(): IntegrationFlow =
integrationFlow(MqttPahoMessageDrivenChannelAdapter("gxf-listener", clientFactory, "measurement" )) {
integrationFlow(MqttPahoMessageDrivenChannelAdapter("gxf-listener", clientFactory, "measurement")) {
handle { message: Message<*> -> processMqttMessage(message) }
}


private fun processMqttMessage(m: Message<*>) {
logger.info("mqtt: ${m.headers.timestamp} - ${m.payload}")
logger.info { "mqtt: ${m.headers.timestamp} - ${m.payload}" }
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
23 changes: 23 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,26 @@ include("application")
include("components:avro")
include("components:kafka")
include("components:mqtt")

dependencyResolutionManagement {
versionCatalogs {
create("libs") {
library("logging", "io.github.oshai", "kotlin-logging-jvm").version("6.0.1")

version("mapstruct", "1.5.5.Final")
library("mapstruct", "org.mapstruct", "mapstruct").versionRef("mapstruct")
library("mapstructannotation", "org.mapstruct", "mapstruct-processor").versionRef("mapstruct")

library("avro", "org.apache.avro", "avro").version("1.11.3")

version("gxfUtils", "0.2")
library("kafkaAvro", "com.gxf.utilities", "kafka-avro").versionRef("gxfUtils")
library("kafkaAzureOAuth", "com.gxf.utilities", "kafka-azure-oauth").versionRef("gxfUtils")
}
create("integrationTestLibs") {
version("testContainers", "1.19.3")
library("kafkaTestContainers", "org.testcontainers", "kafka").versionRef("testContainers")

}
}
}

0 comments on commit 42f2dd8

Please sign in to comment.