diff --git a/src/reference/asciidoc/amqp.adoc b/src/reference/asciidoc/amqp.adoc index 0b16329dba..fe7c0f5cb2 100644 --- a/src/reference/asciidoc/amqp.adoc +++ b/src/reference/asciidoc/amqp.adoc @@ -217,7 +217,7 @@ The JMS Inbound Channel Adapter is using a JmsDestinationPollingSource under the The AMQP Inbound Channel Adapter on the other side uses a`SimpleMessageListenerContainer` and is message driven. In that regard it is more similar to the JMS Message Driven Channel Adapter. -==== Configuring with JavaConfig +==== Configuring with Java Configuration The following Spring Boot application provides an example of configuring the inbound adapter using Java configuration: [source, java] @@ -365,7 +365,7 @@ if you anticipate cases when no `replyTo` property exists in the request message See the note in <> about configuring the `listener-container` attribute. -==== Configuring with JavaConfig +==== Configuring with Java Configuration The following Spring Boot application provides an example of configuring the inbound gateway using Java configuration: [source, java] @@ -608,7 +608,7 @@ Using a `return-channel` requires a `RabbitTemplate` with the `mandatory` proper When using multiple outbound endpoints with returns, a separate `RabbitTemplate` is needed for each endpoint. ===== -==== Configuring with JavaConfig +==== Configuring with Java Configuration The following Spring Boot application provides an example of configuring the outbound adapter using Java configuration: [source, java] @@ -816,7 +816,7 @@ When using multiple outbound endpoints with returns, a separate `RabbitTemplate` IMPORTANT: The underlying `AmqpTemplate` has a default `replyTimeout` of 5 seconds. If you require a longer timeout, it must be configured on the `template`. -==== Configuring with JavaConfig +==== Configuring with Java Configuration The following Spring Boot application provides an example of configuring the outbound gateway using Java configuration: [source, java] @@ -941,7 +941,7 @@ There is no "pollable" option for a publish-subscribe-channel; it must be messag Starting with _version 4.1_ AMQP Backed Message Channels, alongside with `channel-transacted`, support `template-channel-transacted` to separate `transactional` configuration for the `AbstractMessageListenerContainer` and for the `RabbitTemplate`. Note, previously, the `channel-transacted` was `true` by default, now it changed to `false` as standard default value for the `AbstractMessageListenerContainer`. -==== Configuring with JavaConfig +==== Configuring with Java Configuration The following provides an example of configuring the channels using Java configuration: diff --git a/src/reference/asciidoc/content-enrichment.adoc b/src/reference/asciidoc/content-enrichment.adoc index 3cda876528..4386fa0000 100644 --- a/src/reference/asciidoc/content-enrichment.adoc +++ b/src/reference/asciidoc/content-enrichment.adoc @@ -110,9 +110,8 @@ as well as point to a Groovy script: *SpEL Support* -In Spring Integration 2.0 we have introduced the convenience of the http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/expressions.html[Spring Expression Language (SpEL)] to help configure many different components. -The _Header - Enricher_ is one of them. +In Spring Integration 2.0 we have introduced the convenience of the http://docs.spring.io/spring/docs/current/spring-framework-reference/html/expressions.html[Spring Expression Language (SpEL)] to help configure many different components. +The _Header Enricher_ is one of them. Looking again at the POJO example above, you can see that the computation logic to determine the header value is actually pretty simple. A natural question would be: "is there a simpler way to accomplish this?". That is where SpEL shows its true power. @@ -128,6 +127,54 @@ As you can see, by using SpEL for such simple cases, we no longer have to provid All we need is the _expression_ attribute configured with a valid SpEL expression. The 'payload' and 'headers' variables are bound to the SpEL Evaluation Context, giving you full access to the incoming Message. +===== Configuring a Header Enricher with Java Configuration + +The following are some examples of Java Configuration for header enrichers: + +[source, java] +---- +@Bean +@Transformer(inputChannel = "enrichHeadersChannel", outputChannel = "emailChannel") +public HeaderEnricher enrichHeaders() { + Map> headersToAdd = + Collections.singletonMap("emailUrl", + new StaticHeaderValueMessageProcessor<>(this.imapUrl)); + HeaderEnricher enricher = new HeaderEnricher(headersToAdd); + return enricher; +} + +@Bean +@Transformer(inputChannel="enrichHeadersChannel", outputChannel="emailChannel") +public HeaderEnricher enrichHeaders() { + Map> headersToAdd = new HashMap<>(); + headersToAdd.put("emailUrl", new StaticHeaderValueMessageProcessor(this.imapUrl)); + Expression expression = new SpelExpressionParser().parseExpression("payload.from[0].toString()"); + headersToAdd.put("from", + new ExpressionEvaluatingHeaderValueMessageProcessor<>(expression, String.class)); + HeaderEnricher enricher = new HeaderEnricher(headersToAdd); + return enricher; +} +---- + +The first adds a single literal header. +The second adds two headers - a literal header and one based on a SpEL expression. + +===== Configuring a Header Enricher with the Java DSL + +The following is an example of Java DSL Configuration for a header enricher: + +[source, java] +---- +@Bean +public IntegrationFlow enrichHeadersInFlow() { + return f -> f + ... + .enrichHeaders(h -> h.header("emailUrl", this.emailUrl) + .headerExpression("from", "payload.from[0].toString()")) + .handle(...); +} +---- + [[header-channel-registry]] ===== Header Channel Registry @@ -263,7 +310,8 @@ For instance the following SpEL expressions (among others) are possible: <7> Channel where a reply Message is expected. -This is optional; typically the auto-generated temporary reply channel is sufficient._Optional_. +This is optional; typically the auto-generated temporary reply channel is sufficient. +_Optional_. <8> Channel to which an `ErrorMessage` will be sent if an `Exception` occurs downstream of the `request-channel`. @@ -275,7 +323,8 @@ _Optional_. <9> Maximum amount of time in milliseconds to wait when sending a message to the channel, if such channel may block. For example, a Queue Channel can block until space is available, if its maximum capacity has been reached. Internally the send timeout is set on the `MessagingTemplate` and ultimately applied when invoking the send operation on the `MessageChannel`. -By default the send timeout is set to '-1', which may cause the send operation on the `MessageChannel`, depending on the implementation, to block indefinitely._Optional_. +By default the send timeout is set to '-1', which may cause the send operation on the `MessageChannel`, depending on the implementation, to block indefinitely. +_Optional_. <10> Boolean value indicating whether any payload that implements `Cloneable` should be cloned prior to sending the Message to the request chanenl for acquiring the enriching data. @@ -284,7 +333,8 @@ Default is `false`. _Optional_. -<11> Allows you to configure a Message Poller if this endpoint is a Polling Consumer._Optional_. +<11> Allows you to configure a Message Poller if this endpoint is a Polling Consumer. +_Optional_. <12> Each `property` sub-element provides the name of a property (via the mandatory `name` attribute). @@ -371,7 +421,7 @@ The reply contains a full `User` object, which is ultimately added to the `Map` _How can I enrich payloads with static information without using a request channel?_ Here is an example that does not use a request channel at all, but solely enriches the message's payload with static values. -But please be aware that the word 'static' is used loosly here. +But please be aware that the word 'static' is used loosely here. You can still use SpEL expressions for setting those values. [source,xml]