-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Add Kotlin Hello World sample for Spring Integration #372
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
artembilan
merged 6 commits into
spring-projects:main
from
cppwfs:SIS-kotlin-helloworld
Nov 21, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
10b478d
Add Kotlin Hello World sample for Spring Integration
cppwfs af71c1e
Add documentation to configurations
cppwfs fc0597a
Configure Kotlin Spring plugin for proper proxy support
cppwfs 65c928f
Use global variable for kotlinVersion
cppwfs f002e8e
Remove extraneoius kafkaVersion from ext
cppwfs 4f97ca7
Add DirtiesContext to PollerConfigTests
cppwfs 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
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,38 @@ | ||
| Hello World Sample | ||
| ================== | ||
|
|
||
| This is the Kotlin version of the helloworld Java sample using Kotlin DSL. This sample project contains 2 basic sample applications: | ||
|
|
||
| * Hello World | ||
| * Poller Application | ||
|
|
||
| ## Hello World | ||
|
|
||
| The Hello World application demonstrates a simple message flow represented by the diagram below: | ||
|
|
||
| Message -> Channel -> ServiceActivator -> QueueChannel | ||
|
|
||
| To run the sample simply execute **HelloWorldApp** in package **org.springframework.integration.samples.helloworld**. | ||
| You can also execute that class using the [Gradle](https://www.gradle.org): | ||
|
|
||
| $ gradlew :helloworld-kotlin:runHelloWorldApp | ||
|
|
||
| You should see the following output: | ||
|
|
||
| INFO : org.springframework.integration.samples.helloworld.HelloWorldApp - ==> HelloWorldDemo: Hello World | ||
|
|
||
| ## Poller Application | ||
|
|
||
| This simple application will print out the current system time twice every 20 seconds. | ||
|
|
||
| More specifically, an **Inbound Channel Adapter** polls for the current system time 2 times every 20 seconds (20000 milliseconds). The resulting message contains as payload the time in milliseconds and the message is sent to a **Logging Channel Adapter**, which will print the time to the command prompt. | ||
|
|
||
| To run the sample simply execute **PollerApp** in package **org.springframework.integration.samples.helloworld**. | ||
| You can also execute that class using the [Gradle](https://www.gradle.org): | ||
|
|
||
| $ gradlew :helloworld-kotlin:runPollerApp | ||
|
|
||
| You should see output like the following: | ||
|
|
||
| [task-scheduler-1][org.springframework.integration.samples.helloworld] GenericMessage [payload=1763478785243, headers={id=8f93b18a-063a-5e9f-4708-2ed1d04a1566, timestamp=1763478785244}] | ||
| [task-scheduler-1][org.springframework.integration.samples.helloworld] GenericMessage [payload=1763478785248, headers={id=aa37e9c4-95d1-538c-a6cd-d400bb1474bf, timestamp=1763478785248}] |
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,241 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <groupId>org.springframework.integration.samples</groupId> | ||
| <artifactId>helloworld-kotlin</artifactId> | ||
| <version>7.0.0</version> | ||
| <url>https://github.com/spring-projects/spring-integration-samples</url> | ||
| <organization> | ||
| <name>Spring IO</name> | ||
| <url>https://spring.io/projects/spring-integration</url> | ||
| </organization> | ||
| <licenses> | ||
| <license> | ||
| <name>Apache License, Version 2.0</name> | ||
| <url>https://www.apache.org/licenses/LICENSE-2.0.txt</url> | ||
| <distribution>repo</distribution> | ||
| </license> | ||
| </licenses> | ||
| <developers> | ||
| <developer> | ||
| <id>artembilan</id> | ||
| <name>Artem Bilan</name> | ||
| <email>artem.bilan@broadcom.com</email> | ||
| <roles> | ||
| <role>project lead</role> | ||
| </roles> | ||
| </developer> | ||
| <developer> | ||
| <id>garyrussell</id> | ||
| <name>Gary Russell</name> | ||
| <email>github@gprussell.net</email> | ||
| <roles> | ||
| <role>project lead emeritus</role> | ||
| </roles> | ||
| </developer> | ||
| <developer> | ||
| <id>markfisher</id> | ||
| <name>Mark Fisher</name> | ||
| <email>mark.ryan.fisher@gmail.com</email> | ||
| <roles> | ||
| <role>project founder and lead emeritus</role> | ||
| </roles> | ||
| </developer> | ||
| <developer> | ||
| <id>cppwfs</id> | ||
| <name>Glenn Renfro</name> | ||
| <email>glenn.renfro@broadcom.com</email> | ||
| <roles> | ||
| <role>project committer</role> | ||
| </roles> | ||
| </developer> | ||
| </developers> | ||
| <scm> | ||
| <connection>scm:git:scm:git:git://github.com/spring-projects/spring-integration-samples.git</connection> | ||
| <developerConnection>scm:git:scm:git:ssh://git@github.com:spring-projects/spring-integration-samples.git</developerConnection> | ||
| <url>https://github.com/spring-projects/spring-integration-samples</url> | ||
| </scm> | ||
| <issueManagement> | ||
| <system>GitHub</system> | ||
| <url>https://github.com/spring-projects/spring-integration-samples/issues</url> | ||
| </issueManagement> | ||
| <dependencyManagement> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.jetbrains.kotlin</groupId> | ||
| <artifactId>kotlin-stdlib</artifactId> | ||
| <version>2.2.21</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.jetbrains.kotlin</groupId> | ||
| <artifactId>kotlin-reflect</artifactId> | ||
| <version>2.2.21</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.junit</groupId> | ||
| <artifactId>junit-bom</artifactId> | ||
| <version>6.0.0</version> | ||
| <scope>import</scope> | ||
| <type>pom</type> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>tools.jackson</groupId> | ||
| <artifactId>jackson-bom</artifactId> | ||
| <version>3.0.0-rc9</version> | ||
| <scope>import</scope> | ||
| <type>pom</type> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.fasterxml.jackson</groupId> | ||
| <artifactId>jackson-bom</artifactId> | ||
| <version>2.20.0</version> | ||
| <scope>import</scope> | ||
| <type>pom</type> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework</groupId> | ||
| <artifactId>spring-framework-bom</artifactId> | ||
| <version>7.0.0-SNAPSHOT</version> | ||
| <scope>import</scope> | ||
| <type>pom</type> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.integration</groupId> | ||
| <artifactId>spring-integration-bom</artifactId> | ||
| <version>7.0.0-SNAPSHOT</version> | ||
| <scope>import</scope> | ||
| <type>pom</type> | ||
| </dependency> | ||
| </dependencies> | ||
| </dependencyManagement> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.apache.logging.log4j</groupId> | ||
| <artifactId>log4j-core</artifactId> | ||
| <version>2.24.3</version> | ||
| <scope>compile</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.integration</groupId> | ||
| <artifactId>spring-integration-core</artifactId> | ||
| <scope>compile</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.jetbrains.kotlin</groupId> | ||
| <artifactId>kotlin-stdlib</artifactId> | ||
| <scope>compile</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.jetbrains.kotlin</groupId> | ||
| <artifactId>kotlin-reflect</artifactId> | ||
| <scope>compile</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.hamcrest</groupId> | ||
| <artifactId>hamcrest-library</artifactId> | ||
| <version>2.2</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.mockito</groupId> | ||
| <artifactId>mockito-core</artifactId> | ||
| <version>5.18.0</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.junit.jupiter</groupId> | ||
| <artifactId>junit-jupiter-api</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.integration</groupId> | ||
| <artifactId>spring-integration-test</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.logging.log4j</groupId> | ||
| <artifactId>log4j-core-test</artifactId> | ||
| <version>2.24.3</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.awaitility</groupId> | ||
| <artifactId>awaitility</artifactId> | ||
| <version>4.2.2</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.assertj</groupId> | ||
| <artifactId>assertj-core</artifactId> | ||
| <version>3.27.6</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.junit.jupiter</groupId> | ||
| <artifactId>junit-jupiter-engine</artifactId> | ||
| <scope>runtime</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.junit.platform</groupId> | ||
| <artifactId>junit-platform-launcher</artifactId> | ||
| <scope>runtime</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| <properties> | ||
| <java.version>17</java.version> | ||
| </properties> | ||
| <repositories> | ||
| <repository> | ||
| <id>repo.spring.io.milestone</id> | ||
| <name>Spring Framework Maven Milestone Repository</name> | ||
| <url>https://repo.spring.io/milestone</url> | ||
| </repository> | ||
| <repository> | ||
| <id>repo.spring.io.snapshot</id> | ||
| <name>Spring Framework Maven Snapshot Repository</name> | ||
| <url>https://repo.spring.io/snapshot</url> | ||
| </repository> | ||
| </repositories> | ||
| <build> | ||
| <sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory> | ||
| <testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.jetbrains.kotlin</groupId> | ||
| <artifactId>kotlin-maven-plugin</artifactId> | ||
| <version>2.2.21</version> | ||
| <configuration> | ||
| <args> | ||
| <arg>-Xjsr305=strict</arg> | ||
| </args> | ||
| <compilerPlugins> | ||
| <plugin>spring</plugin> | ||
| </compilerPlugins> | ||
| </configuration> | ||
| <executions> | ||
| <execution> | ||
| <id>compile</id> | ||
| <phase>compile</phase> | ||
| <goals> | ||
| <goal>compile</goal> | ||
| </goals> | ||
| </execution> | ||
| <execution> | ||
| <id>test-compile</id> | ||
| <phase>test-compile</phase> | ||
| <goals> | ||
| <goal>test-compile</goal> | ||
| </goals> | ||
| </execution> | ||
| </executions> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.jetbrains.kotlin</groupId> | ||
| <artifactId>kotlin-maven-allopen</artifactId> | ||
| <version>2.2.21</version> | ||
| </dependency> | ||
| </dependencies> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </project> | ||
28 changes: 28 additions & 0 deletions
28
...kotlin/src/main/kotlin/org/springframework/integration/samples/helloworld/HelloService.kt
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 2025-present the original author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.springframework.integration.samples.helloworld | ||
|
|
||
| /** | ||
| * Simple POJO to be referenced from a Service Activator. | ||
| * | ||
| * @author Glenn Renfro | ||
| */ | ||
| class HelloService { | ||
|
|
||
| fun sayHello(name: String) = "Hello $name" | ||
|
|
||
| } |
45 changes: 45 additions & 0 deletions
45
...otlin/src/main/kotlin/org/springframework/integration/samples/helloworld/HelloWorldApp.kt
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,45 @@ | ||
| /* | ||
| * Copyright 2025-present the original author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.springframework.integration.samples.helloworld | ||
|
|
||
| import org.apache.commons.logging.LogFactory | ||
| import org.springframework.context.annotation.AnnotationConfigApplicationContext | ||
| import org.springframework.messaging.MessageChannel | ||
| import org.springframework.messaging.PollableChannel | ||
| import org.springframework.messaging.support.GenericMessage | ||
|
|
||
| /** | ||
| * Demonstrates a basic Message Endpoint that simply prepends a greeting | ||
| * ("Hello ") to an inbound String payload from a Message. | ||
| * | ||
| * @author Glenn Renfro | ||
| */ | ||
| object HelloWorldApp { | ||
|
|
||
| private val logger = LogFactory.getLog(HelloWorldApp::class.java) | ||
|
|
||
| @JvmStatic | ||
| fun main(args: Array<String>) { | ||
| val context = AnnotationConfigApplicationContext(HelloWorldConfig::class.java) | ||
| val inputChannel = context.getBean("inputChannel", MessageChannel::class.java) | ||
| val outputChannel = context.getBean("outputChannel", PollableChannel::class.java) | ||
| inputChannel.send(GenericMessage("World")) | ||
| logger.info("==> HelloWorldDemo: ${outputChannel.receive(0)?.payload}") | ||
| context.close() | ||
| } | ||
|
|
||
| } |
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.