Skip to content

Commit af71c1e

Browse files
committed
Add documentation to configurations
Revise integrationFlow to be idiomatic of the Kotlin DSL
1 parent 10b478d commit af71c1e

File tree

2 files changed

+57
-14
lines changed

2 files changed

+57
-14
lines changed

basic/helloworld-kotlin/src/main/kotlin/org/springframework/integration/samples/helloworld/HelloWorldConfig.kt

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import org.springframework.context.annotation.Configuration
2121
import org.springframework.integration.channel.DirectChannel
2222
import org.springframework.integration.channel.QueueChannel
2323
import org.springframework.integration.config.EnableIntegration
24-
import org.springframework.integration.dsl.IntegrationFlow
2524
import org.springframework.integration.dsl.integrationFlow
2625
import org.springframework.messaging.MessageChannel
2726

@@ -30,24 +29,57 @@ import org.springframework.messaging.MessageChannel
3029
*
3130
* @author Glenn Renfro
3231
*/
33-
@Configuration
32+
@Configuration(proxyBeanMethods = false)
3433
@EnableIntegration
3534
open class HelloWorldConfig {
3635

36+
/**
37+
* Creates the input channel for inbound messages.
38+
*
39+
* A [DirectChannel] is used for synchronous, immediate message delivery.
40+
* Messages arriving on this channel are processed on the sender's thread
41+
* without any buffering or queuing.
42+
*
43+
* @return A [DirectChannel] instance for synchronous inbound message delivery
44+
*/
3745
@Bean
3846
open fun inputChannel() = DirectChannel()
3947

48+
/**
49+
* Creates the output channel for outbound messages.
50+
*
51+
* A [QueueChannel] with capacity of 10 messages provides asynchronous,
52+
* buffered message delivery. Results from the integration flow are queued
53+
* and available for downstream consumption.
54+
*
55+
* @return A [QueueChannel] instance with capacity of 10 messages
56+
*/
4057
@Bean
4158
open fun outputChannel() = QueueChannel(10)
4259

60+
/**
61+
* Creates the Hello World business service.
62+
*
63+
* [HelloService] implements the core greeting logic that transforms
64+
* input messages into personalized greeting responses.
65+
*
66+
* @return A [HelloService] instance
67+
*/
4368
@Bean
4469
open fun helloService() = HelloService()
4570

71+
/**
72+
* Defines the main integration flow for message processing.
73+
*
74+
* @param inputChannel The synchronous input channel receiving messages
75+
* @param outputChannel The asynchronous output channel for results
76+
* @param helloService The service implementing the greeting logic
77+
* @return An IntegrationFlow representing the complete message flow
78+
*/
4679
@Bean
47-
open fun helloWorldFlow(inputChannel: MessageChannel,
48-
outputChannel: MessageChannel) = integrationFlow(inputChannel) {
49-
handle(helloService(), "sayHello")
80+
open fun helloWorldFlow(inputChannel: MessageChannel, outputChannel: MessageChannel, helloService: HelloService) =
81+
integrationFlow(inputChannel) {
82+
handle(helloService, "sayHello")
5083
channel(outputChannel)
5184
}
52-
5385
}

basic/helloworld-kotlin/src/main/kotlin/org/springframework/integration/samples/helloworld/PollerConfig.kt

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ package org.springframework.integration.samples.helloworld
1818

1919
import org.springframework.context.annotation.Bean
2020
import org.springframework.context.annotation.Configuration
21+
import org.springframework.integration.channel.NullChannel
2122
import org.springframework.integration.config.EnableIntegration
22-
import org.springframework.integration.dsl.IntegrationFlow
23+
import org.springframework.integration.dsl.integrationFlow
24+
import org.springframework.integration.endpoint.MessageProcessorMessageSource
2325
import org.springframework.integration.handler.LoggingHandler
2426

2527
/**
@@ -28,17 +30,26 @@ import org.springframework.integration.handler.LoggingHandler
2830
*
2931
* @author Glenn Renfro
3032
*/
31-
@Configuration
33+
@Configuration(proxyBeanMethods = false)
3234
@EnableIntegration
3335
open class PollerConfig {
3436

37+
/**
38+
* Defines a polling-based integration flow for periodic message generation.
39+
*
40+
* This flow demonstrates a time-triggered, scheduled message processing pattern.
41+
* A message source generates timestamps at fixed intervals, logs the values,
42+
* and discards them via the null channel. This is useful for monitoring,
43+
* health checks, or triggering periodic processing logic.
44+
*
45+
* @return An IntegrationFlow that periodically generates and logs timestamps, then discards them.
46+
*/
3547
@Bean
3648
open fun pollerFlow() =
37-
IntegrationFlow.fromSupplier({ System.currentTimeMillis() }) { e ->
38-
e.poller { p ->
39-
p.fixedDelay(20000).maxMessagesPerPoll(2)
49+
integrationFlow(
50+
MessageProcessorMessageSource { System.currentTimeMillis() },
51+
{ poller { it.fixedDelay(20000).maxMessagesPerPoll(2) } }) {
52+
log(LoggingHandler.Level.INFO, "org.springframework.integration.samples.helloworld")
53+
channel(NullChannel())
4054
}
41-
}
42-
.log(LoggingHandler.Level.INFO, "org.springframework.integration.samples.helloworld")
43-
.nullChannel()
4455
}

0 commit comments

Comments
 (0)