From b2689a2876a25568e9fe197195956341284d42a1 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Mon, 19 Jul 2021 11:17:37 -0400 Subject: [PATCH 1/2] GH-3591: Add `gateway()` section into `dsl.adoc` Fixes https://github.com/spring-projects/spring-integration/issues/3591 --- src/reference/asciidoc/chain.adoc | 1 + src/reference/asciidoc/dsl.adoc | 35 +++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/reference/asciidoc/chain.adoc b/src/reference/asciidoc/chain.adoc index 07238c43e2d..c0cd2247526 100644 --- a/src/reference/asciidoc/chain.adoc +++ b/src/reference/asciidoc/chain.adoc @@ -130,6 +130,7 @@ You can access them from the `BeanFactory` by using the appropriate bean name, a TIP: It is useful to provide an explicit `id` attribute on `` elements to simplify the identification of sub-components in logs and to provide access to them from the `BeanFactory` etc. +[[chain-gateway]] ==== Calling a Chain from within a Chain Sometimes, you need to make a nested call to another chain from within a chain and then come back and continue execution within the original chain. diff --git a/src/reference/asciidoc/dsl.adoc b/src/reference/asciidoc/dsl.adoc index 715a36ba9e5..1613eed98e6 100644 --- a/src/reference/asciidoc/dsl.adoc +++ b/src/reference/asciidoc/dsl.adoc @@ -599,6 +599,41 @@ public IntegrationFlow integerFlow() { Also see <>. +[[java-dsl-gateway]] +=== Operator gateway() + +The `gateway()` operator of `IntegrationFlow` definition is a special service activator implementation to call some other endpoint or integration flow via their input channel and wait for reply from there. +Technically it plays the same role as a nested `` component for `` definition (see <<./chain.adoc#chain-gateway,Calling a Chain from within a Chain>>) and allows to make a code flow much cleaner and more straightforward. +And logically and from business perspective it is a messaging gateway to let to distribute and reuse functionality between different parts of the target integration solution (see <<./gateway.adoc#gateway,Messaging Gateways>>). +This operator has several overloads for different goals: + +- `gateway(String requestChannel)` to call some endpoint's input channel by its name; +- `gateway(MessageChannel requestChannel)` to call some endpoint's input channel by its direct injection; +- `gateway(IntegrationFlow flow)` to call the input channel of the provided `IntegrationFlow`. + +All of them have a variant with the second `Consumer` argument to configure the target `GatewayMessageHandler` and respective `AbstractEndpoint`. +Also the `IntegrationFlow`-based has a power that it allows to call existing `IntegrationFlow` bean or declare the flow as a sub-flow via an in-place lambda for an `IntegrationFlow` functional interface or have it extracted in a `private` method cleaner code style: + +==== +[source,java] +---- +@Bean +IntegrationFlow someFlow() { + return IntegrationFlows + .from(...) + .gateway(subFlow()) + .handle(...) + .get(); +} + +private static IntegrationFlow subFlow() { + return f -> f + .scatterGather(s -> s.recipientFlow(...), + g -> g.outputProcessor(MessageGroup::getOne)) +} +---- +==== + [[java-dsl-log]] === Operator log() From c8a6e2c8051c57442d6fae139a51b9b95c08cc3e Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Mon, 19 Jul 2021 15:08:31 -0400 Subject: [PATCH 2/2] Apply review requested changes --- src/reference/asciidoc/dsl.adoc | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/reference/asciidoc/dsl.adoc b/src/reference/asciidoc/dsl.adoc index 1613eed98e6..78e087e2fe3 100644 --- a/src/reference/asciidoc/dsl.adoc +++ b/src/reference/asciidoc/dsl.adoc @@ -602,17 +602,17 @@ Also see <>. [[java-dsl-gateway]] === Operator gateway() -The `gateway()` operator of `IntegrationFlow` definition is a special service activator implementation to call some other endpoint or integration flow via their input channel and wait for reply from there. -Technically it plays the same role as a nested `` component for `` definition (see <<./chain.adoc#chain-gateway,Calling a Chain from within a Chain>>) and allows to make a code flow much cleaner and more straightforward. -And logically and from business perspective it is a messaging gateway to let to distribute and reuse functionality between different parts of the target integration solution (see <<./gateway.adoc#gateway,Messaging Gateways>>). +The `gateway()` operator in an `IntegrationFlow` definition is a special service activator implementation, to call some other endpoint or integration flow via its input channel and wait for reply. +Technically it plays the same role as a nested `` component in a `` definition (see <<./chain.adoc#chain-gateway,Calling a Chain from within a Chain>>) and allows a flow to be cleaner and more straightforward. +Logically, and from business perspective, it is a messaging gateway to allow the distribution and reuse of functionality between different parts of the target integration solution (see <<./gateway.adoc#gateway,Messaging Gateways>>). This operator has several overloads for different goals: -- `gateway(String requestChannel)` to call some endpoint's input channel by its name; -- `gateway(MessageChannel requestChannel)` to call some endpoint's input channel by its direct injection; -- `gateway(IntegrationFlow flow)` to call the input channel of the provided `IntegrationFlow`. +- `gateway(String requestChannel)` to send a message to some endpoint's input channel by its name; +- `gateway(MessageChannel requestChannel)` to send a message to some endpoint's input channel by its direct injection; +- `gateway(IntegrationFlow flow)` to send a message to the input channel of the provided `IntegrationFlow`. -All of them have a variant with the second `Consumer` argument to configure the target `GatewayMessageHandler` and respective `AbstractEndpoint`. -Also the `IntegrationFlow`-based has a power that it allows to call existing `IntegrationFlow` bean or declare the flow as a sub-flow via an in-place lambda for an `IntegrationFlow` functional interface or have it extracted in a `private` method cleaner code style: +All of these have a variant with the second `Consumer` argument to configure the target `GatewayMessageHandler` and respective `AbstractEndpoint`. +Also the `IntegrationFlow`-based methods allows calling existing `IntegrationFlow` bean or declare the flow as a sub-flow via an in-place lambda for an `IntegrationFlow` functional interface or have it extracted in a `private` method cleaner code style: ==== [source,java] @@ -634,6 +634,9 @@ private static IntegrationFlow subFlow() { ---- ==== +IMPORTANT: If the downstream flow does not always return a reply, you should set the `requestTimeout` to 0 to prevent hanging the calling thread indefinitely. +In that case, the flow will end at that point and the thread released for further work. + [[java-dsl-log]] === Operator log()