Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Routers > Custom Routers

Custom Routers

We can use implementations to write our own custom logic for routing messages. To do so, we need to define a class that expects a message, parses the message (or header), and accordingly returns the channel name. The BigTradeRouter shown below implements a routing logic to forward any big Trades (whose quantity is greater than one million pounds) to a big-trades-channel.

public class BigTradeRouter {
  public String bigTrade(Message<Trade> message){
    Trade t = message.getPayload();
  
    // check if the trade is a big one and if it is
    // send it to a separate channel to handle them
    if(t.getQuantity() > 1000000)
      return "big-trades-channel";
    // else send a normal channel
    return "normal-trades-channel";
  }
}

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint