Spring Integration-4 :Transformers

Transformers take a message from a channel and creates a new message containing converted payload or message structure.  This allows the provider of information and the consumer of information to communicate via SI without having to settle on a common format.  XML can be transformed to JSON, JSON transformed to Java objects, etc.

XML to JSON transformation
  • Transformers convert payload or structure of a message into a modified message
  • Above image converting XML message to Json.

Spring Integration Transformers:

Transformers comes up with in-build transformers

  • XML to Object(Unmarshallers) or Object to XML(Marshallers)
  • Object to String / String to Object
  • file to string / string to file
  • Object Serialiser or deserialiser
  • Object to Map / Map to Object
  • Object to Json /Json to Object
  • Claim check
  • It uses simple POJOs to create your own custom transformer

Simple Transformers examples:

Object to String transformer:

  • Takes message with an object payload from inbound channel
  • calls toString method of a payload object
  • put message containing the resulting string inside outbound channel

Example

<int:object-to-string-transformer input-channel=”in” output-channel=”out”/>

String to String transformer using Spel

<int:transformer input-channel=”in” output-channel=”out” expression=”payload.toUppercase()” />

Popular posts from this blog

Window function in PySpark with Joins example using 2 Dataframes (inner join)

Complex SQL: fetch the users who logged in consecutively 3 or more times (lead perfect example)

Credit Card Data Analysis using PySpark (how to use auto broadcast join after disabling it)