liveBook · Manning

@ServiceActivator

As explained in Spring in Action, Sixth Edition

A service activator is a Spring Integration endpoint that receives messages from a channel and invokes message-processing logic, optionally producing a message for an output channel.

@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

How Spring in Action, Sixth Edition covers it

How deep it goes
Explains handlers, returned payloads, reply channels, channel selection, and queue polling, while stopping short of framework internals.
Examples
Uses console output, repository-backed EmailOrder persistence, file writing, QueueChannel polling, and Java DSL handle operations.
What it assumes
Assumes basic Java configuration and message-channel concepts while defining handlers through straightforward lambdas.
What you can do after
Build message-processing endpoints, route returned payloads, terminate flows cleanly, and configure polling consumers.
How it connects
Connects message channels, MessageHandler, GenericHandler, output channels, file-writing handlers, and Java DSL flows.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.