Skip to content

GH-8583: Add Java & DSL samples into docs #8608

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
merged 3 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion src/reference/asciidoc/filter.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,50 @@ MessageFilter filter = new MessageFilter(someSelector);
----
====

In combination with the namespace and SpEL, you can configure powerful filters with very little Java code.
[[filter-dsl]]
==== Configuring a Filter with Java, Groovy and Kotlin DSL

The `IntegrationFlowBuilder` from Java DSL (used also as a base in Groovy and Kotlin DSL) provides a number of overloaded methods for `filter()` operator.
The mentioned above `MessageSelector` abstraction can be used as a Lambda in a `filter()` definition:

====
[source, java, role="primary"]
.Java DSL
----
@Bean
public IntegrationFlow someFlow() {
return f -> f
.<String>filter((payload) -> !"junk".equals(payload));
}
----
[source, kotlin, role="secondary"]
.Kotlin DSL
----
@Bean
fun someFlow() =
integrationFlow {
filter<String> { it != "junk" }
}
----
[source, groovy, role="secondary"]
.Groovy DSL
----
@Bean
someFlow() {
integrationFlow {
filter String, { it != 'junk' }
}
}
----
====

See more information about Java, Kotlin and Groovy DSL in the respective chapters.

[[filter-xml]]
==== Configuring a Filter with XML

In combination with the namespace and SpEL, you can configure powerful filters with very little Java code.

You can use the `<filter>` element is used to create a message-selecting endpoint.
In addition to `input-channel` and `output-channel` attributes, it requires a `ref` attribute.
The `ref` can point to a `MessageSelector` implementation, as the following example shows:
Expand Down
60 changes: 58 additions & 2 deletions src/reference/asciidoc/service-activator.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,63 @@ As with most of the configuration options described here, the same behavior actu
[[service-activator-namespace]]
==== Configuring Service Activator

To create a service activator, use the 'service-activator' element with the 'input-channel' and 'ref' attributes, as the following example shows:
With Java & Annotation configuration, there is just enough to mark respective service method with the `@ServiceActivator` - and the framework calls it when messages are consumed from an input channel:

====
[source,java]
----
public class SomeService {

@ServiceActivator(inputChannel = "exampleChannel")
public void exampleHandler(SomeData payload) {
...
}

}
----
====

See more information in the <<./configuration.adoc#annotations, Annotation Support>>.

For Java, Groovy or Kotlin DSL, the `.handle()` operator of an `IntegrationFlow` represents a service activator:

====
[source, java, role="primary"]
.Java DSL
----
@Bean
public IntegrationFlow someFlow() {
return IntegrationFlow
.from("exampleChannel")
.handle(someService, "exampleHandler")
.get();
}
----
[source, kotlin, role="secondary"]
.Kotlin DSL
----
@Bean
fun someFlow() =
integrationFlow("exampleChannel") {
handle(someService, "exampleHandler")
}
----
[source, groovy, role="secondary"]
.Groovy DSL
----
@Bean
someFlow() {
integrationFlow 'exampleChannel',
{
handle someService, 'exampleHandler'
}
}
----
====

See more information about DSL in respective Java, Groovy and Kotlin chapters.

To create a service activator with an XML configuration, use the 'service-activator' element with the 'input-channel' and 'ref' attributes, as the following example shows:

====
[source,xml]
Expand Down Expand Up @@ -59,7 +115,7 @@ If it can be resolved, the message is sent there.
If the request message does not have a `replyChannel` header and the `reply` object is a `Message`, its `replyChannel` header is consulted for a target destination.
This is the technique used for request-reply messaging in Spring Integration, and it is also an example of the return address pattern.

If your method returns a result and you want to discard it and end the flow, you should configure the `output-channel` to send to a `NullChannel`.
If your method returns a result, and you want to discard it and end the flow, you should configure the `output-channel` to send to a `NullChannel`.
For convenience, the framework registers one with the name, `nullChannel`.
See <<./channel.adoc#channel-special-channels,Special Channels>> for more information.

Expand Down
38 changes: 37 additions & 1 deletion src/reference/asciidoc/splitter.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,42 @@ Starting with version 5.2, the splitter supports a `discardChannel` option for s
In this case there is just no item to iterate for sending to the `outputChannel`.
The `null` splitting result remains as an end of flow indicator.

==== Configuring a Splitter with Java, Groovy and Kotlin DSL

An example of simple splitter based on a `Message` and its iterable payload with DSL configuration:

====
[source, java, role="primary"]
.Java DSL
----
@Bean
public IntegrationFlow someFlow() {
return f -> f.split(Message.class, Message::getPayload);
}
----
[source, kotlin, role="secondary"]
.Kotlin DSL
----
@Bean
fun someFlow() =
integrationFlow {
split<Message<*>> { it.payload }
}
----
[source, groovy, role="secondary"]
.Groovy DSL
----
@Bean
someFlow() {
integrationFlow {
split Message<?>, { it.payload }
}
}
----
====

See <<./dsl.adoc#java-dsl-splitters,Splitters>> in Java DSL chapter for more information.

==== Configuring a Splitter with XML

A splitter can be configured through XML as follows:
Expand Down Expand Up @@ -142,4 +178,4 @@ List<LineItem> extractItems(Order order) {
----
====

See also <<./handler-advice.adoc#advising-with-annotations,Advising Endpoints Using Annotations>>, <<./dsl.adoc#java-dsl-splitters,Splitters>> and <<./file.adoc#file-splitter, File Splitter>>.
See also <<./handler-advice.adoc#advising-with-annotations,Advising Endpoints Using Annotations>> and <<./file.adoc#file-splitter, File Splitter>>.
Loading