-
Notifications
You must be signed in to change notification settings - Fork 6
Add reactive application with database and Kafka #290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
591214c
add tests
marijarin 15a751c
add autowired filter
marijarin 8b178fc
fix tests and flows
1144530
fix mono code
d345b63
lower branch coverage for reactive app to 0.5
bf5d896
merge from master
2b8facf
fix after merge master
0df0dc4
delete some log details
8f8e4ed
Merge branch 'master' into issue-146
mfvanek 6061fc4
done with Mono.fromCallable()
80ce50e
Merge branch 'master' into issue-146
mfvanek bacffa9
3 versions to change headers but not working as expected
6bca264
Merge branch 'issue-146' of https://github.com/mfvanek/spring-boot-op…
438291e
Fix reactive chain
mfvanek cdf8491
Fix tests
mfvanek 922c0ca
Add BlockHound
mfvanek 2991434
Polish
mfvanek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,3 +8,5 @@ build/ | |
| *.iml | ||
| *.ipr | ||
| out/ | ||
|
|
||
| .kotlin | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| plugins { | ||
| id("sb-ot-demo.java-conventions") | ||
| id("sb-ot-demo.forbidden-apis") | ||
| id("sb-ot-demo.docker") | ||
| alias(libs.plugins.spring.boot.v3) | ||
| id("io.freefair.lombok") | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation(platform(project(":common-internal-bom"))) | ||
| implementation(platform(libs.springdoc.openapi)) | ||
| implementation(platform(libs.spring.boot.v3.dependencies)) | ||
| implementation(platform(libs.spring.cloud)) | ||
|
|
||
| implementation("org.springframework.boot:spring-boot-starter-webflux") | ||
| implementation("org.springframework.boot:spring-boot-starter-actuator") | ||
| implementation("org.springframework.boot:spring-boot-starter-security") | ||
| implementation("io.micrometer:micrometer-registry-prometheus") | ||
| implementation("io.projectreactor:reactor-tools") | ||
| implementation("org.springdoc:springdoc-openapi-starter-webflux-ui") | ||
|
|
||
| implementation("org.springframework.kafka:spring-kafka") | ||
|
|
||
| implementation("io.micrometer:micrometer-tracing-bridge-otel") | ||
| implementation("io.opentelemetry:opentelemetry-exporter-otlp") | ||
|
|
||
| implementation("org.springframework.boot:spring-boot-starter-jdbc") | ||
| implementation("org.postgresql:postgresql") | ||
| implementation("com.zaxxer:HikariCP") | ||
| implementation(project(":db-migrations")) | ||
| implementation("org.liquibase:liquibase-core") | ||
| implementation("com.github.blagerweij:liquibase-sessionlock") | ||
| implementation(libs.datasource.micrometer) | ||
| implementation(libs.logstash) | ||
|
|
||
| testImplementation("org.springframework.boot:spring-boot-starter-test") | ||
| testImplementation("org.springframework.boot:spring-boot-starter-webflux") | ||
| testImplementation("org.testcontainers:postgresql") | ||
| testImplementation("org.testcontainers:kafka") | ||
| testImplementation("org.springframework.kafka:spring-kafka-test") | ||
| testImplementation("org.awaitility:awaitility") | ||
| testImplementation("io.github.mfvanek:pg-index-health-test-starter") | ||
| testImplementation("org.springframework.cloud:spring-cloud-starter-contract-stub-runner") | ||
| testImplementation("io.projectreactor:reactor-test") | ||
| testImplementation("io.projectreactor.tools:blockhound:1.0.13.RELEASE") | ||
| } | ||
|
|
||
| tasks { | ||
mfvanek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| withType<Test>().all { | ||
| jvmArgs("-XX:+AllowRedefinitionToAddDeleteMethods") | ||
| } | ||
|
|
||
| jacocoTestCoverageVerification { | ||
| dependsOn(jacocoTestReport) | ||
| violationRules { | ||
| rule { | ||
| limit { | ||
| counter = "BRANCH" | ||
| value = "COVEREDRATIO" | ||
| minimum = "0.50".toBigDecimal() | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| val coverageExcludeList = listOf("**/*Application.class") | ||
| listOf(JacocoCoverageVerification::class, JacocoReport::class).forEach { taskType -> | ||
| tasks.withType(taskType) { | ||
| afterEvaluate { | ||
| classDirectories.setFrom( | ||
| files( | ||
| classDirectories.files.map { file -> | ||
| fileTree(file).apply { | ||
| exclude(coverageExcludeList) | ||
| } | ||
| } | ||
| ) | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| springBoot { | ||
| buildInfo() | ||
| } | ||
21 changes: 21 additions & 0 deletions
21
...-demo-app-reactive/src/main/java/io/github/mfvanek/spring/boot3/reactive/Application.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* | ||
| * Copyright (c) 2020-2025. Ivan Vakhrushev and others. | ||
| * https://github.com/mfvanek/spring-boot-open-telemetry-demo | ||
| * | ||
| * Licensed under the Apache License 2.0 | ||
| */ | ||
|
|
||
| package io.github.mfvanek.spring.boot3.reactive; | ||
|
|
||
| import org.springframework.boot.SpringApplication; | ||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
| import reactor.tools.agent.ReactorDebugAgent; | ||
|
|
||
| @SpringBootApplication | ||
| public class Application { | ||
|
|
||
| public static void main(String[] args) { | ||
| ReactorDebugAgent.init(); | ||
| SpringApplication.run(Application.class, args); | ||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
...pp-reactive/src/main/java/io/github/mfvanek/spring/boot3/reactive/config/ClockConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /* | ||
| * Copyright (c) 2020-2025. Ivan Vakhrushev and others. | ||
| * https://github.com/mfvanek/spring-boot-open-telemetry-demo | ||
| * | ||
| * Licensed under the Apache License 2.0 | ||
| */ | ||
|
|
||
| package io.github.mfvanek.spring.boot3.reactive.config; | ||
|
|
||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| import java.time.Clock; | ||
|
|
||
| @Configuration(proxyBeanMethods = false) | ||
| public class ClockConfig { | ||
|
|
||
| @Bean | ||
| public Clock clock() { | ||
| return Clock.systemUTC(); | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
...ive/src/main/java/io/github/mfvanek/spring/boot3/reactive/config/OpenTelemetryConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /* | ||
| * Copyright (c) 2020-2025. Ivan Vakhrushev and others. | ||
| * https://github.com/mfvanek/spring-boot-open-telemetry-demo | ||
| * | ||
| * Licensed under the Apache License 2.0 | ||
| */ | ||
|
|
||
| package io.github.mfvanek.spring.boot3.reactive.config; | ||
|
|
||
| import io.opentelemetry.sdk.common.export.RetryPolicy; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.boot.actuate.autoconfigure.tracing.otlp.OtlpHttpSpanExporterBuilderCustomizer; | ||
| import org.springframework.boot.actuate.autoconfigure.tracing.otlp.OtlpTracingAutoConfiguration; | ||
| import org.springframework.boot.autoconfigure.AutoConfigureBefore; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| @AutoConfigureBefore(OtlpTracingAutoConfiguration.class) | ||
| @Configuration(proxyBeanMethods = false) | ||
| class OpenTelemetryConfig { | ||
|
|
||
| @Bean | ||
| OtlpHttpSpanExporterBuilderCustomizer otelJaegerHttpSpanExporterBuilderCustomizer( | ||
| @Value("${management.otlp.tracing.retry.max-attempts:2}") int maxAttempts | ||
| ) { | ||
| return builder -> builder.setRetryPolicy( | ||
| RetryPolicy.builder() | ||
| .setMaxAttempts(maxAttempts) | ||
| .build() | ||
| ); | ||
| } | ||
| } |
28 changes: 28 additions & 0 deletions
28
...reactive/src/main/java/io/github/mfvanek/spring/boot3/reactive/config/SecurityConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* | ||
| * Copyright (c) 2020-2025. Ivan Vakhrushev and others. | ||
| * https://github.com/mfvanek/spring-boot-open-telemetry-demo | ||
| * | ||
| * Licensed under the Apache License 2.0 | ||
| */ | ||
|
|
||
| package io.github.mfvanek.spring.boot3.reactive.config; | ||
|
|
||
| import lombok.SneakyThrows; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity; | ||
| import org.springframework.security.config.web.server.ServerHttpSecurity; | ||
| import org.springframework.security.web.server.SecurityWebFilterChain; | ||
|
|
||
| @Configuration(proxyBeanMethods = false) | ||
| @EnableWebFluxSecurity | ||
mfvanek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public class SecurityConfig { | ||
|
|
||
| @Bean | ||
| @SneakyThrows | ||
| public SecurityWebFilterChain securityFilterChain(ServerHttpSecurity http) { | ||
| http | ||
| .authorizeExchange(exchanges -> exchanges.anyExchange().permitAll()); | ||
| return http.build(); | ||
| } | ||
| } | ||
27 changes: 27 additions & 0 deletions
27
...eactive/src/main/java/io/github/mfvanek/spring/boot3/reactive/config/WebClientConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /* | ||
| * Copyright (c) 2020-2025. Ivan Vakhrushev and others. | ||
| * https://github.com/mfvanek/spring-boot-open-telemetry-demo | ||
| * | ||
| * Licensed under the Apache License 2.0 | ||
| */ | ||
|
|
||
| package io.github.mfvanek.spring.boot3.reactive.config; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.web.reactive.function.client.WebClient; | ||
|
|
||
| @Configuration(proxyBeanMethods = false) | ||
| public class WebClientConfig { | ||
|
|
||
| @Value("${app.external-base-url}") | ||
| private String external; | ||
|
|
||
| @Bean | ||
| public WebClient webClient(WebClient.Builder builder) { | ||
| return builder | ||
| .baseUrl(external) | ||
| .build(); | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
...ive/src/main/java/io/github/mfvanek/spring/boot3/reactive/controllers/HomeController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* | ||
| * Copyright (c) 2020-2025. Ivan Vakhrushev and others. | ||
| * https://github.com/mfvanek/spring-boot-open-telemetry-demo | ||
| * | ||
| * Licensed under the Apache License 2.0 | ||
| */ | ||
|
|
||
| package io.github.mfvanek.spring.boot3.reactive.controllers; | ||
|
|
||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
| import reactor.core.publisher.Mono; | ||
|
|
||
| @RestController | ||
| public class HomeController { | ||
|
|
||
| @GetMapping("/") | ||
| public Mono<String> home() { | ||
| return Mono.just("Hello!"); | ||
| } | ||
| } |
31 changes: 31 additions & 0 deletions
31
...src/main/java/io/github/mfvanek/spring/boot3/reactive/controllers/RedirectController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * Copyright (c) 2020-2025. Ivan Vakhrushev and others. | ||
| * https://github.com/mfvanek/spring-boot-open-telemetry-demo | ||
| * | ||
| * Licensed under the Apache License 2.0 | ||
| */ | ||
|
|
||
| package io.github.mfvanek.spring.boot3.reactive.controllers; | ||
|
|
||
| import org.springframework.http.HttpHeaders; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
| import reactor.core.publisher.Mono; | ||
|
|
||
| import java.net.URI; | ||
| import java.net.URISyntaxException; | ||
|
|
||
| @RestController | ||
| public class RedirectController { | ||
|
|
||
| // http://localhost:8080/redirect | ||
| @GetMapping(path = "/redirect") | ||
| public Mono<ResponseEntity<Object>> redirectToGoogle() throws URISyntaxException { | ||
| final URI google = new URI("https://www.google.com"); | ||
| final HttpHeaders httpHeaders = new HttpHeaders(); | ||
| httpHeaders.setLocation(google); | ||
| return Mono.just(new ResponseEntity<>(httpHeaders, HttpStatus.SEE_OTHER)); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.