You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/reference/asciidoc/service-activator.adoc
+21-9Lines changed: 21 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -153,14 +153,26 @@ See <<java-dsl-handle>> in the Java DSL chapter for more information about confi
153
153
==== Asynchronous Service Activator
154
154
155
155
The service activator is invoked by the calling thread.
156
-
This is an upstream thread if the input channel is a
157
-
`SubscribableChannel` or a poller thread for a `PollableChannel`.
158
-
If the service returns a `ListenableFuture<?>`, the default action is to send that as the payload of the message sent
159
-
to the output (or reply) channel.
160
-
Starting with version 4.3, you can now set the `async` attribute to `true` (by using `setAsync(true)` when using
161
-
Java configuration).
156
+
This is an upstream thread if the input channel is a `SubscribableChannel` or a poller thread for a `PollableChannel`.
157
+
If the service returns a `ListenableFuture<?>`, the default action is to send that as the payload of the message sent to the output (or reply) channel.
158
+
Starting with version 4.3, you can now set the `async` attribute to `true` (by using `setAsync(true)` when using Java configuration).
162
159
If the service returns a `ListenableFuture<?>` when this the `async` attribute is set to `true`, the calling thread is released immediately and the reply message is sent on the thread (from within your service) that completes the future.
163
-
This is particularly advantageous for long-running services that use a `PollableChannel`, because the poller thread is
164
-
released to perform other services within the framework.
160
+
This is particularly advantageous for long-running services that use a `PollableChannel`, because the poller thread is released to perform other services within the framework.
165
161
166
-
If the service completes the future with an `Exception`, normal error processing occurs. An `ErrorMessage` is sent to the `errorChannel` message header, if present. Otherwise, an `ErrorMessage` is sent to the default `errorChannel` (if available).
162
+
If the service completes the future with an `Exception`, normal error processing occurs.
163
+
An `ErrorMessage` is sent to the `errorChannel` message header, if present. Otherwise, an `ErrorMessage` is sent to the default `errorChannel` (if available).
164
+
165
+
166
+
[[service-activator-return-type]]
167
+
==== Service Activator and Method Return Type
168
+
169
+
The service method can return any type which becomes reply message payload.
170
+
In this case a new `Message<?>` object is created and all the headers from a request message are copied.
171
+
This works the same way for most Spring Integration `MessageHandler` implementations, when interaction is based on a POJO method invocation.
172
+
173
+
A complete `Message<?>` object can also be returned from the method.
174
+
However keep in mind that, unlike <<transformer, transformers>>, for a Service Activator this message will be modified by copying the headers from the request message if they are not already present in the returned message.
175
+
So, if your method parameter is a `Message<?>` and you copy some, but not all, existing headers in your service method, they will reappear in the reply message.
176
+
It is not a Service Activator responsibility to remove headers from a reply message and, pursuing the loosely-coupled principle, it is better to add a `HeaderFilter` in the integration flow.
177
+
Alternatively, a Transformer can be used instead of a Service Activator but, in that case, when returning a full `Message<?>` the method is completely responsible for the message, including copying request message headers (if needed).
178
+
It is important to ensure that important framework headers (e.g. `replyChannel`, `errorChannel`), if present, must be preserved.
0 commit comments