mule2.2.x架构(六)示例学习scripting

mule2.2.x架构(六)示例学习scripting

所有的示例文档
http://www.mulesoft.org/display/MULE2INTRO/Examples

本示例参考地址
http://www.mulesoft.org/display/MULE2INTRO/Scripting+Example

6.1 标准输入调用script处理业务打印到标准输出
主要配置文件change-machine.xml。。。。为啥叫这个名字呐。
<description>
JSR-223 script as the service component.
</description>
<context:property-placeholder location="scripting/default-config.properties"/>
<configuration defaultSynchronousEndpoints="true"/>

<stdio:connector name="SystemStreamConnector"
       promptMessage="How much more change do you need? (enter an amount such as 2.37)"
       messageDelayTime="1000"/>
                    
<custom-transformer name="StringToNumber" class="com.sillycat.easymule.scripting.transformer.StringToNumber"/>
<custom-transformer name="DollarsToCents" class="com.sillycat.easymule.scripting.transformer.SimpleMathTransformer">
<spring:property name="operation" value="multiply"/>
      <spring:property name="factor" value="100"/>
</custom-transformer>

<model name="main">
<service name="Accumulator">
            <inbound>
            <!-- 标准输入 -->
                <stdio:inbound-endpoint system="IN"
    transformer-refs="StringToNumber DollarsToCents"/>
                <!-- 队列输入 -->
                <vm:inbound-endpoint path="input" transformer-refs="DollarsToCents"/>
            </inbound>
            <component>
            <!-- 计算处理 -->
                <singleton-object     class="com.sillycat.easymule.scripting.service.AccumulatorComponent"/>
            </component>
            <outbound>
                <chaining-router>
                <!-- 队列输出到queen -->
                    <vm:outbound-endpoint path="script"/>
                    <!-- 标准输出 -->
                    <stdio:outbound-endpoint system="OUT"/>
                </chaining-router>
            </outbound>
        </service>
        <service name="ScriptService">
            <inbound>
            <!-- 队列输入到queen -->
                <vm:inbound-endpoint path="script"/>
            </inbound>
            <script:component>
                <script:script file="${scriptfile}">
                    <property key="currency" value="${currency}"/>
                </script:script>
            </script:component>
        </service>
</model>
其实properties中两种配置都应该可以的,python和groovy的脚本都支持的
#These properties can be passed in via the command line i.e. -Dcurrency=GBP
#scriptfile=scripting/greedy.groovy
#currency=USD
scriptfile=scripting/greedy.py
currency=GBP
当然pom.xml上要将null/lib/user/里面的jar都加上。

另外应当注意这个
<chaining-router>
<!-- 队列输出到queen -->
      <vm:outbound-endpoint path="script"/>
      <!-- 标准输出 -->
      <stdio:outbound-endpoint system="OUT"/>
</chaining-router>
我是这样理解的,chaining-router的时候,是先执行了script,然后脚本返回后,才执行的stdio,输出到了控制台。

你可能感兴趣的:(xml,python,脚本,groovy)