-
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
To enrich a payload use simply provide a Function1[_,AnyRef] as a parameter of the enrich(..) method
val employee = new Employee("John", "Doe", 23)
val enricher =
enrich { p: Person => p.name = employee.firstName + " " + employee.lastName; p.age = employee.age; p }
val enrichedPerson = enricher.sendAndRecieve(new Person)
If you need to add any extra properties to any Content Enricher you may do so using where method which accepts named parameters.
For example:
val enricherA = enrich { m: Message[_] => m } where(name="myEnricher") //infix
val enricherB = enrich { m: Message[_] => m }.where(name="myEnricher")
will produce a Content Enricher named 'myEnricher'.
name - component name
[Back to Core Messaging Patterns] (https://github.com/SpringSource/spring-integration-scala/wiki/Core-Messaging-Patterns)