Merge remote-tracking branch 'upstream/master' into 4.0.0-WIP
Conflicts: spring-integration-core/src/main/java/org/springframework/integration/handler/ExpressionEvaluatingMessageHandler.java spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyServiceActivatorTests.java Resolve.
This commit is contained in:
@@ -47,11 +47,11 @@
|
||||
</tip>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<section id="amqp-inbound-channel-adapter">
|
||||
<title>Inbound Channel Adapter</title>
|
||||
|
||||
<para>A configuration sample for an AMQP Inbound Channel Adapter is shown
|
||||
below with all available parameters.</para>
|
||||
below.</para>
|
||||
<programlisting language="xml"><![CDATA[<int-amqp:inbound-channel-adapter id="inboundAmqp"]]><co id="amqp-inbound-channel-adapter-xml-01-co" linkends="amqp-inbound-channel-adapter-xml-01" /><![CDATA[
|
||||
channel="inboundChannel"]]><co id="amqp-inbound-channel-adapter-xml-02-co" linkends="amqp-inbound-channel-adapter-xml-02" /><![CDATA[
|
||||
queue-names="si.test.queue"]]><co id="amqp-inbound-channel-adapter-xml-03-co" linkends="amqp-inbound-channel-adapter-xml-03" /><![CDATA[
|
||||
@@ -165,7 +165,20 @@ this list can also be simple patterns to be matched against the header names (e.
|
||||
core responsibility of this Channel Adapter implementation,
|
||||
the referenced listener container must NOT already have its
|
||||
own MessageListener configured.
|
||||
<emphasis>Optional</emphasis>.</para>
|
||||
<emphasis>Optional</emphasis>.
|
||||
<note>
|
||||
Note that when configuring an external container, you cannot use the <emphasis role="bold">Spring AMQP</emphasis>
|
||||
namespace to define the container. This is because the namespace requires at least one <code><listener/></code>
|
||||
element. In this environment, the listener is internal to the adapter. For this reason, you must define
|
||||
the container using a normal Spring <code><bean/></code> definition, such as:
|
||||
<programlisting language="xml"><![CDATA[
|
||||
<bean id="container"
|
||||
class="org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer">
|
||||
<property name="connectionFactory" ref="connectionFactory" />
|
||||
<property name="queueNames" value="foo.queue" />
|
||||
<property name="defaultRequeueRejected" value="false"/>
|
||||
</bean>]]></programlisting>
|
||||
</note></para>
|
||||
</callout>
|
||||
<callout arearefs="amqp-inbound-channel-adapter-xml-15-co" id="amqp-inbound-channel-adapter-xml-15">
|
||||
<para>The MessageConverter to use when receiving AMQP Messages.
|
||||
@@ -273,7 +286,7 @@ this list can also be simple patterns to be matched against the header names (e.
|
||||
<title>Outbound Channel Adapter</title>
|
||||
|
||||
<para>A configuration sample for an AMQP Outbound Channel Adapter is shown
|
||||
below with all available parameters.</para>
|
||||
below.</para>
|
||||
<programlisting language="xml"><![CDATA[<int-amqp:outbound-channel-adapter id="outboundAmqp"]]><co id="amqp-outbound-channel-adapter-xml-1-co" linkends="amqp-outbound-channel-adapter-xml-1" /><![CDATA[
|
||||
channel="outboundChannel"]]><co id="amqp-outbound-channel-adapter-xml-2-co" linkends="amqp-outbound-channel-adapter-xml-2" /><![CDATA[
|
||||
amqp-template="myAmqpTemplate"]]><co id="amqp-outbound-channel-adapter-xml-3-co" linkends="amqp-outbound-channel-adapter-xml-3" /><![CDATA[
|
||||
@@ -368,7 +381,7 @@ this list can also be simple patterns to be matched against the header names (e.
|
||||
<section>
|
||||
<title>Inbound Gateway</title>
|
||||
<para>A configuration sample for an AMQP Inbound Gateway is shown
|
||||
below with all available parameters.</para>
|
||||
below.</para>
|
||||
<programlisting language="xml"><![CDATA[<int-amqp:inbound-gateway id="inboundGateway"]]><co id="amqp-inbound-gateway-adapter-xml-1-co" linkends="amqp-inbound-gateway-adapter-xml-1" /><![CDATA[
|
||||
request-channel="myRequestChannel"]]><co id="amqp-inbound-gateway-adapter-xml-2-co" linkends="amqp-inbound-gateway-adapter-xml-2" /><![CDATA[
|
||||
queue-names="si.test.queue"]]><co id="amqp-inbound-gateway-adapter-xml-3-co" linkends="amqp-inbound-gateway-adapter-xml-3" /><![CDATA[
|
||||
@@ -415,12 +428,16 @@ this list can also be simple patterns to be matched against the header names (e.
|
||||
</callout>
|
||||
</calloutlist>
|
||||
</para>
|
||||
<para>
|
||||
See the note in <xref linkend="amqp-inbound-channel-adapter"/> about configuring the <code>listener-container</code>
|
||||
attribute.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<title>Outbound Gateway</title>
|
||||
<para>A configuration sample for an AMQP Outbound Gateway is shown
|
||||
below with all available parameters.</para>
|
||||
below.</para>
|
||||
<programlisting language="xml"><![CDATA[<int-amqp:outbound-gateway id="inboundGateway"]]><co id="amqp-outbound-gateway-adapter-xml-1-co" linkends="amqp-outbound-gateway-adapter-xml-1" /><![CDATA[
|
||||
request-channel="myRequestChannel"]]><co id="amqp-outbound-gateway-adapter-xml-2-co" linkends="amqp-outbound-gateway-adapter-xml-2" /><![CDATA[
|
||||
amqp-template=""]]><co id="amqp-outbound-gateway-adapter-xml-3-co" linkends="amqp-outbound-gateway-adapter-xml-3" /><![CDATA[
|
||||
|
||||
@@ -57,6 +57,8 @@
|
||||
|
||||
Setting a custom GroovyObjectCustomizer is not mutually exclusive with <code><variable></code> sub-elements or
|
||||
the <code>script-variable-generator</code> attribute. It can also be provided when defining an inline script.
|
||||
For more information regarding <code><variable></code> and <code>script-variable-generator</code>, see the
|
||||
paragraph '<emphasis>Script variable bindings</emphasis>' of <xref linkend="scripting-config"/>.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
|
||||
@@ -8,26 +8,26 @@
|
||||
<title>Scripting support</title>
|
||||
|
||||
<para>With Spring Integration 2.1 we've added support for the <ulink url="http://jcp.org/aboutJava/communityprocess/pr/jsr223/">
|
||||
JSR223 Scripting for Java specification</ulink>,
|
||||
introduced in Java version 6. This allows you to use scripts written in any supported language including
|
||||
Ruby/JRuby, Javascript and Groovy to provide the logic for various integration components similar to the way
|
||||
the Spring Expression Language (SpEL) is used in Spring Integration. For more information about JSR223 please refer to the
|
||||
JSR223 Scripting for Java specification</ulink>,
|
||||
introduced in Java version 6. This allows you to use scripts written in any supported language including
|
||||
Ruby/JRuby, Javascript and Groovy to provide the logic for various integration components similar to the way
|
||||
the Spring Expression Language (SpEL) is used in Spring Integration. For more information about JSR223 please refer to the
|
||||
<ulink url="http://java.sun.com/developer/technicalArticles/J2SE/Desktop/scripting/">documentation</ulink>
|
||||
<important>
|
||||
Note that this feature requires Java 6 or higher. Sun developed a JSR223 reference implementation which works with
|
||||
Note that this feature requires Java 6 or higher. Sun developed a JSR223 reference implementation which works with
|
||||
Java 5 but it is not officially supported and we have not tested it with Spring Integration.
|
||||
</important>
|
||||
</para>
|
||||
<para>
|
||||
In order to use a JVM scripting language, a JSR223 implementation for that language must be included in your class path. Java 6 natively
|
||||
supports Javascript. The <ulink url="http://groovy.codehaus.org">Groovy</ulink> and
|
||||
supports Javascript. The <ulink url="http://groovy.codehaus.org">Groovy</ulink> and
|
||||
<ulink url="http://jruby.org/">JRuby</ulink> projects provide JSR233 support in their standard distribution.
|
||||
Other language implementations may be available or under development. Please refer to the appropriate project website for more information.
|
||||
<important>
|
||||
Various JSR223 language implementations have been developed by third parties. A particular implementation's compatibility
|
||||
with Spring Integration depends on how well it conforms to the specification and/or the implementer's interpretation of the specification.
|
||||
</important>
|
||||
<tip>If you plan to use Groovy as your scripting language, we recommended you use <xref linkend="groovy">Spring-Integration's Groovy Support</xref>
|
||||
Various JSR223 language implementations have been developed by third parties. A particular implementation's compatibility
|
||||
with Spring Integration depends on how well it conforms to the specification and/or the implementer's interpretation of the specification.
|
||||
</important>
|
||||
<tip>If you plan to use Groovy as your scripting language, we recommended you use <xref linkend="groovy">Spring-Integration's Groovy Support</xref>
|
||||
as it offers additional features specific to Groovy. <emphasis>However you will find this section relevant as well</emphasis>.
|
||||
</tip>
|
||||
</para>
|
||||
@@ -50,28 +50,30 @@
|
||||
</int:filter>
|
||||
|
||||
<int:filter input-channel="inlineScriptInput">
|
||||
<int-script:script lang="groovy"><![CDATA[
|
||||
<int-script:script lang="groovy">
|
||||
<![CDATA[
|
||||
return payload == 'good'
|
||||
]]></int-script:script>
|
||||
]]>
|
||||
</int-script:script>
|
||||
</int:filter></programlisting>
|
||||
|
||||
Here, you see that the script can be included inline
|
||||
or can reference a resource location via the <code>location</code> attribute. Additionally the <code>lang</code> attribute
|
||||
or can reference a resource location via the <code>location</code> attribute. Additionally the <code>lang</code> attribute
|
||||
corresponds to the language name (or JSR223 alias)</para>
|
||||
|
||||
<para>Other Spring Integration endpoint elements which support scripting include <emphasis>router</emphasis>, <emphasis>service-activator</emphasis>,
|
||||
<emphasis>transformer</emphasis>, and <emphasis>splitter</emphasis>. The scripting configuration in each case would be identical to the above
|
||||
<emphasis>transformer</emphasis>, and <emphasis>splitter</emphasis>. The scripting configuration in each case would be identical to the above
|
||||
(besides the endpoint element).
|
||||
</para>
|
||||
|
||||
<para>Another useful feature of Scripting support is the ability to update (reload) scripts without
|
||||
having to restart the Application Context. To accomplish this, specify the <code>refresh-check-delay</code>
|
||||
<para>Another useful feature of Scripting support is the ability to update (reload) scripts without
|
||||
having to restart the Application Context. To accomplish this, specify the <code>refresh-check-delay</code>
|
||||
attribute on the <emphasis>script</emphasis> element:
|
||||
|
||||
<programlisting language="xml"><int-script:script location="..." refresh-check-delay="5000"/></programlisting>
|
||||
|
||||
In the above example, the script location will be checked for updates every 5 seconds. If the script is updated,
|
||||
any invocation that occurs later than 5 seconds since the update will result in execution of the new script.
|
||||
any invocation that occurs later than 5 seconds since the update will result in execution of the new script.
|
||||
|
||||
<programlisting language="xml"><int-script:script location="..." refresh-check-delay="0"/></programlisting>
|
||||
|
||||
@@ -82,12 +84,12 @@
|
||||
This is the default behavior. <important>Inline scripts can not be reloaded.</important></para>
|
||||
|
||||
<programlisting language="xml"><int-script:script location="..." refresh-check-delay="-1"/></programlisting>
|
||||
|
||||
|
||||
<para><emphasis>Script variable bindings</emphasis> </para>
|
||||
|
||||
|
||||
<para>
|
||||
Variable bindings are required to enable the script to reference variables externally provided to the script's execution context.
|
||||
As we have seen, <code>payload</code> and <code>headers</code> are used as binding variables by default. You can bind additional variables
|
||||
Variable bindings are required to enable the script to reference variables externally provided to the script's execution context.
|
||||
As we have seen, <code>payload</code> and <code>headers</code> are used as binding variables by default. You can bind additional variables
|
||||
to a script via <code><variable></code> sub-elements:
|
||||
<programlisting language="xml"><![CDATA[<script:script lang="js" location="foo/bar/MyScript.js">
|
||||
<script:variable name="foo" value="foo"/>
|
||||
@@ -96,29 +98,32 @@
|
||||
</script:script>]]></programlisting>
|
||||
As shown in the above example, you can bind a script variable either to a scalar value or a Spring bean reference. Note that
|
||||
<code>payload</code> and <code>headers</code> will still be included as binding variables.
|
||||
|
||||
|
||||
</para>
|
||||
<para>
|
||||
If you need more control over how variables are generated, you can implement your own Java class
|
||||
If you need more control over how variables are generated, you can implement your own Java class
|
||||
using the <classname>ScriptVariableGenerator</classname> strategy:
|
||||
<programlisting language="java"><![CDATA[public interface ScriptVariableGenerator {
|
||||
|
||||
|
||||
Map<String, Object> generateScriptVariables(Message<?> message);
|
||||
|
||||
|
||||
}]]></programlisting>
|
||||
|
||||
This interface requires you to implement the method <code>generateScriptVariables(Message)</code>. The Message
|
||||
argument allows you to access any data available in the Message payload and headers and the return value is
|
||||
the Map of bound variables. This method will be called every time the script is executed for a Message. All you need to do is
|
||||
the Map of bound variables. This method will be called every time the script is executed for a Message. All you need to do is
|
||||
provide an implementation of <classname>ScriptVariableGenerator</classname> and reference it with the <code>script-variable-generator</code>
|
||||
attribute:
|
||||
<programlisting language="xml"><![CDATA[<int-script:script location="foo/bar/MyScript.groovy"
|
||||
script-variable-generator="variableGenerator"/>
|
||||
|
||||
<bean id="variableGenerator" class="foo.bar.MyScriptVariableGenerator"/>]]></programlisting>
|
||||
|
||||
If a <code>script-variable-generator</code> is not provided, script components use
|
||||
<classname>org.springframework.integration.scripting.DefaultScriptVariableGenerator</classname>, which merges
|
||||
any provided <code><variable></code>s with <emphasis>payload</emphasis> and <emphasis>headers</emphasis>
|
||||
variables from the <code>Message</code> in its <code>generateScriptVariables(Message)</code> method.
|
||||
<important>
|
||||
You cannot provide both the <code>script-variable-generator</code> attribute and <code><variable></code> sub-element(s)
|
||||
You cannot provide both the <code>script-variable-generator</code> attribute and <code><variable></code> sub-element(s)
|
||||
as they are mutually exclusive. Also, custom variable bindings cannot be used with an inline script.
|
||||
</important>
|
||||
</para>
|
||||
|
||||
Reference in New Issue
Block a user