Using annotations
Spring's power comes from converting simple Java classes to specific components without extending or implementing external classes. To define routers, we can leverage the framework's @Router
annotation. We can annotate any method with @Router
, and can use its reference. Let's take an example where we want to route our feed based on the author:
@Component public class AnnotatedFeedsAuthorRouter { @Router public String feedAuthor(Message<SoFeed > message) { SoFeed sf = message.getPayload(); return sf.getAuthor() ; } }
The return value is a string that is the author's name—a channel with the same name must be present. Alternatively, we can return MessageChannel
or a list of MessageChannel
references directly.
Get Spring Integration Essentials now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.