(window.webpackJsonp=window.webpackJsonp||[]).push([[127],{555:function(e,t,a){"use strict";a.r(t);var n=a(56),r=Object(n.a)({},(function(){var e=this,t=e.$createElement,a=e._self._c||t;return a("ContentSlotsDistributor",{attrs:{"slot-key":e.$parent.slotKey}},[a("h1",{attrs:{id:"message-transformation"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#message-transformation"}},[e._v("#")]),e._v(" Message Transformation")]),e._v(" "),a("h2",{attrs:{id:"message-transformation-2"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#message-transformation-2"}},[e._v("#")]),e._v(" Message Transformation")]),e._v(" "),a("h3",{attrs:{id:"transformer"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#transformer"}},[e._v("#")]),e._v(" Transformer")]),e._v(" "),a("p",[e._v("Message transformers play a very important role in enabling the loose-coupling of message producers and message consumers.\nRather than requiring every message-producing component to know what type is expected by the next consumer, you can add transformers between those components.\nGeneric transformers, such as one that converts a "),a("code",[e._v("String")]),e._v(" to an XML Document, are also highly reusable.")]),e._v(" "),a("p",[e._v("For some systems, it may be best to provide a "),a("a",{attrs:{href:"https://www.enterpriseintegrationpatterns.com/CanonicalDataModel.html",target:"_blank",rel:"noopener noreferrer"}},[e._v("canonical data model"),a("OutboundLink")],1),e._v(", but Spring Integration’s general philosophy is not to require any particular format.\nRather, for maximum flexibility, Spring Integration aims to provide the simplest possible model for extension.\nAs with the other endpoint types, the use of declarative configuration in XML or Java annotations enables simple POJOs to be adapted for the role of message transformers.\nThe rest of this chapter describes these configuration options.")]),e._v(" "),a("table",[a("thead",[a("tr",[a("th"),e._v(" "),a("th",[e._v("For the sake of maximizing flexibility, Spring does not require XML-based message payloads."),a("br"),e._v("Nevertheless, the framework does provide some convenient transformers for dealing with XML-based payloads if that is indeed the right choice for your application."),a("br"),e._v("For more information on those transformers, see "),a("RouterLink",{attrs:{to:"/en/spring-integration/xml.html#xml"}},[e._v("XML Support - Dealing with XML Payloads")]),e._v(".")],1)])]),e._v(" "),a("tbody")]),e._v(" "),a("h4",{attrs:{id:"configuring-a-transformer-with-xml"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#configuring-a-transformer-with-xml"}},[e._v("#")]),e._v(" Configuring a Transformer with XML")]),e._v(" "),a("p",[e._v("The "),a("code",[e._v("")]),e._v(" element is used to create a message-transforming endpoint.\nIn addition to "),a("code",[e._v("input-channel")]),e._v(" and "),a("code",[e._v("output-channel")]),e._v(" attributes, it requires a "),a("code",[e._v("ref")]),e._v(" attribute.\nThe "),a("code",[e._v("ref")]),e._v(" may either point to an object that contains the "),a("code",[e._v("@Transformer")]),e._v(" annotation on a single method (see "),a("a",{attrs:{href:"#transformer-annotation"}},[e._v("Configuring a Transformer with Annotations")]),e._v("), or it may be combined with an explicit method name value provided in the "),a("code",[e._v("method")]),e._v(" attribute.")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n\n')])])]),a("p",[e._v("Using a "),a("code",[e._v("ref")]),e._v(" attribute is generally recommended if the custom transformer handler implementation can be reused in other "),a("code",[e._v("")]),e._v(" definitions.\nHowever, if the custom transformer handler implementation should be scoped to a single definition of the "),a("code",[e._v("")]),e._v(", you can define an inner bean definition, as the following example shows:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n \n\n')])])]),a("table",[a("thead",[a("tr",[a("th"),e._v(" "),a("th",[e._v("Using both the "),a("code",[e._v("ref")]),e._v(" attribute and an inner handler definition in the same "),a("code",[e._v("")]),e._v(" configuration is not allowed, as it creates an ambiguous condition and results in an exception being thrown.")])])]),e._v(" "),a("tbody")]),e._v(" "),a("table",[a("thead",[a("tr",[a("th"),e._v(" "),a("th",[e._v("If the "),a("code",[e._v("ref")]),e._v(" attribute references a bean that extends "),a("code",[e._v("AbstractMessageProducingHandler")]),e._v(" (such as transformers provided by the framework itself), the configuration is optimized by injecting the output channel into the handler directly."),a("br"),e._v("In this case, each "),a("code",[e._v("ref")]),e._v(" must be to a separate bean instance (or a "),a("code",[e._v("prototype")]),e._v("-scoped bean) or use the inner "),a("code",[e._v("")]),e._v(" configuration type."),a("br"),e._v("If you inadvertently reference the same message handler from multiple beans, you get a configuration exception.")])])]),e._v(" "),a("tbody")]),e._v(" "),a("p",[e._v("When using a POJO, the method that is used for transformation may expect either the "),a("code",[e._v("Message")]),e._v(" type or the payload type of inbound messages.\nIt may also accept message header values either individually or as a full map by using the "),a("code",[e._v("@Header")]),e._v(" and "),a("code",[e._v("@Headers")]),e._v(" parameter annotations, respectively.\nThe return value of the method can be any type.\nIf the return value is itself a "),a("code",[e._v("Message")]),e._v(", that is passed along to the transformer’s output channel.")]),e._v(" "),a("p",[e._v("As of Spring Integration 2.0, a message transformer’s transformation method can no longer return "),a("code",[e._v("null")]),e._v(".\nReturning "),a("code",[e._v("null")]),e._v(" results in an exception, because a message transformer should always be expected to transform each source message into a valid target message.\nIn other words, a message transformer should not be used as a message filter, because there is a dedicated "),a("code",[e._v("")]),e._v(" option for that.\nHowever, if you do need this type of behavior (where a component might return "),a("code",[e._v("null")]),e._v(" and that should not be considered an error), you could use a service activator.\nIts "),a("code",[e._v("requires-reply")]),e._v(" value is "),a("code",[e._v("false")]),e._v(" by default, but that can be set to "),a("code",[e._v("true")]),e._v(" in order to have exceptions thrown for "),a("code",[e._v("null")]),e._v(" return values, as with the transformer.")]),e._v(" "),a("h4",{attrs:{id:""}},[a("a",{staticClass:"header-anchor",attrs:{href:"#"}},[e._v("#")])]),e._v(" "),a("p",[e._v("Like routers, aggregators, and other components, as of Spring Integration 2.0, transformers can also benefit from "),a("a",{attrs:{href:"https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#expressions",target:"_blank",rel:"noopener noreferrer"}},[e._v("SpEL support"),a("OutboundLink")],1),e._v(" whenever transformation logic is relatively simple.\nThe following example shows how to use a SpEL expression:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n')])])]),a("p",[e._v("The preceding example transforms the payload without writing a custom transformer.\nOur payload (assumed to be a "),a("code",[e._v("String")]),e._v(") is upper-cased, concatenated with the current timestamp, and has some formatting applied.")]),e._v(" "),a("h4",{attrs:{id:"common-transformers"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#common-transformers"}},[e._v("#")]),e._v(" Common Transformers")]),e._v(" "),a("p",[e._v("Spring Integration provides a few transformer implementations.")]),e._v(" "),a("h5",{attrs:{id:"object-to-string-transformer"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#object-to-string-transformer"}},[e._v("#")]),e._v(" Object-to-String Transformer")]),e._v(" "),a("p",[e._v("Because it is fairly common to use the "),a("code",[e._v("toString()")]),e._v(" representation of an "),a("code",[e._v("Object")]),e._v(", Spring Integration provides an "),a("code",[e._v("ObjectToStringTransformer")]),e._v(" whose output is a "),a("code",[e._v("Message")]),e._v(" with a String "),a("code",[e._v("payload")]),e._v(".\nThat "),a("code",[e._v("String")]),e._v(" is the result of invoking the "),a("code",[e._v("toString()")]),e._v(" operation on the inbound Message’s payload.\nThe following example shows how to declare an instance of the object-to-string transformer:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n')])])]),a("p",[e._v("A potential use for this transformer would be sending some arbitrary object to the 'outbound-channel-adapter' in the "),a("code",[e._v("file")]),e._v(" namespace.\nWhereas that channel adapter only supports "),a("code",[e._v("String")]),e._v(", byte-array, or "),a("code",[e._v("java.io.File")]),e._v(" payloads by default, adding this transformer immediately before the adapter handles the necessary conversion.\nThat works fine as long as the result of the "),a("code",[e._v("toString()")]),e._v(" call is what you want to be written to the file.\nOtherwise, you can provide a custom POJO-based transformer by using the generic 'transformer' element shown previously.")]),e._v(" "),a("table",[a("thead",[a("tr",[a("th"),e._v(" "),a("th",[e._v("When debugging, this transformer is not typically necessary, since the "),a("code",[e._v("logging-channel-adapter")]),e._v(" is capable of logging the message payload."),a("br"),e._v("See "),a("RouterLink",{attrs:{to:"/en/spring-integration/channel.html#channel-wiretap"}},[e._v("Wire Tap")]),e._v(" for more detail.")],1)])]),e._v(" "),a("tbody")]),e._v(" "),a("table",[a("thead",[a("tr",[a("th"),e._v(" "),a("th",[e._v("The object-to-string transformer is very simple."),a("br"),e._v("It invokes "),a("code",[e._v("toString()")]),e._v(" on the inbound payload."),a("br"),e._v("Since Spring Integration 3.0, there are two exceptions to this rule:"),a("br"),a("br"),e._v("* If the payload is a "),a("code",[e._v("char[]")]),e._v(", it invokes "),a("code",[e._v("new String(payload)")]),e._v("."),a("br"),a("br"),e._v("* If the payload is a "),a("code",[e._v("byte[]")]),e._v(", it invokes "),a("code",[e._v("new String(payload, charset)")]),e._v(", where "),a("code",[e._v("charset")]),e._v(" is UTF-8 by default."),a("br"),e._v(" The "),a("code",[e._v("charset")]),e._v(" can be modified by supplying the charset attribute on the transformer."),a("br"),a("br"),e._v("For more sophistication (such as selection of the charset dynamically, at runtime), you can use a SpEL expression-based transformer instead, as the following example shows:"),a("br"),a("br"),a("code",[e._v('
expression="new java.lang.String(payload, headers[\'myCharset\']" />
')])])])]),e._v(" "),a("tbody")]),e._v(" "),a("p",[e._v("If you need to serialize an "),a("code",[e._v("Object")]),e._v(" to a byte array or deserialize a byte array back into an "),a("code",[e._v("Object")]),e._v(", Spring Integration provides symmetrical serialization transformers.\nThese use standard Java serialization by default, but you can provide an implementation of Spring "),a("code",[e._v("Serializer")]),e._v(" or "),a("code",[e._v("Deserializer")]),e._v(" strategies by using the "),a("code",[e._v("serializer")]),e._v(" and "),a("code",[e._v("deserializer")]),e._v(" attributes, respectively.\nThe following example shows to use Spring’s serializer and deserializer:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n\n\n')])])]),a("table",[a("thead",[a("tr",[a("th"),e._v(" "),a("th",[e._v("When deserializing data from untrusted sources, you should consider adding a "),a("code",[e._v("allow-list")]),e._v(" of package and class patterns."),a("br"),e._v("By default, all classes are deserialized.")])])]),e._v(" "),a("tbody")]),e._v(" "),a("h5",{attrs:{id:"object-to-map-and-map-to-object-transformers"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#object-to-map-and-map-to-object-transformers"}},[e._v("#")]),e._v(" "),a("code",[e._v("Object")]),e._v("-to-"),a("code",[e._v("Map")]),e._v(" and "),a("code",[e._v("Map")]),e._v("-to-"),a("code",[e._v("Object")]),e._v(" Transformers")]),e._v(" "),a("p",[e._v("Spring Integration also provides "),a("code",[e._v("Object")]),e._v("-to-"),a("code",[e._v("Map")]),e._v(" and "),a("code",[e._v("Map")]),e._v("-to-"),a("code",[e._v("Object")]),e._v(" transformers, which use the JSON to serialize and de-serialize the object graphs.\nThe object hierarchy is introspected to the most primitive types ("),a("code",[e._v("String")]),e._v(", "),a("code",[e._v("int")]),e._v(", and so on).\nThe path to this type is described with SpEL, which becomes the "),a("code",[e._v("key")]),e._v(" in the transformed "),a("code",[e._v("Map")]),e._v(".\nThe primitive type becomes the value.")]),e._v(" "),a("p",[e._v("Consider the following example:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v("public class Parent{\n private Child child;\n private String name;\n // setters and getters are omitted\n}\n\npublic class Child{\n private String name;\n private List nickNames;\n // setters and getters are omitted\n}\n")])])]),a("p",[e._v("The two classes in the preceding example are transformed to the following "),a("code",[e._v("Map")]),e._v(":")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v("{person.name=George, person.child.name=Jenna, person.child.nickNames[0]=Jen ...}\n")])])]),a("p",[e._v("The JSON-based "),a("code",[e._v("Map")]),e._v(" lets you describe the object structure without sharing the actual types, which lets you restore and rebuild the object graph into a differently typed object graph, as long as you maintain the structure.")]),e._v(" "),a("p",[e._v("For example, the preceding structure could be restored back to the following object graph by using the "),a("code",[e._v("Map")]),e._v("-to-"),a("code",[e._v("Object")]),e._v(" transformer:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v("public class Father {\n private Kid child;\n private String name;\n // setters and getters are omitted\n}\n\npublic class Kid {\n private String name;\n private List nickNames;\n // setters and getters are omitted\n}\n")])])]),a("p",[e._v("If you need to create a “structured” map, you can provide the "),a("code",[e._v("flatten")]),e._v(" attribute.\nThe default is 'true'.\nIf you set it to 'false', the structure is a "),a("code",[e._v("Map")]),e._v(" of "),a("code",[e._v("Map")]),e._v(" objects.")]),e._v(" "),a("p",[e._v("Consider the following example:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v("public class Parent {\n\tprivate Child child;\n\tprivate String name;\n\t// setters and getters are omitted\n}\n\npublic class Child {\n\tprivate String name;\n\tprivate List nickNames;\n\t// setters and getters are omitted\n}\n")])])]),a("p",[e._v("The two classes in the preceding example are transformed to the following "),a("code",[e._v("Map")]),e._v(":")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v("{name=George, child={name=Jenna, nickNames=[Bimbo, ...]}}\n")])])]),a("p",[e._v("To configure these transformers, Spring Integration provides namespace support for Object-to-Map, as the following example shows:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n')])])]),a("p",[e._v("You can also set the "),a("code",[e._v("flatten")]),e._v(" attribute to false, as follows:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n')])])]),a("p",[e._v("Spring Integration provides namespace support for Map-to-Object, as the following example shows:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n')])])]),a("p",[e._v("Alterately, you could use a "),a("code",[e._v("ref")]),e._v(" attribute and a prototype-scoped bean, as the following example shows:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n\n')])])]),a("table",[a("thead",[a("tr",[a("th"),e._v(" "),a("th",[e._v("The 'ref' and 'type' attributes are mutually exclusive."),a("br"),e._v("Also, if you use the 'ref' attribute, you must point to a 'prototype' scoped bean."),a("br"),e._v("Otherwise, a "),a("code",[e._v("BeanCreationException")]),e._v(" is thrown.")])])]),e._v(" "),a("tbody")]),e._v(" "),a("p",[e._v("Starting with version 5.0, you can supply the "),a("code",[e._v("ObjectToMapTransformer")]),e._v(" with a customized "),a("code",[e._v("JsonObjectMapper")]),e._v(" — for when you need special formats for dates or nulls for empty collections (and other uses).\nSee "),a("a",{attrs:{href:"#json-transformers"}},[e._v("JSON Transformers")]),e._v(" for more information about "),a("code",[e._v("JsonObjectMapper")]),e._v(" implementations.")]),e._v(" "),a("h5",{attrs:{id:"stream-transformer"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#stream-transformer"}},[e._v("#")]),e._v(" Stream Transformer")]),e._v(" "),a("p",[e._v("The "),a("code",[e._v("StreamTransformer")]),e._v(" transforms "),a("code",[e._v("InputStream")]),e._v(" payloads to a "),a("code",[e._v("byte[]")]),e._v("( or a "),a("code",[e._v("String")]),e._v(" if a "),a("code",[e._v("charset")]),e._v(" is provided).")]),e._v(" "),a("p",[e._v("The following example shows how to use the "),a("code",[e._v("stream-transformer")]),e._v(" element in XML:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v(' \x3c!-- byte[] --\x3e\n\n \x3c!-- String --\x3e\n')])])]),a("p",[e._v("The following example shows how to use the "),a("code",[e._v("StreamTransformer")]),e._v(" class and the "),a("code",[e._v("@Transformer")]),e._v(" annotation to configure a stream transformer in Java:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('@Bean\n@Transformer(inputChannel = "stream", outputChannel = "data")\npublic StreamTransformer streamToBytes() {\n return new StreamTransformer(); // transforms to byte[]\n}\n\n@Bean\n@Transformer(inputChannel = "stream", outputChannel = "data")\npublic StreamTransformer streamToString() {\n return new StreamTransformer("UTF-8"); // transforms to String\n}\n')])])]),a("h5",{attrs:{id:"json-transformers"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#json-transformers"}},[e._v("#")]),e._v(" JSON Transformers")]),e._v(" "),a("p",[e._v("Spring Integration provides Object-to-JSON and JSON-to-Object transformers.\nThe following pair of examples show how to declare them in XML:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n')])])]),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n')])])]),a("p",[e._v("By default, the transformers in the preceding listing use a vanilla "),a("code",[e._v("JsonObjectMapper")]),e._v(".\nIt is based on an implementation from the classpath.\nYou can provide your own custom "),a("code",[e._v("JsonObjectMapper")]),e._v(" implementation with appropriate options or based on a required library (such as GSON), as the following example shows:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n')])])]),a("table",[a("thead",[a("tr",[a("th"),e._v(" "),a("th",[e._v("Beginning with version 3.0, the "),a("code",[e._v("object-mapper")]),e._v(" attribute references an instance of a new strategy interface: "),a("code",[e._v("JsonObjectMapper")]),e._v("."),a("br"),e._v("This abstraction lets multiple implementations of JSON mappers be used."),a("br"),e._v("Implementation that wraps "),a("a",{attrs:{href:"https://github.com/FasterXML",target:"_blank",rel:"noopener noreferrer"}},[e._v("Jackson 2"),a("OutboundLink")],1),e._v(" is provided, with the version being detected on the classpath."),a("br"),e._v("The class is "),a("code",[e._v("Jackson2JsonObjectMapper")]),e._v(", respectively.")])])]),e._v(" "),a("tbody")]),e._v(" "),a("p",[e._v("You may wish to consider using a "),a("code",[e._v("FactoryBean")]),e._v(" or a factory method to create the "),a("code",[e._v("JsonObjectMapper")]),e._v(" with the required characteristics.\nThe following example shows how to use such a factory:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v("public class ObjectMapperFactory {\n\n public static Jackson2JsonObjectMapper getMapper() {\n ObjectMapper mapper = new ObjectMapper();\n mapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);\n return new Jackson2JsonObjectMapper(mapper);\n }\n}\n")])])]),a("p",[e._v("The following example shows how to do the same thing in XML")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n')])])]),a("table",[a("thead",[a("tr",[a("th"),e._v(" "),a("th",[e._v("Beginning with version 2.2, the "),a("code",[e._v("object-to-json-transformer")]),e._v(" sets the "),a("code",[e._v("content-type")]),e._v(" header to "),a("code",[e._v("application/json")]),e._v(", by default, if the input message does not already have that header."),a("br"),a("br"),e._v("It you wish to set the "),a("code",[e._v("content-type")]),e._v(" header to some other value or explicitly overwrite any existing header with some value (including "),a("code",[e._v("application/json")]),e._v("), use the "),a("code",[e._v("content-type")]),e._v(" attribute."),a("br"),e._v("If you wish to suppress the setting of the header, set the "),a("code",[e._v("content-type")]),e._v(" attribute to an empty string ("),a("code",[e._v('""')]),e._v(")."),a("br"),e._v("Doing so results in a message with no "),a("code",[e._v("content-type")]),e._v(" header, unless such a header was present on the input message.")])])]),e._v(" "),a("tbody")]),e._v(" "),a("p",[e._v("Beginning with version 3.0, the "),a("code",[e._v("ObjectToJsonTransformer")]),e._v(" adds headers, reflecting the source type, to the message.\nSimilarly, the "),a("code",[e._v("JsonToObjectTransformer")]),e._v(" can use those type headers when converting the JSON to an object.\nThese headers are mapped in the AMQP adapters so that they are entirely compatible with the Spring-AMQP "),a("a",{attrs:{href:"https://docs.spring.io/spring-amqp/api/",target:"_blank",rel:"noopener noreferrer"}},[a("code",[e._v("JsonMessageConverter")]),a("OutboundLink")],1),e._v(".")]),e._v(" "),a("p",[e._v("This enables the following flows to work without any special configuration:")]),e._v(" "),a("ul",[a("li",[a("p",[a("code",[e._v("…​→amqp-outbound-adapter---→")])])]),e._v(" "),a("li",[a("p",[a("code",[e._v("---→amqp-inbound-adapter→json-to-object-transformer→…​")])]),e._v(" "),a("p",[e._v("Where the outbound adapter is configured with a "),a("code",[e._v("JsonMessageConverter")]),e._v(" and the inbound adapter uses the default "),a("code",[e._v("SimpleMessageConverter")]),e._v(".")])]),e._v(" "),a("li",[a("p",[a("code",[e._v("…​→object-to-json-transformer→amqp-outbound-adapter---→")])])]),e._v(" "),a("li",[a("p",[a("code",[e._v("---→amqp-inbound-adapter→…​")])]),e._v(" "),a("p",[e._v("Where the outbound adapter is configured with a "),a("code",[e._v("SimpleMessageConverter")]),e._v(" and the inbound adapter uses the default "),a("code",[e._v("JsonMessageConverter")]),e._v(".")])]),e._v(" "),a("li",[a("p",[a("code",[e._v("…​→object-to-json-transformer→amqp-outbound-adapter---→")])])]),e._v(" "),a("li",[a("p",[a("code",[e._v("---→amqp-inbound-adapter→json-to-object-transformer→")])]),e._v(" "),a("p",[e._v("Where both adapters are configured with a "),a("code",[e._v("SimpleMessageConverter")]),e._v(".")])])]),e._v(" "),a("table",[a("thead",[a("tr",[a("th"),e._v(" "),a("th",[e._v("When using the headers to determine the type, you should not provide a "),a("code",[e._v("class")]),e._v(" attribute, because it takes precedence over the headers.")])])]),e._v(" "),a("tbody")]),e._v(" "),a("p",[e._v("In addition to JSON Transformers, Spring Integration provides a built-in "),a("code",[e._v("#jsonPath")]),e._v(" SpEL function for use in expressions.\nFor more information see "),a("RouterLink",{attrs:{to:"/en/spring-integration/spel.html#spel"}},[e._v("Spring Expression Language (SpEL)")]),e._v(".")],1),e._v(" "),a("p",[e._v("Since version 3.0, Spring Integration also provides a built-in "),a("code",[e._v("#xpath")]),e._v(" SpEL function for use in expressions.\nFor more information see "),a("RouterLink",{attrs:{to:"/en/spring-integration/xml.html#xpath-spel-function"}},[e._v("#xpath SpEL Function")]),e._v(".")],1),e._v(" "),a("p",[e._v("Beginning with version 4.0, the "),a("code",[e._v("ObjectToJsonTransformer")]),e._v(" supports the "),a("code",[e._v("resultType")]),e._v(" property, to specify the node JSON representation.\nThe result node tree representation depends on the implementation of the provided "),a("code",[e._v("JsonObjectMapper")]),e._v(".\nBy default, the "),a("code",[e._v("ObjectToJsonTransformer")]),e._v(" uses a "),a("code",[e._v("Jackson2JsonObjectMapper")]),e._v(" and delegates the conversion of the object to the node tree to the "),a("code",[e._v("ObjectMapper#valueToTree")]),e._v(" method.\nThe node JSON representation provides efficiency for using the "),a("code",[e._v("JsonPropertyAccessor")]),e._v(" when the downstream message flow uses SpEL expressions with access to the properties of the JSON data.\nSee "),a("RouterLink",{attrs:{to:"/en/spring-integration/spel.html#spel-property-accessors"}},[e._v("Property Accessors")]),e._v(" for more information.")],1),e._v(" "),a("p",[e._v("Beginning with version 5.1, the "),a("code",[e._v("resultType")]),e._v(" can be configured as "),a("code",[e._v("BYTES")]),e._v(" to produce a message with the "),a("code",[e._v("byte[]")]),e._v(" payload for convenience when working with downstream handlers which operate with this data type.")]),e._v(" "),a("p",[e._v("Starting with version 5.2, the "),a("code",[e._v("JsonToObjectTransformer")]),e._v(" can be configured with a "),a("code",[e._v("ResolvableType")]),e._v(" to support generics during deserialization with the target JSON processor.\nAlso this component now consults request message headers first for the presence of the "),a("code",[e._v("JsonHeaders.RESOLVABLE_TYPE")]),e._v(" or "),a("code",[e._v("JsonHeaders.TYPE_ID")]),e._v(" and falls back to the configured type otherwise.\nThe "),a("code",[e._v("ObjectToJsonTransformer")]),e._v(" now also populates a "),a("code",[e._v("JsonHeaders.RESOLVABLE_TYPE")]),e._v(" header based on the request message payload for any possible downstream scenarios.")]),e._v(" "),a("p",[e._v("Starting with version 5.2.6, the "),a("code",[e._v("JsonToObjectTransformer")]),e._v(" can be supplied with a "),a("code",[e._v("valueTypeExpression")]),e._v(" to resolve a "),a("code",[e._v("ResolvableType")]),e._v(" for the payload to convert from JSON at runtime against the request message.\nBy default it consults "),a("code",[e._v("JsonHeaders")]),e._v(" in the request message.\nIf this expression returns "),a("code",[e._v("null")]),e._v(" or "),a("code",[e._v("ResolvableType")]),e._v(" building throws a "),a("code",[e._v("ClassNotFoundException")]),e._v(", the transformer falls back to the provided "),a("code",[e._v("targetType")]),e._v(".\nThis logic is present as an expression because "),a("code",[e._v("JsonHeaders")]),e._v(" may not have real class values, but rather some type ids which have to be mapped to target classes according some external registry.")]),e._v(" "),a("h5",{attrs:{id:"apache-avro-transformers"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#apache-avro-transformers"}},[e._v("#")]),e._v(" Apache Avro Transformers")]),e._v(" "),a("p",[e._v("Version 5.2 added simple transformers to transform to/from Apache Avro.")]),e._v(" "),a("p",[e._v("They are unsophisticated in that there is no schema registry; the transformers simply use the schema embedded in the "),a("code",[e._v("SpecificRecord")]),e._v(" implementation generated from the Avro schema.")]),e._v(" "),a("p",[e._v("Messages sent to the "),a("code",[e._v("SimpleToAvroTransformer")]),e._v(" must have a payload that implements "),a("code",[e._v("SpecificRecord")]),e._v("; the transformer can handle multiple types.\nThe "),a("code",[e._v("SimpleFromAvroTransformer")]),e._v(" must be configured with a "),a("code",[e._v("SpecificRecord")]),e._v(" class which is used as the default type to deserialize.\nYou can also specify a SpEL expression to determine the type to deserialize using the "),a("code",[e._v("setTypeExpression")]),e._v(" method.\nThe default SpEL expression is "),a("code",[e._v("headers[avro_type]")]),e._v(" ("),a("code",[e._v("AvroHeaders.TYPE")]),e._v(") which, by default, is populated by the "),a("code",[e._v("SimpleToAvroTransformer")]),e._v(" with the fully qualified class name of the source class.\nIf the expression returns "),a("code",[e._v("null")]),e._v(", the "),a("code",[e._v("defaultType")]),e._v(" is used.")]),e._v(" "),a("p",[e._v("The "),a("code",[e._v("SimpleToAvroTransformer")]),e._v(" also has a "),a("code",[e._v("setTypeExpression")]),e._v(" method.\nThis allows decoupling of the producer and consumer where the sender can set the header to some token representing the type and the consumer then maps that token to a type.")]),e._v(" "),a("h4",{attrs:{id:"configuring-a-transformer-with-annotations"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#configuring-a-transformer-with-annotations"}},[e._v("#")]),e._v(" Configuring a Transformer with Annotations")]),e._v(" "),a("p",[e._v("You can add the "),a("code",[e._v("@Transformer")]),e._v(" annotation to methods that expect either the "),a("code",[e._v("Message")]),e._v(" type or the message payload type.\nThe return value is handled in the exact same way as described earlier "),a("a",{attrs:{href:"#transformer-namespace"}},[e._v("in the section describing the "),a("code",[e._v("")]),e._v(" element")]),e._v(".\nThe following example shows how to use the "),a("code",[e._v("@Transformer")]),e._v(" annotation to transform a "),a("code",[e._v("String")]),e._v(" into an "),a("code",[e._v("Order")]),e._v(":")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v("@Transformer\nOrder generateOrder(String productId) {\n return new Order(productId);\n}\n")])])]),a("p",[e._v("Transformer methods can also accept the "),a("code",[e._v("@Header")]),e._v(" and "),a("code",[e._v("@Headers")]),e._v(" annotations, as documented in "),a("code",[e._v("[Annotation Support](./configuration.html#annotations)")]),e._v(".\nThe following examples shows how to use the "),a("code",[e._v("@Header")]),e._v(" annotation:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('@Transformer\nOrder generateOrder(String productId, @Header("customerName") String customer) {\n return new Order(productId, customer);\n}\n')])])]),a("p",[e._v("See also "),a("RouterLink",{attrs:{to:"/en/spring-integration/handler-advice.html#advising-with-annotations"}},[e._v("Advising Endpoints Using Annotations")]),e._v(".")],1),e._v(" "),a("h4",{attrs:{id:"header-filter"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#header-filter"}},[e._v("#")]),e._v(" Header Filter")]),e._v(" "),a("p",[e._v("Sometimes, your transformation use case might be as simple as removing a few headers.\nFor such a use case, Spring Integration provides a header filter that lets you specify certain header names that should be removed from the output message (for example, removing headers for security reasons or a value that was needed only temporarily).\nBasically, the header filter is the opposite of the header enricher.\nThe latter is discussed in "),a("RouterLink",{attrs:{to:"/en/spring-integration/content-enrichment.html#header-enricher"}},[e._v("Header Enricher")]),e._v(".\nThe following example defines a header filter:")],1),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n')])])]),a("p",[e._v("As you can see, configuration of a header filter is quite simple.\nIt is a typical endpoint with input and output channels and a "),a("code",[e._v("header-names")]),e._v(" attribute.\nThat attribute accepts the names of the headers (delimited by commas if there are multiple) that need to be removed.\nSo, in the preceding example, the headers named 'lastName' and 'state' are not present on the outbound message.")]),e._v(" "),a("h4",{attrs:{id:"codec-based-transformers"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#codec-based-transformers"}},[e._v("#")]),e._v(" Codec-Based Transformers")]),e._v(" "),a("p",[e._v("See "),a("RouterLink",{attrs:{to:"/en/spring-integration/codec.html#codec"}},[e._v("Codec")]),e._v(".")],1),e._v(" "),a("h3",{attrs:{id:"content-enricher"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#content-enricher"}},[e._v("#")]),e._v(" Content Enricher")]),e._v(" "),a("p",[e._v("At times, you may have a requirement to enhance a request with more information than was provided by the target system.\nThe "),a("a",{attrs:{href:"https://www.enterpriseintegrationpatterns.com/DataEnricher.html",target:"_blank",rel:"noopener noreferrer"}},[e._v("data enricher"),a("OutboundLink")],1),e._v(" pattern describes various scenarios as well as the component (Enricher) that lets you address such requirements.")]),e._v(" "),a("p",[e._v("The Spring Integration "),a("code",[e._v("Core")]),e._v(" module includes two enrichers:")]),e._v(" "),a("ul",[a("li",[a("p",[a("a",{attrs:{href:"#header-enricher"}},[e._v("Header Enricher")])])]),e._v(" "),a("li",[a("p",[a("a",{attrs:{href:"#payload-enricher"}},[e._v("Payload Enricher")])])])]),e._v(" "),a("p",[e._v("It also includes three adapter-specific header enrichers:")]),e._v(" "),a("ul",[a("li",[a("p",[a("RouterLink",{attrs:{to:"/en/spring-integration/xml.html#xml-xpath-header-enricher"}},[e._v("XPath Header Enricher (XML Module)")])],1)]),e._v(" "),a("li",[a("p",[a("RouterLink",{attrs:{to:"/en/spring-integration/mail.html#mail-namespace"}},[e._v("Mail Header Enricher (Mail Module)")])],1)]),e._v(" "),a("li",[a("p",[a("RouterLink",{attrs:{to:"/en/spring-integration/xmpp.html#xmpp-message-outbound-channel-adapter"}},[e._v("XMPP Header Enricher (XMPP Module)")])],1)])]),e._v(" "),a("p",[e._v("See the adapter-specific sections of this reference manual to learn more about those adapters.")]),e._v(" "),a("p",[e._v("For more information regarding expressions support, see "),a("RouterLink",{attrs:{to:"/en/spring-integration/spel.html#spel"}},[e._v("Spring Expression Language (SpEL)")]),e._v(".")],1),e._v(" "),a("h4",{attrs:{id:"header-enricher"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#header-enricher"}},[e._v("#")]),e._v(" Header Enricher")]),e._v(" "),a("p",[e._v("If you need do nothing more than add headers to a message and the headers are not dynamically determined by the message content, referencing a custom implementation of a transformer may be overkill.\nFor that reason, Spring Integration provides support for the header enricher pattern.\nIt is exposed through the "),a("code",[e._v("")]),e._v(" element.\nThe following example shows how to use it:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n \n \n\n')])])]),a("p",[e._v("The header enricher also provides helpful sub-elements to set well known header names, as the following example shows:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n \n \n \n \n \n \n\n')])])]),a("p",[e._v("The preceding configuration shows that, for well known headers (such as "),a("code",[e._v("errorChannel")]),e._v(", "),a("code",[e._v("correlationId")]),e._v(", "),a("code",[e._v("priority")]),e._v(", "),a("code",[e._v("replyChannel")]),e._v(", "),a("code",[e._v("routing-slip")]),e._v(", and others), instead of using generic "),a("code",[e._v("
")]),e._v(" sub-elements where you would have to provide both header 'name' and 'value', you can use convenient sub-elements to set those values directly.")]),e._v(" "),a("p",[e._v("Starting with version 4.1, the header enricher provides a "),a("code",[e._v("routing-slip")]),e._v(" sub-element.\nSee "),a("RouterLink",{attrs:{to:"/en/spring-integration/router.html#routing-slip"}},[e._v("Routing Slip")]),e._v(" for more information.")],1),e._v(" "),a("h5",{attrs:{id:"pojo-support"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#pojo-support"}},[e._v("#")]),e._v(" POJO Support")]),e._v(" "),a("p",[e._v("Often, a header value cannot be defined statically and has to be determined dynamically based on some content in the message.\nThat is why the header enricher lets you also specify a bean reference by using the "),a("code",[e._v("ref")]),e._v(" and "),a("code",[e._v("method")]),e._v(" attributes.\nThe specified method calculates the header value.\nConsider the following configuration and a bean with a method that modifies a "),a("code",[e._v("String")]),e._v(":")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n \n\n\n\n')])])]),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('public class MyBean {\n\n public String computeValue(String payload){\n return payload.toUpperCase() + "_US";\n }\n}\n')])])]),a("p",[e._v("You can also configure your POJO as an inner bean, as the following example shows:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n \n \n \n\n')])])]),a("p",[e._v("You can similarly point to a Groovy script, as the following example shows:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n \n \n \n\n')])])]),a("h5",{attrs:{id:"spel-support"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#spel-support"}},[e._v("#")]),e._v(" SpEL Support")]),e._v(" "),a("p",[e._v("In Spring Integration 2.0, we introduced the convenience of the "),a("a",{attrs:{href:"https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#expressions",target:"_blank",rel:"noopener noreferrer"}},[e._v("Spring Expression Language (SpEL)"),a("OutboundLink")],1),e._v(' to help configure many different components.\nThe header enricher is one of them.\nLook again at the POJO example shown earlier.\nYou can see that the computation logic to determine the header value is pretty simple.\nA natural question would be: "Is there an even simpler way to accomplish this?".\nThat is where SpEL shows its true power.\nConsider the following example:')]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n \n\n')])])]),a("p",[e._v("By using SpEL for such simple cases, you no longer have to provide a separate class and configure it in the application context.\nAll you need do is configured the "),a("code",[e._v("expression")]),e._v(" attribute with a valid SpEL expression.\nThe 'payload' and 'headers' variables are bound to the SpEL evaluation context, giving you full access to the incoming message.")]),e._v(" "),a("h5",{attrs:{id:"configuring-a-header-enricher-with-java-configuration"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#configuring-a-header-enricher-with-java-configuration"}},[e._v("#")]),e._v(" Configuring a Header Enricher with Java Configuration")]),e._v(" "),a("p",[e._v("The following two examples show how to use Java Configuration for header enrichers:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('@Bean\n@Transformer(inputChannel = "enrichHeadersChannel", outputChannel = "emailChannel")\npublic HeaderEnricher enrichHeaders() {\n Map> headersToAdd =\n Collections.singletonMap("emailUrl",\n new StaticHeaderValueMessageProcessor<>(this.imapUrl));\n HeaderEnricher enricher = new HeaderEnricher(headersToAdd);\n return enricher;\n}\n\n@Bean\n@Transformer(inputChannel="enrichHeadersChannel", outputChannel="emailChannel")\npublic HeaderEnricher enrichHeaders() {\n Map> headersToAdd = new HashMap<>();\n headersToAdd.put("emailUrl", new StaticHeaderValueMessageProcessor(this.imapUrl));\n Expression expression = new SpelExpressionParser().parseExpression("payload.from[0].toString()");\n headersToAdd.put("from",\n new ExpressionEvaluatingHeaderValueMessageProcessor<>(expression, String.class));\n HeaderEnricher enricher = new HeaderEnricher(headersToAdd);\n return enricher;\n}\n')])])]),a("p",[e._v("The first example adds a single literal header.\nThe second example adds two headers, a literal header and one based on a SpEL expression.")]),e._v(" "),a("h5",{attrs:{id:"configuring-a-header-enricher-with-the-java-dsl"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#configuring-a-header-enricher-with-the-java-dsl"}},[e._v("#")]),e._v(" Configuring a Header Enricher with the Java DSL")]),e._v(" "),a("p",[e._v("The following example shows Java DSL Configuration for a header enricher:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('@Bean\npublic IntegrationFlow enrichHeadersInFlow() {\n return f -> f\n ...\n .enrichHeaders(h -> h.header("emailUrl", this.emailUrl)\n .headerExpression("from", "payload.from[0].toString()"))\n .handle(...);\n}\n')])])]),a("h5",{attrs:{id:"header-channel-registry"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#header-channel-registry"}},[e._v("#")]),e._v(" Header Channel Registry")]),e._v(" "),a("p",[e._v("Starting with Spring Integration 3.0, a new sub-element "),a("code",[e._v("")]),e._v(" is available.\nIt has no attributes.\nThis new sub-element converts existing "),a("code",[e._v("replyChannel")]),e._v(" and "),a("code",[e._v("errorChannel")]),e._v(" headers (when they are a "),a("code",[e._v("MessageChannel")]),e._v(") to a "),a("code",[e._v("String")]),e._v(" and stores the channels in a registry for later resolution, when it is time to send a reply or handle an error.\nThis is useful for cases where the headers might be lost — for example, when serializing a message into a message store or when transporting the message over JMS.\nIf the header does not already exist or it is not a "),a("code",[e._v("MessageChannel")]),e._v(", no changes are made.")]),e._v(" "),a("p",[e._v("Using this functionality requires the presence of a "),a("code",[e._v("HeaderChannelRegistry")]),e._v(" bean.\nBy default, the framework creates a "),a("code",[e._v("DefaultHeaderChannelRegistry")]),e._v(" with the default expiry (60 seconds).\nChannels are removed from the registry after this time.\nTo change this behavior, define a bean with an "),a("code",[e._v("id")]),e._v(" of "),a("code",[e._v("integrationHeaderChannelRegistry")]),e._v(" and configure the required default delay by using a constructor argument (in milliseconds).")]),e._v(" "),a("p",[e._v("Since version 4.1, you can set a property called "),a("code",[e._v("removeOnGet")]),e._v(" to "),a("code",[e._v("true")]),e._v(" on the "),a("code",[e._v("")]),e._v(" definition, and the mapping entry is removed immediately on first use.\nThis might be useful in a high-volume environment and when the channel is only used once, rather than waiting for the reaper to remove it.")]),e._v(" "),a("p",[e._v("The "),a("code",[e._v("HeaderChannelRegistry")]),e._v(" has a "),a("code",[e._v("size()")]),e._v(" method to determine the current size of the registry.\nThe "),a("code",[e._v("runReaper()")]),e._v(" method cancels the current scheduled task and runs the reaper immediately.\nThe task is then scheduled to run again based on the current delay.\nThese methods can be invoked directly by getting a reference to the registry, or you can send a message with, for example, the following content to a control bus:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('"@integrationHeaderChannelRegistry.runReaper()"\n')])])]),a("p",[e._v("This sub-element is a convenience, and is the equivalent of specifying the following configuration:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n\n')])])]),a("p",[e._v("Starting with version 4.1, you can now override the registry’s configured reaper delay so that the channel mapping is retained for at least the specified time, regardless of the reaper delay.\nThe following example shows how to do so:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n \n\n\n\n \n\n')])])]),a("p",[e._v("In the first case, the time to live for every header channel mapping will be two minutes.\nIn the second case, the time to live is specified in the message header and uses an Elvis operator to use two minutes if there is no header.")]),e._v(" "),a("h4",{attrs:{id:"payload-enricher"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#payload-enricher"}},[e._v("#")]),e._v(" Payload Enricher")]),e._v(" "),a("p",[e._v("In certain situations, the header enricher, as discussed earlier, may not be sufficient and payloads themselves may have to be enriched with additional information.\nFor example, order messages that enter the Spring Integration messaging system have to look up the order’s customer based on the provided customer number and then enrich the original payload with that information.")]),e._v(" "),a("p",[e._v("Spring Integration 2.1 introduced the payload enricher.\nThe payload enricher defines an endpoint that passes a "),a("code",[e._v("Message")]),e._v(" to the exposed request channel and then expects a reply message.\nThe reply message then becomes the root object for evaluation of expressions to enrich the target payload.")]),e._v(" "),a("p",[e._v("The payload enricher provides full XML namespace support through the "),a("code",[e._v("enricher")]),e._v(" element.\nIn order to send request messages, the payload enricher has a "),a("code",[e._v("request-channel")]),e._v(" attribute that lets you dispatch messages to a request channel.")]),e._v(" "),a("p",[e._v("Basically, by defining the request channel, the payload enricher acts as a gateway, waiting for the message sent to the request channel to return.\nThe enricher then augments the message’s payload with the data provided by the reply message.")]),e._v(" "),a("p",[e._v("When sending messages to the request channel, you also have the option to send only a subset of the original payload by using the "),a("code",[e._v("request-payload-expression")]),e._v(" attribute.")]),e._v(" "),a("p",[e._v("The enriching of payloads is configured through SpEL expressions, providing a maximum degree of flexibility.\nTherefore, you can not only enrich payloads with direct values from the reply channel’s "),a("code",[e._v("Message")]),e._v(", but you can use SpEL expressions to extract a subset from that message or to apply additional inline transformations, letting you further manipulate the data.")]),e._v(" "),a("p",[e._v("If you need only to enrich payloads with static values, you need not provide the "),a("code",[e._v("request-channel")]),e._v(" attribute.")]),e._v(" "),a("table",[a("thead",[a("tr",[a("th"),e._v(" "),a("th",[e._v("Enrichers are a variant of transformers."),a("br"),e._v("In many cases, you could use a payload enricher or a generic transformer implementation to add additional data to your message payloads."),a("br"),e._v("You should familiarize yourself with all transformation-capable components that are provided by Spring Integration and carefully select the implementation that semantically fits your business case best.")])])]),e._v(" "),a("tbody")]),e._v(" "),a("h5",{attrs:{id:"configuration"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#configuration"}},[e._v("#")]),e._v(" Configuration")]),e._v(" "),a("p",[e._v("The following example shows all available configuration options for the payload enricher:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v(' (10)\n (11)\n (12)\n \n (13)\n \n\n')])])]),a("table",[a("thead",[a("tr",[a("th",[a("strong",[e._v("1")])]),e._v(" "),a("th",[e._v("Channel to which a message is sent to get the data to use for enrichment."),a("br"),e._v("Optional.")])])]),e._v(" "),a("tbody",[a("tr",[a("td",[a("strong",[e._v("2")])]),e._v(" "),a("td",[e._v("Lifecycle attribute signaling whether this component should be started during the application context startup."),a("br"),e._v("Defaults to true."),a("br"),e._v("Optional.")])]),e._v(" "),a("tr",[a("td",[a("strong",[e._v("3")])]),e._v(" "),a("td",[e._v("ID of the underlying bean definition, which is either an "),a("code",[e._v("EventDrivenConsumer")]),e._v(" or a "),a("code",[e._v("PollingConsumer")]),e._v("."),a("br"),e._v("Optional.")])]),e._v(" "),a("tr",[a("td",[a("strong",[e._v("4")])]),e._v(" "),a("td",[e._v("Specifies the order for invocation when this endpoint is connected as a subscriber to a channel."),a("br"),e._v("This is particularly relevant when that channel is using a “failover” dispatching strategy."),a("br"),e._v("It has no effect when this endpoint is itself a polling consumer for a channel with a queue."),a("br"),e._v("Optional.")])]),e._v(" "),a("tr",[a("td",[a("strong",[e._v("5")])]),e._v(" "),a("td",[e._v("Identifies the message channel where a message is sent after it is being processed by this endpoint."),a("br"),e._v("Optional.")])]),e._v(" "),a("tr",[a("td",[a("strong",[e._v("6")])]),e._v(" "),a("td",[e._v("By default, the original message’s payload is used as payload that is sent to the "),a("code",[e._v("request-channel")]),e._v("."),a("br"),e._v("By specifying a SpEL expression as the value for the "),a("code",[e._v("request-payload-expression")]),e._v(" attribute, you can use a subset of the original payload, a header value, or any other resolvable SpEL expression as the basis for the payload that is sent to the request-channel."),a("br"),e._v("For the expression evaluation, the full message is available as the 'root object'."),a("br"),e._v("For instance, the following SpEL expressions (among others) are possible: "),a("code",[e._v("payload.something")]),e._v(", "),a("code",[e._v("headers.something")]),e._v(", "),a("code",[e._v("new java.util.Date()")]),e._v(", "),a("code",[e._v("'thing1' + 'thing2'")])])]),e._v(" "),a("tr",[a("td",[a("strong",[e._v("7")])]),e._v(" "),a("td",[e._v("Channel where a reply message is expected."),a("br"),e._v("This is optional."),a("br"),e._v("Typically, the auto-generated temporary reply channel suffices."),a("br"),e._v("Optional.")])]),e._v(" "),a("tr",[a("td",[a("strong",[e._v("8")])]),e._v(" "),a("td",[e._v("The channel to which an "),a("code",[e._v("ErrorMessage")]),e._v(" is sent if an "),a("code",[e._v("Exception")]),e._v(" occurs downstream of the "),a("code",[e._v("request-channel")]),e._v("."),a("br"),e._v("This enables you to return an alternative object to use for enrichment."),a("br"),e._v("If it is not set, an "),a("code",[e._v("Exception")]),e._v(" is thrown to the caller."),a("br"),e._v("Optional.")])]),e._v(" "),a("tr",[a("td",[a("strong",[e._v("9")])]),e._v(" "),a("td",[e._v("Maximum amount of time in milliseconds to wait when sending a message to the channel, if the channel might block."),a("br"),e._v("For example, a queue channel can block until space is available, if its maximum capacity has been reached."),a("br"),e._v("Internally, the send timeout is set on the "),a("code",[e._v("MessagingTemplate")]),e._v(" and ultimately applied when invoking the send operation on the "),a("code",[e._v("MessageChannel")]),e._v("."),a("br"),e._v("By default, the send timeout is set to '-1', which can cause the send operation on the "),a("code",[e._v("MessageChannel")]),e._v(", depending on the implementation, to block indefinitely."),a("br"),e._v("Optional.")])]),e._v(" "),a("tr",[a("td",[a("strong",[e._v("10")])]),e._v(" "),a("td",[e._v("Boolean value indicating whether any payload that implements "),a("code",[e._v("Cloneable")]),e._v(" should be cloned prior to sending the message to the request channel for acquiring the enriching data."),a("br"),e._v("The cloned version would be used as the target payload for the ultimate reply."),a("br"),e._v("The default is "),a("code",[e._v("false")]),e._v("."),a("br"),e._v("Optional.")])]),e._v(" "),a("tr",[a("td",[a("strong",[e._v("11")])]),e._v(" "),a("td",[e._v("Lets you configure a message poller if this endpoint is a polling consumer."),a("br"),e._v("Optional.")])]),e._v(" "),a("tr",[a("td",[a("strong",[e._v("12")])]),e._v(" "),a("td",[e._v("Each "),a("code",[e._v("property")]),e._v(" sub-element provides the name of a property (through the mandatory "),a("code",[e._v("name")]),e._v(" attribute)."),a("br"),e._v("That property should be settable on the target payload instance."),a("br"),e._v("Exactly one of the "),a("code",[e._v("value")]),e._v(" or "),a("code",[e._v("expression")]),e._v(" attributes must be provided as well — the former for a literal value to set and the latter for a SpEL expression to be evaluated."),a("br"),e._v("The root object of the evaluation context is the message that was returned from the flow initiated by this enricher — the input message if there is no request channel or the application context (using the "),a("code",[e._v("@.")]),e._v(" SpEL syntax)."),a("br"),e._v("Starting with version 4.0, when specifying a "),a("code",[e._v("value")]),e._v(" attribute, you can also specify an optional "),a("code",[e._v("type")]),e._v(" attribute."),a("br"),e._v("When the destination is a typed setter method, the framework coerces the value appropriately (as long as a "),a("code",[e._v("PropertyEditor")]),e._v(") exists to handle the conversion."),a("br"),e._v("If, however, the target payload is a "),a("code",[e._v("Map")]),e._v(", the entry is populated with the value without conversion."),a("br"),e._v("The "),a("code",[e._v("type")]),e._v(" attribute lets you, for example, convert a "),a("code",[e._v("String")]),e._v(" containing a number to an "),a("code",[e._v("Integer")]),e._v(" value in the target payload."),a("br"),e._v("Starting with version 4.1, you can also specify an optional "),a("code",[e._v("null-result-expression")]),e._v(" attribute."),a("br"),e._v("When the "),a("code",[e._v("enricher")]),e._v(" returns null, it is evaluated, and the output of the evaluation is returned instead.")])]),e._v(" "),a("tr",[a("td",[a("strong",[e._v("13")])]),e._v(" "),a("td",[e._v("Each "),a("code",[e._v("header")]),e._v(" sub-element provides the name of a message header (through the mandatory "),a("code",[e._v("name")]),e._v(" attribute)."),a("br"),e._v("Exactly one of the "),a("code",[e._v("value")]),e._v(" or "),a("code",[e._v("expression")]),e._v(" attributes must also be provided — the former for a literal value to set and the latter for a SpEL expression to be evaluated."),a("br"),e._v("The root object of the evaluation context is the message that was returned from the flow initiated by this enricher — the input message if there is no request channel or the application context (using the '@.' SpEL syntax)."),a("br"),e._v("Note that, similarly to the "),a("code",[e._v("")]),e._v(", the "),a("code",[e._v("")]),e._v(" element’s "),a("code",[e._v("header")]),e._v(" element has "),a("code",[e._v("type")]),e._v(" and "),a("code",[e._v("overwrite")]),e._v(" attributes."),a("br"),e._v("However, a key difference is that, with the "),a("code",[e._v("")]),e._v(", the "),a("code",[e._v("overwrite")]),e._v(" attribute is "),a("code",[e._v("true")]),e._v(" by default, to be consistent with the "),a("code",[e._v("")]),e._v(" element’s "),a("code",[e._v("")]),e._v(" sub-element."),a("br"),e._v("Starting with version 4.1, you can also specify an optional "),a("code",[e._v("null-result-expression")]),e._v(" attribute."),a("br"),e._v("When the "),a("code",[e._v("enricher")]),e._v(" returns null, it is evaluated, and the output of the evaluation is returned instead.")])])])]),e._v(" "),a("h5",{attrs:{id:"examples"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#examples"}},[e._v("#")]),e._v(" Examples")]),e._v(" "),a("p",[e._v("This section contains several examples of using a payload enricher in various situations.")]),e._v(" "),a("table",[a("thead",[a("tr",[a("th"),e._v(" "),a("th",[e._v("The code samples shown here are part of the Spring Integration Samples project."),a("br"),e._v("See "),a("RouterLink",{attrs:{to:"/en/spring-integration/samples.html#samples"}},[e._v("Spring Integration Samples")]),e._v(".")],1)])]),e._v(" "),a("tbody")]),e._v(" "),a("p",[e._v("In the following example, a "),a("code",[e._v("User")]),e._v(" object is passed as the payload of the "),a("code",[e._v("Message")]),e._v(":")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n \n \n\n')])])]),a("p",[e._v("The "),a("code",[e._v("User")]),e._v(" has several properties, but only the "),a("code",[e._v("username")]),e._v(" is set initially.\nThe enricher’s "),a("code",[e._v("request-channel")]),e._v(" attribute is configured to pass the "),a("code",[e._v("User")]),e._v(" to the "),a("code",[e._v("findUserServiceChannel")]),e._v(".")]),e._v(" "),a("p",[e._v("Through the implicitly set "),a("code",[e._v("reply-channel")]),e._v(", a "),a("code",[e._v("User")]),e._v(" object is returned and, by using the "),a("code",[e._v("property")]),e._v(" sub-element, properties from the reply are extracted and used to enrich the original payload.")]),e._v(" "),a("h5",{attrs:{id:"how-do-i-pass-only-a-subset-of-data-to-the-request-channel"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#how-do-i-pass-only-a-subset-of-data-to-the-request-channel"}},[e._v("#")]),e._v(" How Do I Pass Only a Subset of Data to the Request Channel?")]),e._v(" "),a("p",[e._v("When using a "),a("code",[e._v("request-payload-expression")]),e._v(" attribute, a single property of the payload instead of the full message can be passed on to the request channel.\nIn the following example, the username property is passed on to the request channel:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n \n \n\n')])])]),a("p",[e._v("Keep in mind that, although only the username is passed, the resulting message to the request channel contains the full set of "),a("code",[e._v("MessageHeaders")]),e._v(".")]),e._v(" "),a("h6",{attrs:{id:"how-can-i-enrich-payloads-that-consist-of-collection-data"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#how-can-i-enrich-payloads-that-consist-of-collection-data"}},[e._v("#")]),e._v(" How Can I Enrich Payloads that Consist of Collection Data?")]),e._v(" "),a("p",[e._v("In the following example, instead of a "),a("code",[e._v("User")]),e._v(" object, a "),a("code",[e._v("Map")]),e._v(" is passed in:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n \n\n')])])]),a("p",[e._v("The "),a("code",[e._v("Map")]),e._v(" contains the username under the "),a("code",[e._v("username")]),e._v(" map key.\nOnly the "),a("code",[e._v("username")]),e._v(" is passed on to the request channel.\nThe reply contains a full "),a("code",[e._v("User")]),e._v(" object, which is ultimately added to the "),a("code",[e._v("Map")]),e._v(" under the "),a("code",[e._v("user")]),e._v(" key.")]),e._v(" "),a("h5",{attrs:{id:"how-can-i-enrich-payloads-with-static-information-without-using-a-request-channel"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#how-can-i-enrich-payloads-with-static-information-without-using-a-request-channel"}},[e._v("#")]),e._v(" How Can I Enrich Payloads with Static Information without Using a Request Channel?")]),e._v(" "),a("p",[e._v("The following example does not use a request channel at all but solely enriches the message’s payload with static values:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n \n \n \n \n\n')])])]),a("p",[e._v("Note that the word, 'static', is used loosely here.\nYou can still use SpEL expressions for setting those values.")]),e._v(" "),a("h3",{attrs:{id:"claim-check"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#claim-check"}},[e._v("#")]),e._v(" Claim Check")]),e._v(" "),a("p",[e._v("In earlier sections, we covered several content enricher components that can help you deal with situations where a message is missing a piece of data.\nWe also discussed content filtering, which lets you remove data items from a message.\nHowever, there are times when we want to hide data temporarily.\nFor example, in a distributed system, we may receive a message with a very large payload.\nSome intermittent message processing steps may not need access to this payload and some may only need to access certain headers, so carrying the large message payload through each processing step may cause performance degradation, may produce a security risk, and may make debugging more difficult.")]),e._v(" "),a("p",[e._v("The "),a("a",{attrs:{href:"https://www.enterpriseintegrationpatterns.com/StoreInLibrary.html",target:"_blank",rel:"noopener noreferrer"}},[e._v("store in library"),a("OutboundLink")],1),e._v(" (or claim check) pattern describes a mechanism that lets you store data in a well known place while maintaining only a pointer (a claim check) to where that data is located.\nYou can pass that pointer around as the payload of a new message, thereby letting any component within the message flow get the actual data as soon as it needs it.\nThis approach is very similar to the certified mail process, where you get a claim check in your mailbox and then have to go to the post office to claim your actual package.\nIt is also the same idea as baggage claim after a flight or in a hotel.")]),e._v(" "),a("p",[e._v("Spring Integration provides two types of claim check transformers:")]),e._v(" "),a("ul",[a("li",[a("p",[e._v("Incoming Claim Check Transformer")])]),e._v(" "),a("li",[a("p",[e._v("Outgoing Claim Check Transformer")])])]),e._v(" "),a("p",[e._v("Convenient namespace-based mechanisms are available to configure them.")]),e._v(" "),a("h4",{attrs:{id:"incoming-claim-check-transformer"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#incoming-claim-check-transformer"}},[e._v("#")]),e._v(" Incoming Claim Check Transformer")]),e._v(" "),a("p",[e._v("An incoming claim check transformer transforms an incoming message by storing it in the message store identified by its "),a("code",[e._v("message-store")]),e._v(" attribute.\nThe following example defines an incoming claim check transformer:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n')])])]),a("p",[e._v("In the preceding configuration, the message that is received on the "),a("code",[e._v("input-channel")]),e._v(" is persisted to the message store identified with the "),a("code",[e._v("message-store")]),e._v(" attribute and indexed with a generated ID.\nThat ID is the claim check for that message.\nThe claim check also becomes the payload of the new (transformed) message that is sent to the "),a("code",[e._v("output-channel")]),e._v(".")]),e._v(" "),a("p",[e._v("Now, assume that at some point you do need access to the actual message.\nYou can access the message store manually and get the contents of the message, or you can use the same approach (creating a transformer) except that now you transform the Claim Check to the actual message by using an outgoing claim check transformer.")]),e._v(" "),a("p",[e._v("The following listing provides an overview of all available parameters of an incoming claim check transformer:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v(' (7)\n (8)\n\n')])])]),a("table",[a("thead",[a("tr",[a("th",[a("strong",[e._v("1")])]),e._v(" "),a("th",[e._v("Lifecycle attribute signaling whether this component should be started during application context startup."),a("br"),e._v("It defaults to "),a("code",[e._v("true")]),e._v("."),a("br"),e._v("This attribute is not available inside a "),a("code",[e._v("Chain")]),e._v(" element."),a("br"),e._v("Optional.")])])]),e._v(" "),a("tbody",[a("tr",[a("td",[a("strong",[e._v("2")])]),e._v(" "),a("td",[e._v("ID identifying the underlying bean definition ("),a("code",[e._v("MessageTransformingHandler")]),e._v(")."),a("br"),e._v("This attribute is not available inside a "),a("code",[e._v("Chain")]),e._v(" element."),a("br"),e._v("Optional.")])]),e._v(" "),a("tr",[a("td",[a("strong",[e._v("3")])]),e._v(" "),a("td",[e._v("The receiving message channel of this endpoint."),a("br"),e._v("This attribute is not available inside a "),a("code",[e._v("Chain")]),e._v(" element."),a("br"),e._v("Optional.")])]),e._v(" "),a("tr",[a("td",[a("strong",[e._v("4")])]),e._v(" "),a("td",[e._v("Reference to the "),a("code",[e._v("MessageStore")]),e._v(" to be used by this claim check transformer."),a("br"),e._v("If not specified, the default reference is to a bean named "),a("code",[e._v("messageStore")]),e._v("."),a("br"),e._v("Optional.")])]),e._v(" "),a("tr",[a("td",[a("strong",[e._v("5")])]),e._v(" "),a("td",[e._v("Specifies the order for invocation when this endpoint is connected as a subscriber to a channel."),a("br"),e._v("This is particularly relevant when that channel uses a "),a("code",[e._v("failover")]),e._v(" dispatching strategy."),a("br"),e._v("It has no effect when this endpoint is itself a polling consumer for a channel with a queue."),a("br"),e._v("This attribute is not available inside a "),a("code",[e._v("Chain")]),e._v(" element."),a("br"),e._v("Optional.")])]),e._v(" "),a("tr",[a("td",[a("strong",[e._v("6")])]),e._v(" "),a("td",[e._v("Identifies the message channel where the message is sent after being processed by this endpoint."),a("br"),e._v("This attribute is not available inside a "),a("code",[e._v("Chain")]),e._v(" element."),a("br"),e._v("Optional.")])]),e._v(" "),a("tr",[a("td",[a("strong",[e._v("7")])]),e._v(" "),a("td",[e._v("Specifies the maximum amount of time (in milliseconds) to wait when sending a reply message to the output channel."),a("br"),e._v("Defaults to "),a("code",[e._v("-1")]),e._v(" — blocking indefinitely."),a("br"),e._v("This attribute is not available inside a "),a("code",[e._v("Chain")]),e._v(" element."),a("br"),e._v("Optional.")])]),e._v(" "),a("tr",[a("td",[a("strong",[e._v("8")])]),e._v(" "),a("td",[e._v("Defines a poller."),a("br"),e._v("This element is not available inside a "),a("code",[e._v("Chain")]),e._v(" element."),a("br"),e._v("Optional.")])])])]),e._v(" "),a("h4",{attrs:{id:"outgoing-claim-check-transformer"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#outgoing-claim-check-transformer"}},[e._v("#")]),e._v(" Outgoing Claim Check Transformer")]),e._v(" "),a("p",[e._v("An outgoing claim check transformer lets you transform a message with a claim check payload into a message with the original content as its payload.")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n')])])]),a("p",[e._v("In the preceding configuration, the message received on the "),a("code",[e._v("input-channel")]),e._v(" should have a claim check as its payload.\nThe outgoing claim check transformer transforms it into a message with the original payload by querying the message store for a message identified by the provided claim check.\nIt then sends the newly checked-out message to the "),a("code",[e._v("output-channel")]),e._v(".")]),e._v(" "),a("p",[e._v("The following listing provides an overview of all available parameters of an outgoing claim check transformer:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v(' (8)\n (9)\n\n')])])]),a("table",[a("thead",[a("tr",[a("th",[a("strong",[e._v("1")])]),e._v(" "),a("th",[e._v("Lifecycle attribute signaling whether this component should be started during application context startup."),a("br"),e._v("It defaults to "),a("code",[e._v("true")]),e._v("."),a("br"),e._v("This attribute is not available inside a "),a("code",[e._v("Chain")]),e._v(" element."),a("br"),e._v("Optional.")])])]),e._v(" "),a("tbody",[a("tr",[a("td",[a("strong",[e._v("2")])]),e._v(" "),a("td",[e._v("ID identifying the underlying bean definition ("),a("code",[e._v("MessageTransformingHandler")]),e._v(")."),a("br"),e._v("This attribute is not available inside a "),a("code",[e._v("Chain")]),e._v(" element."),a("br"),e._v("Optional.")])]),e._v(" "),a("tr",[a("td",[a("strong",[e._v("3")])]),e._v(" "),a("td",[e._v("The receiving message channel of this endpoint."),a("br"),e._v("This attribute is not available inside a "),a("code",[e._v("Chain")]),e._v(" element."),a("br"),e._v("Optional.")])]),e._v(" "),a("tr",[a("td",[a("strong",[e._v("4")])]),e._v(" "),a("td",[e._v("Reference to the "),a("code",[e._v("MessageStore")]),e._v(" to be used by this claim check transformer."),a("br"),e._v("If not specified, the default reference is to a bean named "),a("code",[e._v("messageStore")]),e._v("."),a("br"),e._v("Optional.")])]),e._v(" "),a("tr",[a("td",[a("strong",[e._v("5")])]),e._v(" "),a("td",[e._v("Specifies the order for invocation when this endpoint is connected as a subscriber to a channel."),a("br"),e._v("This is particularly relevant when that channel is using a "),a("code",[e._v("failover")]),e._v(" dispatching strategy."),a("br"),e._v("It has no effect when this endpoint is itself a polling consumer for a channel with a queue."),a("br"),e._v("This attribute is not available inside a "),a("code",[e._v("Chain")]),e._v(" element."),a("br"),e._v("Optional.")])]),e._v(" "),a("tr",[a("td",[a("strong",[e._v("6")])]),e._v(" "),a("td",[e._v("Identifies the message channel where the message is sent after being processed by this endpoint."),a("br"),e._v("This attribute is not available inside a "),a("code",[e._v("Chain")]),e._v(" element."),a("br"),e._v("Optional.")])]),e._v(" "),a("tr",[a("td",[a("strong",[e._v("7")])]),e._v(" "),a("td",[e._v("If set to "),a("code",[e._v("true")]),e._v(", the message is removed from the "),a("code",[e._v("MessageStore")]),e._v(" by this transformer."),a("br"),e._v("This setting is useful when Message can be “claimed” only once."),a("br"),e._v("It defaults to "),a("code",[e._v("false")]),e._v("."),a("br"),e._v("Optional.")])]),e._v(" "),a("tr",[a("td",[a("strong",[e._v("8")])]),e._v(" "),a("td",[e._v("Specifies the maximum amount of time (in milliseconds) to wait when sending a reply message to the output channel."),a("br"),e._v("It defaults to "),a("code",[e._v("-1")]),e._v(" — blocking indefinitely."),a("br"),e._v("This attribute is not available inside a "),a("code",[e._v("Chain")]),e._v(" element."),a("br"),e._v("Optional.")])]),e._v(" "),a("tr",[a("td",[a("strong",[e._v("9")])]),e._v(" "),a("td",[e._v("Defines a poller."),a("br"),e._v("This element is not available inside a "),a("code",[e._v("Chain")]),e._v(" element."),a("br"),e._v("Optional.")])])])]),e._v(" "),a("h4",{attrs:{id:"claim-once"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#claim-once"}},[e._v("#")]),e._v(" Claim Once")]),e._v(" "),a("p",[e._v("Sometimes, a particular message must be claimed only once.\nAs an analogy, consider process of handling airplane luggage.\nYou checking in your luggage on departure and claiming it on arrival.\nOnce the luggage has been claimed, it can not be claimed again without first checking it back in.\nTo accommodate such cases, we introduced a "),a("code",[e._v("remove-message")]),e._v(" boolean attribute on the "),a("code",[e._v("claim-check-out")]),e._v(" transformer.\nThis attribute is set to "),a("code",[e._v("false")]),e._v(" by default.\nHowever, if set to "),a("code",[e._v("true")]),e._v(", the claimed message is removed from the "),a("code",[e._v("MessageStore")]),e._v(" so that it cannot be claimed again.")]),e._v(" "),a("p",[e._v("This feature has an impact in terms of storage space, especially in the case of the in-memory "),a("code",[e._v("Map")]),e._v("-based "),a("code",[e._v("SimpleMessageStore")]),e._v(", where failing to remove messages could ultimately lead to an "),a("code",[e._v("OutOfMemoryException")]),e._v(".\nTherefore, if you do not expect multiple claims to be made, we recommend that you set the "),a("code",[e._v("remove-message")]),e._v(" attribute’s value to "),a("code",[e._v("true")]),e._v(".\nThe following example show how to use the "),a("code",[e._v("remove-message")]),e._v(" attribute:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n')])])]),a("h4",{attrs:{id:"a-word-on-message-store"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#a-word-on-message-store"}},[e._v("#")]),e._v(" A Word on Message Store")]),e._v(" "),a("p",[e._v("Although we rarely care about the details of the claim checks (as long as they work), you should know that the current implementation of the actual claim check (the pointer) in Spring Integration uses a UUID to ensure uniqueness.")]),e._v(" "),a("p",[a("code",[e._v("org.springframework.integration.store.MessageStore")]),e._v(" is a strategy interface for storing and retrieving messages.\nSpring Integration provides two convenient implementations of it:")]),e._v(" "),a("ul",[a("li",[a("p",[a("code",[e._v("SimpleMessageStore")]),e._v(": An in-memory, "),a("code",[e._v("Map")]),e._v("-based implementation (the default, good for testing)")])]),e._v(" "),a("li",[a("p",[a("code",[e._v("JdbcMessageStore")]),e._v(": An implementation that uses a relational database over JDBC")])])]),e._v(" "),a("h3",{attrs:{id:"codec"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#codec"}},[e._v("#")]),e._v(" Codec")]),e._v(" "),a("p",[e._v("Version 4.2 of Spring Integration introduced the "),a("code",[e._v("Codec")]),e._v(" abstraction.\nCodecs encode and decode objects to and from "),a("code",[e._v("byte[]")]),e._v(".\nThey offer an alternative to Java serialization.\nOne advantage is that, typically, objects need not implement "),a("code",[e._v("Serializable")]),e._v(".\nWe provide one implementation that uses "),a("a",{attrs:{href:"https://github.com/EsotericSoftware/kryo",target:"_blank",rel:"noopener noreferrer"}},[e._v("Kryo"),a("OutboundLink")],1),e._v(" for serialization, but you can provide your own implementation for use in any of the following components:")]),e._v(" "),a("ul",[a("li",[a("p",[a("code",[e._v("EncodingPayloadTransformer")])])]),e._v(" "),a("li",[a("p",[a("code",[e._v("DecodingTransformer")])])]),e._v(" "),a("li",[a("p",[a("code",[e._v("CodecMessageConverter")])])])]),e._v(" "),a("h4",{attrs:{id:"encodingpayloadtransformer"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#encodingpayloadtransformer"}},[e._v("#")]),e._v(" "),a("code",[e._v("EncodingPayloadTransformer")])]),e._v(" "),a("p",[e._v("This transformer encodes the payload to a "),a("code",[e._v("byte[]")]),e._v(" by using the codec.\nIt does not affect message headers.")]),e._v(" "),a("p",[e._v("See the "),a("a",{attrs:{href:"https://docs.spring.io/spring-integration/api/org/springframework/integration/transformer/EncodingPayloadTransformer.html",target:"_blank",rel:"noopener noreferrer"}},[e._v("Javadoc"),a("OutboundLink")],1),e._v(" for more information.")]),e._v(" "),a("h4",{attrs:{id:"decodingtransformer"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#decodingtransformer"}},[e._v("#")]),e._v(" "),a("code",[e._v("DecodingTransformer")])]),e._v(" "),a("p",[e._v("This transformer decodes a "),a("code",[e._v("byte[]")]),e._v(" by using the codec.\nIt needs to be configured with the "),a("code",[e._v("Class")]),e._v(" to which the object should be decoded (or an expression that resolves to a "),a("code",[e._v("Class")]),e._v(").\nIf the resulting object is a "),a("code",[e._v("Message")]),e._v(", inbound headers are not retained.")]),e._v(" "),a("p",[e._v("See the "),a("a",{attrs:{href:"https://docs.spring.io/spring-integration/api/org/springframework/integration/transformer/DecodingTransformer.html",target:"_blank",rel:"noopener noreferrer"}},[e._v("Javadoc"),a("OutboundLink")],1),e._v(" for more information.")]),e._v(" "),a("h4",{attrs:{id:"codecmessageconverter"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#codecmessageconverter"}},[e._v("#")]),e._v(" "),a("code",[e._v("CodecMessageConverter")])]),e._v(" "),a("p",[e._v("Certain endpoints (such as TCP and Redis) have no concept of message headers.\nThey support the use of a "),a("code",[e._v("MessageConverter")]),e._v(", and the "),a("code",[e._v("CodecMessageConverter")]),e._v(" can be used to convert a message to or from a "),a("code",[e._v("byte[]")]),e._v(" for transmission.")]),e._v(" "),a("p",[e._v("See the "),a("a",{attrs:{href:"https://docs.spring.io/spring-integration/api/org/springframework/integration/codec/CodecMessageConverter.html",target:"_blank",rel:"noopener noreferrer"}},[e._v("Javadoc"),a("OutboundLink")],1),e._v(" for more information.")]),e._v(" "),a("h4",{attrs:{id:"kryo"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#kryo"}},[e._v("#")]),e._v(" Kryo")]),e._v(" "),a("p",[e._v("Currently, this is the only implementation of "),a("code",[e._v("Codec")]),e._v(", and it provides two kinds of "),a("code",[e._v("Codec")]),e._v(":")]),e._v(" "),a("ul",[a("li",[a("p",[a("code",[e._v("PojoCodec")]),e._v(": Used in the transformers")])]),e._v(" "),a("li",[a("p",[a("code",[e._v("MessageCodec")]),e._v(": Used in the "),a("code",[e._v("CodecMessageConverter")])])])]),e._v(" "),a("p",[e._v("The framework provides several custom serializers:")]),e._v(" "),a("ul",[a("li",[a("p",[a("code",[e._v("FileSerializer")])])]),e._v(" "),a("li",[a("p",[a("code",[e._v("MessageHeadersSerializer")])])]),e._v(" "),a("li",[a("p",[a("code",[e._v("MutableMessageHeadersSerializer")])])])]),e._v(" "),a("p",[e._v("The first can be used with the "),a("code",[e._v("PojoCodec")]),e._v(" by initializing it with the "),a("code",[e._v("FileKryoRegistrar")]),e._v(".\nThe second and third are used with the "),a("code",[e._v("MessageCodec")]),e._v(", which is initialized with the "),a("code",[e._v("MessageKryoRegistrar")]),e._v(".")]),e._v(" "),a("h5",{attrs:{id:"customizing-kryo"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#customizing-kryo"}},[e._v("#")]),e._v(" Customizing Kryo")]),e._v(" "),a("p",[e._v("By default, Kryo delegates unknown Java types to its "),a("code",[e._v("FieldSerializer")]),e._v(".\nKryo also registers default serializers for each primitive type, along with "),a("code",[e._v("String")]),e._v(", "),a("code",[e._v("Collection")]),e._v(", and "),a("code",[e._v("Map")]),e._v("."),a("code",[e._v("FieldSerializer")]),e._v(" uses reflection to navigate the object graph.\nA more efficient approach is to implement a custom serializer that is aware of the object’s structure and can directly serialize selected primitive fields.\nThe following example shows such a serializer:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v("public class AddressSerializer extends Serializer
{\n\n @Override\n public void write(Kryo kryo, Output output, Address address) {\n output.writeString(address.getStreet());\n output.writeString(address.getCity());\n output.writeString(address.getCountry());\n }\n\n @Override\n public Address read(Kryo kryo, Input input, Class
type) {\n return new Address(input.readString(), input.readString(), input.readString());\n }\n}\n")])])]),a("p",[e._v("The "),a("code",[e._v("Serializer")]),e._v(" interface exposes "),a("code",[e._v("Kryo")]),e._v(", "),a("code",[e._v("Input")]),e._v(", and "),a("code",[e._v("Output")]),e._v(", which provide complete control over which fields are included and other internal settings, as described in the "),a("a",{attrs:{href:"https://github.com/EsotericSoftware/kryo",target:"_blank",rel:"noopener noreferrer"}},[e._v("Kryo documentation"),a("OutboundLink")],1),e._v(".")]),e._v(" "),a("table",[a("thead",[a("tr",[a("th"),e._v(" "),a("th",[e._v("When registering your custom serializer, you need a registration ID."),a("br"),e._v("The registration IDs are arbitrary."),a("br"),e._v("However, in our case, the IDs must be explicitly defined, because each Kryo instance across the distributed application must use the same IDs."),a("br"),e._v("Kryo recommends small positive integers and reserves a few ids (value < 10)."),a("br"),e._v("Spring Integration currently defaults to using 40, 41, and 42 (for the file and message header serializers mentioned earlier)."),a("br"),e._v("We recommend you start at 60, to allow for expansion in the framework."),a("br"),e._v("You can override these framework defaults by configuring the registrars mentioned earlier.")])])]),e._v(" "),a("tbody")]),e._v(" "),a("h6",{attrs:{id:"using-a-custom-kryo-serializer"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#using-a-custom-kryo-serializer"}},[e._v("#")]),e._v(" Using a Custom Kryo Serializer")]),e._v(" "),a("p",[e._v("If you need custom serialization, see the "),a("a",{attrs:{href:"https://github.com/EsotericSoftware/kryo",target:"_blank",rel:"noopener noreferrer"}},[e._v("Kryo"),a("OutboundLink")],1),e._v(" documentation, because you need to use the native API to do the customization.\nFor an example, see the "),a("a",{attrs:{href:"https://github.com/spring-projects/spring-integration/blob/main/spring-integration-core/src/main/java/org/springframework/integration/codec/kryo/MessageCodec.java",target:"_blank",rel:"noopener noreferrer"}},[a("code",[e._v("MessageCodec")]),a("OutboundLink")],1),e._v(" implementation.")]),e._v(" "),a("h6",{attrs:{id:"implementing-kryoserializable"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#implementing-kryoserializable"}},[e._v("#")]),e._v(" Implementing KryoSerializable")]),e._v(" "),a("p",[e._v("If you have write access to the domain object source code, you can implement "),a("code",[e._v("KryoSerializable")]),e._v(" as described "),a("a",{attrs:{href:"https://github.com/EsotericSoftware/kryo#kryoserializable",target:"_blank",rel:"noopener noreferrer"}},[e._v("here"),a("OutboundLink")],1),e._v(".\nIn this case, the class provides the serialization methods itself and no further configuration is required.\nHowever benchmarks have shown this is not quite as efficient as registering a custom serializer explicitly.\nThe following example shows a custom Kryo serializer:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v("public class Address implements KryoSerializable {\n ...\n\n @Override\n public void write(Kryo kryo, Output output) {\n output.writeString(this.street);\n output.writeString(this.city);\n output.writeString(this.country);\n }\n\n @Override\n public void read(Kryo kryo, Input input) {\n this.street = input.readString();\n this.city = input.readString();\n this.country = input.readString();\n }\n}\n")])])]),a("p",[e._v("You can also use this technique to wrap a serialization library other than Kryo.")]),e._v(" "),a("h6",{attrs:{id:"using-the-defaultserializer-annotation"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#using-the-defaultserializer-annotation"}},[e._v("#")]),e._v(" Using the "),a("code",[e._v("@DefaultSerializer")]),e._v(" Annotation")]),e._v(" "),a("p",[e._v("Kryo also provides a "),a("code",[e._v("@DefaultSerializer")]),e._v(" annotation, as described "),a("a",{attrs:{href:"https://github.com/EsotericSoftware/kryo#default-serializers",target:"_blank",rel:"noopener noreferrer"}},[e._v("here"),a("OutboundLink")],1),e._v(".")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v("@DefaultSerializer(SomeClassSerializer.class)\npublic class SomeClass {\n // ...\n}\n")])])]),a("p",[e._v("If you have write access to the domain object, this may be a simpler way to specify a custom serializer.\nNote that this does not register the class with an ID, which may make the technique unhelpful for certain situations.")])])}),[],!1,null,null,null);t.default=r.exports}}]);