Skip to content

Commit 55f6920

Browse files
garyrussellartembilan
authored andcommitted
Gateway void return type docs
* Polishing - PR Comments
1 parent ec10698 commit 55f6920

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/reference/asciidoc/gateway.adoc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,30 @@ mono.subscribe(invoice -> handleInvoice(invoice));
764764
765765
The calling thread continues, with `handleInvoice()` being called when the flow completes.
766766
767+
===== Downstream Flows Returning an Async Type
768+
769+
As mentioned in the `ListenableFuture` section above; if you wish some downstream component to return a message with an async payload (`Future`, `Mono`, etc), you must explicitly set the async executor to `null` (or `""` when using XML configuration).
770+
The flow is then invoked on the caller thread and the result can be retrieved later.
771+
772+
===== `void` Return Type
773+
774+
Unlike the return types above, when the method return type is `void`, the framework cannot implicitly determine that you wish the downstream flow to run asynchronously, with the caller thread returning immediately.
775+
In this case, it is necessary to annotate the interface method with `@Async`.
776+
777+
[source, java]
778+
----
779+
@MessagingGateway
780+
public interface MyGateway {
781+
782+
@Gateway(requestChannel = "sendAsyncChannel")
783+
@Async
784+
void sendAsync(String payload);
785+
786+
}
787+
----
788+
789+
Of course, unlike the `Future<?>` return types, there is no way to inform the caller if some exception is thrown by the flow, unless some custom `TaskExecutor` (e.g. an `ErrorHandlingTaskExecutor`) is associated with the `@Async` annotation.
790+
767791
[[gateway-no-response]]
768792
==== Gateway Behavior When No response Arrives
769793

0 commit comments

Comments
 (0)