-
Notifications
You must be signed in to change notification settings - Fork 33
Message content enricher
EIP reference for Content Enricher can be found here - http://www.eaipatterns.com/DataEnricher.html
Continuation from Content Enricher could be expressed using '-->' operator.
We currently support payload and headers enrichment within the scope of Content Enricher pattern
There are several convenience methods to enrich the value of the message headers
To enrich a single header use header(..) method
val enricher = enrich.header("hello" -> "bye")
The value of the header could actually be a Function. However there could be tow intentions for providing such function:
- Execute Function to calculate the value of the header
- _Pass Function as is so it may be executed by the component that receives the Message
For #1 simply provide a function as a value of the header
val enricher = enrich.header("hello" -> { m: Message[String] => m.getPayload().toUpperCase() })
For #2 simply pass a function as a value of Some
val enricher = enrich.header("hello" -> Some({ m: Message[String] => m.getPayload().toUpperCase() }))
You can also use Spring Expression Language (SpEL) to pass an Expression that will be executed to calculate the value of the header when Message is processed
val expression = new SpelExpressionParser(new SpelParserConfiguration(true, true)).
parseExpression("(2 * 6) + ' days of Christmas'");
val enricherB = enrich.header("phrase" -> expression)
In the future we'll provide a utility to simplify construction of SpEL expressions
To enrich a multiple headers use headers(..) method
val enricherA = enrich.headers("hello" -> "hello", "bye" -> "bye")
You can use the same techniques to calculate the value of the headers as described above
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'.
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)