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

Message content enricher

olegz edited this page Jun 5, 2012 · 5 revisions

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

Header Enricher

Root DSL element for all Header Enricher is enrich

There are several convenience methods to enrich the value of the message headers

Enrich single header

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:

  1. Execute Function to calculate the value of the header
  2. _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

Enrich multiple headers

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

Payload Enricher

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 additionalAttributes method which accepts named parameters.

For example:

val enricherA = enrich { m: Message[_] => m } additionalAttributes(name="myEnricher") //infix

val enricherB = enrich { m: Message[_] => m }.additionalAttributes(name="myEnricher") 

will produce a Content Enricher named 'myEnricher'.

Properties that could be set:

name - component name


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