How does the Spring Integration ServiceActivator return type work?
When you add @ServiceActivator the annotation on the method, which can have different return types, which seems to have different effects on the service:
@ServiceActivator(inputChannel = "..", outputChannel = "..")
public T messageReceiver() {...}
Where could it be
Invalid
Object
Message handlers
How does ServiceActivator differ depending on the return type? I specifically want to know docs The line in reads:
Return values from the annotated method may be of any type. If the return value is not a Message, a reply Message will be created with that object as its payload.
But I didn’t follow this because I see people returning MessageHandlers from their ServiceActivator annotation method and they don’t want their MessageHandlers to be wrapped as payloads, right?
Like this:
@Bean
@ServiceActivator(inputChannel = "sendAsyncChannel", autoStartup="false")
public MessageHandler sendAsyncHandler() {
return // some MessageHandler
}
Solution
You are referring to the messaging comment on the @Bean
. This is a somewhat different story, and it implies nothing to do with the POJO method call aspect.
We use @ServiceActivator on MessageHandler
@Bean
to register MessageHandler
for the provided EventDrivenConsumer
endpoint, when the POJO method is styled. Create a
MethodInvokingMessageHandler
for the method labeled with this @ServiceActivator
.
See the citation manual for more information: