Skip to content

Commit f513738

Browse files
authored
Add Groovy Hello World sample implementation
* Add Groovy Hello World sample implementation This commit introduces a new Hello World sample specifically designed for Groovy developers. The sample demonstrates basic Spring Integration concepts using Groovy DSL and provides two runnable applications. Changes include: - Add `helloworld-groovy` project with Groovy DSL configuration - Implement HelloWorldApp and PollerApp examples - Configure Groovy dependencies and spring-integration-groovy module - Add runHelloWorldApp and runPollerApp Gradle tasks for execution - Update developer information in build.gradle POM configuration * Added tests to sample * basic tests fixed * Add SpringJUnitConfig to PollerConfigTest * Update PR per code review comments. * Remove dependencies that are picked up transitively * Update JUnit version * Add SpringJunitConfig to HelloWorldConfigTests
1 parent 527cb55 commit f513738

File tree

12 files changed

+757
-0
lines changed

12 files changed

+757
-0
lines changed

basic/helloworld-groovy/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Hello World Sample
2+
==================
3+
4+
This is the Groovy version of the helloworld Java sample using Groovy DSL. This sample project contains 2 basic sample applications:
5+
6+
* Hello World
7+
* Poller Application
8+
9+
## Hello World
10+
11+
The Hello World application demonstrates a simple message flow represented by the diagram below:
12+
13+
Message -> Channel -> ServiceActivator -> QueueChannel
14+
15+
To run the sample simply execute **HelloWorldApp** in package **org.springframework.integration.samples.helloworld**.
16+
You can also execute that class using the [Gradle](https://www.gradle.org):
17+
18+
$ gradlew :helloworld-groovy:runHelloWorldApp
19+
20+
You should see the following output:
21+
22+
INFO : org.springframework.integration.samples.helloworld.HelloWorldApp - ==> HelloWorldDemo: Hello World
23+
24+
## Poller Application
25+
26+
This simple application will print out the current system time twice every 20 seconds.
27+
28+
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.
29+
30+
To run the sample simply execute **PollerApp** in package **org.springframework.integration.samples.helloworld**.
31+
You can also execute that class using the [Gradle](https://www.gradle.org):
32+
33+
$ gradlew :helloworld-groovy:runPollerApp
34+
35+
You should see output like the following:
36+
37+
[task-scheduler-1][org.springframework.integration.samples.helloworld] GenericMessage [payload=1763478785243, headers={id=8f93b18a-063a-5e9f-4708-2ed1d04a1566, timestamp=1763478785244}]
38+
[task-scheduler-1][org.springframework.integration.samples.helloworld] GenericMessage [payload=1763478785248, headers={id=aa37e9c4-95d1-538c-a6cd-d400bb1474bf, timestamp=1763478785248}]
39+

basic/helloworld-groovy/pom.xml

Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>org.springframework.integration.samples</groupId>
5+
<artifactId>helloworld-groovy</artifactId>
6+
<version>7.0.0</version>
7+
<url>https://github.com/spring-projects/spring-integration-samples</url>
8+
<organization>
9+
<name>Spring IO</name>
10+
<url>https://spring.io/projects/spring-integration</url>
11+
</organization>
12+
<licenses>
13+
<license>
14+
<name>Apache License, Version 2.0</name>
15+
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
16+
<distribution>repo</distribution>
17+
</license>
18+
</licenses>
19+
<developers>
20+
<developer>
21+
<id>artembilan</id>
22+
<name>Artem Bilan</name>
23+
<email>[email protected]</email>
24+
<roles>
25+
<role>project lead</role>
26+
</roles>
27+
</developer>
28+
<developer>
29+
<id>garyrussell</id>
30+
<name>Gary Russell</name>
31+
<email>[email protected]</email>
32+
<roles>
33+
<role>project lead emeritus</role>
34+
</roles>
35+
</developer>
36+
<developer>
37+
<id>markfisher</id>
38+
<name>Mark Fisher</name>
39+
<email>[email protected]</email>
40+
<roles>
41+
<role>project founder and lead emeritus</role>
42+
</roles>
43+
</developer>
44+
<developer>
45+
<id>cppwfs</id>
46+
<name>Glenn Renfro</name>
47+
<email>[email protected]</email>
48+
<roles>
49+
<role>project committer</role>
50+
</roles>
51+
</developer>
52+
</developers>
53+
<scm>
54+
<connection>scm:git:scm:git:git://github.com/spring-projects/spring-integration-samples.git</connection>
55+
<developerConnection>scm:git:scm:git:ssh://[email protected]:spring-projects/spring-integration-samples.git</developerConnection>
56+
<url>https://github.com/spring-projects/spring-integration-samples</url>
57+
</scm>
58+
<issueManagement>
59+
<system>GitHub</system>
60+
<url>https://github.com/spring-projects/spring-integration-samples/issues</url>
61+
</issueManagement>
62+
<dependencies>
63+
<dependency>
64+
<groupId>org.springframework.integration</groupId>
65+
<artifactId>spring-integration-core</artifactId>
66+
<scope>compile</scope>
67+
</dependency>
68+
<dependency>
69+
<groupId>org.springframework.integration</groupId>
70+
<artifactId>spring-integration-groovy</artifactId>
71+
<scope>compile</scope>
72+
</dependency>
73+
<dependency>
74+
<groupId>org.apache.groovy</groupId>
75+
<artifactId>groovy</artifactId>
76+
<version>${groovy.version}</version>
77+
<scope>compile</scope>
78+
</dependency>
79+
<dependency>
80+
<groupId>org.apache.logging.log4j</groupId>
81+
<artifactId>log4j-core</artifactId>
82+
<version>${log4j.version}</version>
83+
<scope>compile</scope>
84+
</dependency>
85+
<dependency>
86+
<groupId>org.apache.logging.log4j</groupId>
87+
<artifactId>log4j-core-test</artifactId>
88+
<version>${log4j.version}</version> <!-- Replace with your Log4j 2 version -->
89+
<scope>test</scope>
90+
</dependency>
91+
<dependency>
92+
<groupId>org.awaitility</groupId>
93+
<artifactId>awaitility</artifactId>
94+
<version>4.3.0</version>
95+
<scope>test</scope>
96+
</dependency>
97+
<dependency>
98+
<groupId>org.assertj</groupId>
99+
<artifactId>assertj-core</artifactId>
100+
<version>3.27.6</version>
101+
<scope>test</scope>
102+
</dependency>
103+
104+
<dependency>
105+
<groupId>org.hamcrest</groupId>
106+
<artifactId>hamcrest-library</artifactId>
107+
<version>2.2</version>
108+
<scope>test</scope>
109+
</dependency>
110+
<dependency>
111+
<groupId>org.mockito</groupId>
112+
<artifactId>mockito-core</artifactId>
113+
<version>5.18.0</version>
114+
<scope>test</scope>
115+
</dependency>
116+
<dependency>
117+
<groupId>org.junit.jupiter</groupId>
118+
<artifactId>junit-jupiter-api</artifactId>
119+
<scope>test</scope>
120+
</dependency>
121+
<dependency>
122+
<groupId>org.springframework.integration</groupId>
123+
<artifactId>spring-integration-test</artifactId>
124+
<scope>test</scope>
125+
</dependency>
126+
<dependency>
127+
<groupId>org.springframework</groupId>
128+
<artifactId>spring-test</artifactId>
129+
<scope>test</scope>
130+
</dependency>
131+
<dependency>
132+
<groupId>org.junit.jupiter</groupId>
133+
<artifactId>junit-jupiter-engine</artifactId>
134+
<scope>runtime</scope>
135+
</dependency>
136+
<dependency>
137+
<groupId>org.junit.platform</groupId>
138+
<artifactId>junit-platform-launcher</artifactId>
139+
<scope>runtime</scope>
140+
</dependency>
141+
</dependencies>
142+
<dependencyManagement>
143+
<dependencies>
144+
<dependency>
145+
<groupId>org.junit</groupId>
146+
<artifactId>junit-bom</artifactId>
147+
<version>6.0.1</version>
148+
<scope>import</scope>
149+
<type>pom</type>
150+
</dependency>
151+
<dependency>
152+
<groupId>tools.jackson</groupId>
153+
<artifactId>jackson-bom</artifactId>
154+
<version>3.0.0-rc5</version>
155+
<scope>import</scope>
156+
<type>pom</type>
157+
</dependency>
158+
<dependency>
159+
<groupId>com.fasterxml.jackson</groupId>
160+
<artifactId>jackson-bom</artifactId>
161+
<version>2.19.1</version>
162+
<scope>import</scope>
163+
<type>pom</type>
164+
</dependency>
165+
<dependency>
166+
<groupId>org.springframework</groupId>
167+
<artifactId>spring-framework-bom</artifactId>
168+
<version>7.0.0-SNAPSHOT</version>
169+
<scope>import</scope>
170+
<type>pom</type>
171+
</dependency>
172+
<dependency>
173+
<groupId>org.springframework.integration</groupId>
174+
<artifactId>spring-integration-bom</artifactId>
175+
<version>7.0.0-SNAPSHOT</version>
176+
<scope>import</scope>
177+
<type>pom</type>
178+
</dependency>
179+
</dependencies>
180+
</dependencyManagement>
181+
<properties>
182+
<java.version>17</java.version>
183+
<groovy.version>4.0.24</groovy.version>
184+
<log4j.version>2.24.3</log4j.version>
185+
</properties>
186+
<build>
187+
<plugins>
188+
<plugin>
189+
<groupId>org.codehaus.gmavenplus</groupId>
190+
<artifactId>gmavenplus-plugin</artifactId>
191+
<version>4.0.1</version>
192+
<executions>
193+
<execution>
194+
<goals>
195+
<goal>addSources</goal>
196+
<goal>addTestSources</goal>
197+
<goal>compile</goal>
198+
<goal>compileTests</goal>
199+
</goals>
200+
</execution>
201+
</executions>
202+
<configuration>
203+
<sources>
204+
<source>
205+
<directory>${project.basedir}/src/main/groovy</directory>
206+
<includes>
207+
<include>**/*.groovy</include>
208+
</includes>
209+
</source>
210+
</sources>
211+
<testSources>
212+
<testSource>
213+
<directory>${project.basedir}/src/test/groovy</directory>
214+
<includes>
215+
<include>**/*.groovy</include>
216+
</includes>
217+
</testSource>
218+
</testSources>
219+
</configuration>
220+
</plugin>
221+
<plugin>
222+
<groupId>org.apache.maven.plugins</groupId>
223+
<artifactId>maven-compiler-plugin</artifactId>
224+
<version>3.13.0</version>
225+
<configuration>
226+
<source>${java.version}</source>
227+
<target>${java.version}</target>
228+
</configuration>
229+
</plugin>
230+
</plugins>
231+
</build>
232+
<repositories>
233+
<repository>
234+
<id>repo.spring.io.milestone</id>
235+
<name>Spring Framework Maven Milestone Repository</name>
236+
<url>https://repo.spring.io/milestone</url>
237+
</repository>
238+
<repository>
239+
<id>repo.spring.io.snapshot</id>
240+
<name>Spring Framework Maven Snapshot Repository</name>
241+
<url>https://repo.spring.io/snapshot</url>
242+
</repository>
243+
</repositories>
244+
</project>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2025-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.integration.samples.helloworld
18+
19+
/**
20+
* Simple POJO to be referenced from a Service Activator.
21+
*
22+
* @author Glenn Renfro
23+
*/
24+
class HelloService {
25+
26+
String sayHello(String name) {
27+
"Hello $name"
28+
}
29+
30+
}
31+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2025-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.integration.samples.helloworld
18+
19+
import org.apache.commons.logging.Log
20+
import org.apache.commons.logging.LogFactory
21+
import org.springframework.context.annotation.AnnotationConfigApplicationContext
22+
import org.springframework.messaging.MessageChannel
23+
import org.springframework.messaging.PollableChannel
24+
import org.springframework.messaging.support.GenericMessage
25+
26+
/**
27+
* Demonstrates a basic Message Endpoint that simply prepends a greeting
28+
* ("Hello ") to an inbound String payload from a Message. This is a very
29+
* low-level example, using Message Channels directly for both input and
30+
* output. Notice that the output channel is a QueueChannel. It is
31+
* therefore a PollableChannel and its consumers must invoke receive() as
32+
* demonstrated below.
33+
* <p>
34+
* View the configuration using Groovy DSL in HelloWorldConfig.groovy.
35+
*
36+
* @author Glenn Renfro
37+
*/
38+
class HelloWorldApp {
39+
40+
private static final Log logger = LogFactory.getLog(HelloWorldApp)
41+
42+
static void main(String[] args) {
43+
def context = new AnnotationConfigApplicationContext(HelloWorldConfig)
44+
def inputChannel = context.getBean('inputChannel', MessageChannel)
45+
def outputChannel = context.getBean('outputChannel', PollableChannel)
46+
inputChannel.send(new GenericMessage<String>('World'))
47+
logger.info("==> HelloWorldDemo: ${outputChannel.receive(0).payload}")
48+
context.close()
49+
}
50+
51+
}
52+

0 commit comments

Comments
 (0)