Skip to content

Commit d46847e

Browse files
authored
Update Koltin DSL README for the current state
1 parent 27bc293 commit d46847e

File tree

1 file changed

+3
-98
lines changed

1 file changed

+3
-98
lines changed
Lines changed: 3 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,4 @@
1-
## **_This project has been absorbed by Spring Integration Core starting with version 5.3. Please consult its https://docs.spring.io/spring-integration/docs/current/reference/html[Reference Manual] for the actual documentation. This project is only in a maintenance, bug fixing state._**
1+
Spring Integration Kotlin DSL
2+
===============================
23

3-
= Spring Integration Kotlin DSL
4-
5-
This project is a Kotlin extension for https://docs.spring.io/spring-integration/docs/current/reference/html/#java-dsl[Spring Integration Java DSL].
6-
7-
NOTE: The project should be treated as experimental and API is a subject to changes.
8-
9-
The main goal we pursue here is to make Spring Integration development on Kotlin as smooth and straightforward as is it possible with interoperability with existing Java DSL and some Kotlin extensions or language-specific structures.
10-
11-
All you need to get started is just an import for `org.springframework.integration.dsl.kotlin.integrationFlow` - an overloaded global function for Kotlin DSL.
12-
13-
For `IntegrationFlow` definitions as lambdas we typically don't need anything else from Kotlin and just declare a bean like this:
14-
15-
====
16-
[source, kotlin]
17-
----
18-
@Bean
19-
fun oddFlow() =
20-
IntegrationFlow { flow ->
21-
flow.handle<Any> { _, _ -> "odd" }
22-
}
23-
----
24-
====
25-
26-
In this case Kotlin understands that the lambda should be translated into `IntegrationFlow` anonymous instance and target Java DSL processor parses this construction properly into Java objects.
27-
28-
As an alternative to the construction above and for consistency with use-cases explained below, this project suggest a Kotlin-specif DSL for declaring integration flows in the *builder* pattern style:
29-
30-
====
31-
[source, kotlin]
32-
----
33-
@Bean
34-
fun flowLambda() =
35-
integrationFlow {
36-
filter<String> { it === "test" }
37-
wireTap {
38-
handle { println(it.payload) }
39-
}
40-
transform<String, String> { it.toUpperCase() }
41-
}
42-
----
43-
====
44-
45-
Such a global `integrationFlow()` function expects a lambda in builder style for a `KotlinIntegrationFlowDefinition` (a Kotlin wrapper for the `IntegrationFlowDefinition`) and produces a regular `IntegrationFlow` lambda implementation.
46-
See more overloaded `integrationFlow()` variants below.
47-
48-
Many other scenarios require an `IntegrationFlow` to be started from source of data (e.g. `JdbcPollingChannelAdapter`, `JmsInboundGateway` or just an existing `MessageChannel`).
49-
For this purpose Spring Integration Java DSL provides an `IntegrationFlows` factory with its bunch of overloaded `from()` methods.
50-
This factory can be used in Kotlin as well:
51-
52-
====
53-
[source, kotlin]
54-
----
55-
@Bean
56-
fun flowFromSupplier() =
57-
IntegrationFlows.from<String>({ "bar" }) { e -> e.poller { p -> p.fixedDelay(10).maxMessagesPerPoll(1) } }
58-
.channel { c -> c.queue("fromSupplierQueue") }
59-
.get()
60-
----
61-
====
62-
63-
But unfortunately not all `from()` methods are compatible with Kotlin structures.
64-
To fix a gap, this project provides a Kotlin DSL around an `IntegrationFlows` factory.
65-
It is done as a set of overloaded `integrationFlow()` functions.
66-
With a consumer for a `KotlinIntegrationFlowDefinition` to declare the rest of the flow as an `IntegrationFlow` lambda to reuse the mentioned above experience and also avoid `get()` call in the end.
67-
For example:
68-
69-
====
70-
[source, kotlin]
71-
----
72-
@Bean
73-
fun functionFlow() =
74-
integrationFlow<Function<String, String>>({ beanName("functionGateway") }) {
75-
transform<String, String> { it.toUpperCase() }
76-
}
77-
78-
@Bean
79-
fun messageSourceFlow() =
80-
integrationFlow(MessageProcessorMessageSource { "testSource" },
81-
{ poller { it.fixedDelay(10).maxMessagesPerPoll(1) } }) {
82-
channel { queue("fromSupplierQueue") }
83-
}
84-
----
85-
====
86-
87-
In addition this project provides Kotlin extensions for Java DSL API which needs some refinement for Kotlin structures.
88-
For example `IntegrationFlowDefinition<*>` requires a reifying for many methods with `Class<P>` argument:
89-
90-
====
91-
[source, kotlin]
92-
----
93-
@Bean
94-
fun convertFlow() =
95-
integrationFlow("convertFlowInput") {
96-
convert<TestPojo>()
97-
}
98-
----
99-
====
4+
Starting with Spring Integration `5.3` this extension has been absorbed by [core project](https://docs.spring.io/spring-integration/docs/current/reference/html/kotlin-dsl.html#kotlin-dsl).

0 commit comments

Comments
 (0)