@ServiceActivator marks a Spring Integration endpoint that receives messages from an input channel and hands them to message-processing logic. A MessageHandler can finish the flow, while a GenericHandler can return a payload for an output channel. section 10.2 section 10.2.6
Saving an email order
Annotate a GenericHandler with @ServiceActivator(inputChannel="orderChannel", outputChannel="completeChannel"). The handler receives an EmailOrder payload and message headers, saves the order through an OrderRepository, and returns the saved order to completeChannel. section 10.2.6
Configure the endpoint according to the channel and flow behavior:
- Use inputChannel to consume messages from a named channel. section 10.2.6
- Add outputChannel when the handler returns a value that should continue through the flow. section 10.2.6
- Set expectReply(false) for a terminal handler such as a file-writing service, avoiding errors about a missing reply channel. section 10.1.2
- Add a poller when consuming from a QueueChannel; fixedRate="1000" polls every second. section 10.2.1
@Bean
@ServiceActivator(inputChannel="orderChannel",
outputChannel="completeChannel")
public GenericHandler<EmailOrder> orderHandler(
OrderRepository orderRepo) {
return (payload, headers) -> {
return orderRepo.save(payload);
};
}
See the complete annotation and GenericHandler example for saving an order and publishing its result. section 10.2.6
