From 5df3c1c47eb1e27af0ecf2eff58d230d93e31e52 Mon Sep 17 00:00:00 2001 From: Thomas Peetz Date: Thu, 3 Jul 2025 17:42:30 +0200 Subject: [PATCH] integrate Apache Camel into Spring Boot --- kontor-spring/build.gradle | 6 ++++++ kontor-spring/gradle/libs.versions.toml | 2 ++ .../kontor/integration/ReadQueueRoute.java | 14 +++++++++++++ .../src/main/resources/application.yml | 17 ++++++++++++++- .../de/thpeetz/kontor/ApplicationTests.java | 21 ++++++++++++++++++- .../media/services/MediaFileServiceTest.java | 5 ++++- 6 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 kontor-spring/src/main/java/de/thpeetz/kontor/integration/ReadQueueRoute.java diff --git a/kontor-spring/build.gradle b/kontor-spring/build.gradle index 5308d79..bca62b7 100644 --- a/kontor-spring/build.gradle +++ b/kontor-spring/build.gradle @@ -54,9 +54,13 @@ configurations { dependencies { implementation 'com.vaadin:vaadin-core' implementation 'com.vaadin:vaadin-spring-boot-starter' + implementation 'org.springframework.boot:spring-boot-starter-artemis' implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-validation' + implementation 'org.apache.camel.springboot:camel-spring-boot-starter' + implementation 'org.apache.activemq:artemis-jakarta-client' + implementation 'org.apache.camel.springboot:camel-jms-starter' implementation 'org.springframework.boot:spring-boot-starter-actuator' developmentOnly 'org.springframework.boot:spring-boot-devtools' implementation 'io.micrometer:micrometer-registry-prometheus' @@ -78,6 +82,7 @@ dependencies { testImplementation 'org.springframework.security:spring-security-test' testImplementation 'com.vaadin:vaadin-testbench-junit5' testImplementation 'io.projectreactor:reactor-test' + testImplementation 'org.apache.camel:camel-test-spring-junit5' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' @@ -145,6 +150,7 @@ build.dependsOn asciidoctorPdf dependencyManagement { imports { mavenBom libs.vaadin.bom.get().toString() + mavenBom libs.camel.bom.get().toString() } } diff --git a/kontor-spring/gradle/libs.versions.toml b/kontor-spring/gradle/libs.versions.toml index 39ad0b9..c4e75f8 100644 --- a/kontor-spring/gradle/libs.versions.toml +++ b/kontor-spring/gradle/libs.versions.toml @@ -19,6 +19,7 @@ cimtConventions = "1.0.0-SNAPSHOT" springboot = "3.2.5" springdependencies = "1.1.4" vaadin = "24.3.8" +camel = "4.10.6" lombok = "8.6" gson = "2.9.0" jackson = "2.16.1" @@ -43,6 +44,7 @@ mail = { module = "com.sun.mail:javax.mail", version.ref ="mail" } sqlite-jdbc = { module = "org.xerial:sqlite-jdbc", version.ref = "sqlite" } hypersistence = { module = "io.hypersistence:hypersistence-utils-hibernate-63", version.ref = "hypersistence" } vaadin-bom = { module = "com.vaadin:vaadin-bom", version.ref = "vaadin" } +camel-bom = { module = "org.apache.camel.springboot:camel-spring-boot-bom", version.ref = "camel"} asciidoctorGradleJvmGems = { module = "org.asciidoctor:asciidoctor-gradle-jvm-gems", version.ref= "asciidoctor" } asciidoctorGradleJvm = { module = "org.asciidoctor:asciidoctor-gradle-jvm", version.ref= "asciidoctor" } asciidoctorGradleJvmPdf = { module = "org.asciidoctor:asciidoctor-gradle-jvm-pdf", version.ref= "asciidoctor" } diff --git a/kontor-spring/src/main/java/de/thpeetz/kontor/integration/ReadQueueRoute.java b/kontor-spring/src/main/java/de/thpeetz/kontor/integration/ReadQueueRoute.java new file mode 100644 index 0000000..9e06cff --- /dev/null +++ b/kontor-spring/src/main/java/de/thpeetz/kontor/integration/ReadQueueRoute.java @@ -0,0 +1,14 @@ +package de.thpeetz.kontor.integration; + +import org.apache.camel.builder.RouteBuilder; +import org.springframework.stereotype.Component; + +@Component +public class ReadQueueRoute extends RouteBuilder { + + @Override + public void configure() throws Exception { + from("jms:queue:KontorMediaFile") + .log("${body}"); + } +} diff --git a/kontor-spring/src/main/resources/application.yml b/kontor-spring/src/main/resources/application.yml index 63a3f43..cf0dd2d 100644 --- a/kontor-spring/src/main/resources/application.yml +++ b/kontor-spring/src/main/resources/application.yml @@ -24,14 +24,29 @@ spring: multipart: max-file-size: 10MB max-request-size: 10MB + artemis: + mode: native + host: 127.0.0.1 + port: 61616 + user: artemis + password: artemis +camel: + cloud: + enabled: true + springboot: + routes-reload-enabled: true + routes-reload-directory: routes + routes-relaod-pattern: "*.xml" management: endpoints: web: exposure: - include: health,info,metrics,prometheus + include: health,info,metrics,prometheus,camelroutes endpoint: health: show-details: always + probes: + enabled: true prometheus: enabled: true logging: diff --git a/kontor-spring/src/test/java/de/thpeetz/kontor/ApplicationTests.java b/kontor-spring/src/test/java/de/thpeetz/kontor/ApplicationTests.java index abf5c95..7f01251 100644 --- a/kontor-spring/src/test/java/de/thpeetz/kontor/ApplicationTests.java +++ b/kontor-spring/src/test/java/de/thpeetz/kontor/ApplicationTests.java @@ -1,11 +1,30 @@ package de.thpeetz.kontor; +import org.junit.Ignore; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import java.util.concurrent.TimeUnit; -@SpringBootTest +import org.apache.camel.test.spring.junit5.CamelSpringBootTest; +import org.apache.camel.CamelContext; +import org.apache.camel.builder.NotifyBuilder; + +import static org.junit.jupiter.api.Assertions.assertTrue; + + +@CamelSpringBootTest +@SpringBootTest(classes = Application.class) class ApplicationTests { + @Autowired + private CamelContext camelContext; + @Test + @Ignore + public void shouldProduceMessages() throws Exception { + NotifyBuilder notify = new NotifyBuilder(camelContext).whenDone(1).create(); + assertTrue(notify.matches(10, TimeUnit.SECONDS)); + } @Test void contextLoads() { diff --git a/kontor-spring/src/test/java/de/thpeetz/kontor/media/services/MediaFileServiceTest.java b/kontor-spring/src/test/java/de/thpeetz/kontor/media/services/MediaFileServiceTest.java index 2201be5..e08193d 100644 --- a/kontor-spring/src/test/java/de/thpeetz/kontor/media/services/MediaFileServiceTest.java +++ b/kontor-spring/src/test/java/de/thpeetz/kontor/media/services/MediaFileServiceTest.java @@ -1,5 +1,6 @@ package de.thpeetz.kontor.media.services; +import de.thpeetz.kontor.common.views.SearchFilter; import de.thpeetz.kontor.media.TestConstants; import de.thpeetz.kontor.media.data.MediaFile; import org.junit.jupiter.api.MethodOrderer; @@ -40,7 +41,9 @@ public class MediaFileServiceTest { @Order(3) void testDeleteMediaFile() { int mediaFileCount = mediaFileService.findAllMediaFiles(null).size(); - List mediaFileList = mediaFileService.findAllMediaFiles(TestConstants.URL); + SearchFilter searchFilter = new SearchFilter(); + searchFilter.setSearchTerm(TestConstants.URL); + List mediaFileList = mediaFileService.findAllMediaFiles(searchFilter); assertEquals(1, mediaFileList.size()); mediaFileService.deleteMediaFile(mediaFileList.get(0)); assertEquals(--mediaFileCount, mediaFileService.findAllMediaFiles(null).size());