Skip to content
This repository was archived by the owner on Jul 9, 2022. It is now read-only.

Message router

olegz edited this page Feb 29, 2012 · 7 revisions

EIP reference for Message Router can be found here - http://www.eaipatterns.com/MessageRouter.html

Continuation from Message Router could be expressed using '-->' operator. However since any router essentially provides a conditional split/fork in the flow, continuation from the router identifies a default Message route when non of the conditions are met.

We currently support several types of Message Routers

Header Value Router

val messageFlow =
	    route.onValueOfHeader("someHeaderName") (
	
	      when("foo") then 
	      	handle.using{m:Message[_] => println("Header is 'foo': " + m)}
	      ,
	      when("bar") then
	        handle.using{m:Message[_] => println("Header is 'bar': " + m)}
	    ) --> 
            handle.using{m:Message[_] => println("Header is not set: " + m)}

Payload Type Router

val messageFlow =
	    route.onPayloadType(
	
	      when(classOf[String]) then 
	      	handle.using{m:Message[_] => println("Payload is String: " + m)}
	      ,
	      when(classOf[Int]) then
	        handle.using{m:Message[_] => println("Payload is Int: " + m)}
	    ) --> 
            handle.using{m:Message[_] => println("Payload is: " + m.getPayload())}

Custom Router

val messageFlow =
	    route.using{m:Message[String] => m.getPayload}(
	
	      when("Hello") then 
	      	handle.using{m:Message[_] => println("Payload is Hello: " + m)}
	      ,
	      when("Bye") then
	        handle.using{m:Message[_] => println("Payload is Bye: " + m)}
	    ) --> 
            Channel("Hi") -->
            handle.using{m:Message[_] => println("Payload is: " + m.getPayload())}

If you need to add any extra properties to any Message Router you may do so using where method which accepts named parameters.

For example:

val messageRouterA = route.using { m: Message[_] => m } where(name="myRouter") //infix

val messageFilterB = route.using { m: Message[_] => m }.where(name="myRouter") 

will produce a Message Router named 'myRouter'.

Properties that could be set:

name - component name

Router's using method signature is:

def using(function:Function1[_,String])

That is done to guard from Functions that return anything other than String to satisfy the Messaging Router contract

[Back to Core Messaging Patterns] (https://github.com/SpringSource/spring-integration-scala/wiki/Core-Messaging-Patterns)

Clone this wiki locally