Skip to content

Commit dbc8af9

Browse files
authored
GH-3591: Add gateway() section into dsl.adoc (#3593)
* GH-3591: Add `gateway()` section into `dsl.adoc` Fixes #3591 * Apply review requested changes
1 parent af9e69c commit dbc8af9

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/reference/asciidoc/chain.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ You can access them from the `BeanFactory` by using the appropriate bean name, a
130130

131131
TIP: It is useful to provide an explicit `id` attribute on `<chain>` elements to simplify the identification of sub-components in logs and to provide access to them from the `BeanFactory` etc.
132132

133+
[[chain-gateway]]
133134
==== Calling a Chain from within a Chain
134135

135136
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.

src/reference/asciidoc/dsl.adoc

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,44 @@ public IntegrationFlow integerFlow() {
599599

600600
Also see <<java-dsl-class-cast>>.
601601

602+
[[java-dsl-gateway]]
603+
=== Operator gateway()
604+
605+
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.
606+
Technically it plays the same role as a nested `<gateway>` component in a `<chain>` definition (see <<./chain.adoc#chain-gateway,Calling a Chain from within a Chain>>) and allows a flow to be cleaner and more straightforward.
607+
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>>).
608+
This operator has several overloads for different goals:
609+
610+
- `gateway(String requestChannel)` to send a message to some endpoint's input channel by its name;
611+
- `gateway(MessageChannel requestChannel)` to send a message to some endpoint's input channel by its direct injection;
612+
- `gateway(IntegrationFlow flow)` to send a message to the input channel of the provided `IntegrationFlow`.
613+
614+
All of these have a variant with the second `Consumer<GatewayEndpointSpec>` argument to configure the target `GatewayMessageHandler` and respective `AbstractEndpoint`.
615+
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:
616+
617+
====
618+
[source,java]
619+
----
620+
@Bean
621+
IntegrationFlow someFlow() {
622+
return IntegrationFlows
623+
.from(...)
624+
.gateway(subFlow())
625+
.handle(...)
626+
.get();
627+
}
628+
629+
private static IntegrationFlow subFlow() {
630+
return f -> f
631+
.scatterGather(s -> s.recipientFlow(...),
632+
g -> g.outputProcessor(MessageGroup::getOne))
633+
}
634+
----
635+
====
636+
637+
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.
638+
In that case, the flow will end at that point and the thread released for further work.
639+
602640
[[java-dsl-log]]
603641
=== Operator log()
604642

0 commit comments

Comments
 (0)