Book Image

Spring Integration Essentials

By : CHANDAN K PANDEY
Book Image

Spring Integration Essentials

By: CHANDAN K PANDEY

Overview of this book

Table of Contents (18 chapters)
Spring Integration Essentials
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

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.