<spring:beans>创建spring bean与mule创建的对象一起放在mule的注册信息里。
<spring:beans>
<spring:bean name="globalCache" class="com.mycompany.utils.LRUCache" >
<spring:property name="maxItems" value="200"/>
</spring:bean>
</spring:beans>
<spring:property>mule创建的对象可以spring的属性对象
<custom-processor class="com.mycompany.utils.CustomerClassChecker">
<spring:property name="highPriorities">
<spring:list>
<spring:value>Gold</spring:value>
<spring:value>Platinum</spring:value>
<spring:value>Executive</spring:value>
</spring:list>
</spring:property>
</custom-processor>
mule可以使用spring属性
<spring:beans>
<context:property-placeholder
location="classpath:my-mule-app.properties,
classpath:my-mule-app-override.properties" />
</spring:beans>
<http:endpoint name="ProtectedWebResource"
user="${web.rsc.user}"
password="${web.rsc.password}"
host="${web.rsc.host}"
port="80"
path="path/to/resource" />
Properties file:
web.rsc.user=alice
web.rsc.password=s3cr3t
web.rsc.host=www.acme.com
Connectors
mule具体的传输对象
mule endpoint可以指定connectors这样endpoint与connector分离非常灵活
endpoint只能有一个connector
如果endpoint没指定connector mule将会为其创建connector
<vm:connector name="persistentConnector">
<vm:queueProfile persistent="true" />
</vm:connector>
<file:connector name="fileConnector"
pollingFrequency="1000" moveToDirectory="/tmp/test-data/out" />
Endpoints
mule的一个对象可以读取信息或写入信息,其中的属性定义怎样处理消息
<vm:endpoint name="in" address="vm://in" connector-ref="persistentConnector" />
<http:endpoint name="in" host="localhost" port="8080" path = "services/orders" />
<endpoint name="inFiles" address="file://c:/Orders" />
Transformers
转换当前mule信息
<json:json-to-object-transformer
name="jsonToFruitCollection" returnClass="org.mule.module.json.transformers.FruitCollection">
<json:deserialization-mixin
mixinClass="org.mule.module.json.transformers.OrangeMixin" targetClass="org.mule.tck.testmodels.fruit.Orange"/>
</json:json-to-object-transformer>
<message-properties-transformer name="SetInvocationProperty" scope="invocation">
<add-message-property key="processed" value="yes" />
</message-properties-transformer>
Filters
过滤信息是否被处理
<wildcard-filter pattern="* header received"/>
只有匹配指定的pattern的信息才被处理
<mxml:is-xml-filter/>
只处理xml
<message-filter onUnaccepted="deadLetterQueue"> ❶
<wildcard-filter pattern="* header received"/>
</message-filter>
<message-filter throwOnUnaccepted="true"> ❷
<mxml:is-xml-filter/>
</message-filter>
可以嵌套
<or-filter>
<wildcard-filter pattern="*priority:1*"/>
<and-filter>
<not-filter>
<wildcard-filter pattern="*region:Canada*"/>
</not-filter>
<wildcard-filter pattern="*priority:2*"/>
</and-filter>
</or-filter>
嵌套加入条件
Expressions
mule表达式,可以用来判断或影响mule的行为
<expression-filter evaluator="header" expression="my-header!=null"/>
在值中利用表达式的值#[evaluator:expression]
<message-properties-transformer>
<add-message-property name="GUID" value="#[string:#[xpath:/msg/header/ID]-#[xpath:/msg/body/@ref]]"/>
</message-properties-transformer>
Names and References
用于指定全局对象并且复用
vm:endpoint name="in" address="vm://in" connector-ref="persistentConnector" />
<expression-filter name=checkMyHeader" evaluator="header" expression="my-header!
<message-properties-transformer name="SetInvocationProperty" scope="invocation">
<add-message-property key="processed" value="yes" />
</message-properties-transformer>
<flow name="useReferences">
<vm:inbound-endpoint ref="in"/>
<filter ref="checkSetInvocationPropertyMyHeader"/>
<transformer ref=""/>
</flow>
Flows
最基本的mule处理单元,开始于一个inbound endpoint接着是一系列的处理与可选择的outbound endpoint
<flow name="acceptAndProcessOrder">
<http:inbound-endpoint ref="in"/> ❶
<byte-array-to-string-transformer/> ❷
<jdbc:outbound-endpoint ref="getOrdersById" exchange-pattern="request-response"/> ❸
<mxml:object-to-xml-transformer/> ❹
<expression-filter evaluator="xpath" expression="/status = 'ready'/>❺
<logger level="DEBUG" message="fetched orders: #[payload]"/> ❻
<splitter evaluator="xpath" expression="/order"/> ➐
<enricher> ❽
<authorize:authorization-and-capture amount="#[xpath:/amount]" ❾
cardNumber="#[xpath:/card/number]"
expDate="#[xpath:/card/expire]" />
<enrich target="#[variable:PaymentSuccess]" source="#[bean:responseCode]"/>
</enricher>
<message-properties-transformer scope=:invocation"> ❶❶
<add-message-property key"user-email-address" value="[xpath:/user/email]"/>
</message-properties-transformer>
<component class="org.mycompany.OrderPreProcessor"/> ❶❷
<flow-ref name="processOrder"/> ❶❸
<smtp:outbound-endpoint subject="Your order has been processed" to="#[header:INVOCATION:user-email-address]/> ❶❹
<default-exception-strategy> ❶❺
<processor-chain> ❶❻
<object-to-string-transformer/> ❶➐
<jms:outbound-endpoint ref="order-processing-errors"/> ❶❽
</processor-chain/>
</default-exception-strategy>
</flow>
Routers
Components
mule信息处理者,默认是java实现,可以为其他语言<entry-point-resolver-set>
<method-entry-point-resolver>
<include-entry-point method="preProcessXMLOrder" />
<include-entry-point method="preProcessTextOorder" />
</method-entry-point-resolver>
<reflection-entry-point-resolver/>
</entry-point-resolver-set>
</component>
<component class="org.mycompany.OrderPreProcessor"> ❷
<property-entry-point-resolver property="methodToCall"/>
</component>
<component class="org.mycompany.generateDefaultOrder"> ❸
<no-arguments-entry-point-resolver>
<include-entry-point method="generate"/>
</no-arguments-entry-point-resolver>
</component>
Cloud Connectors
调用云服务Processor Chain
信息处理链Sub-flow
调用其他flow的flowBridge
连接inbound endpoint与outbound endpointtransacted="true"
inboundAddress="jms://myQueue"
outboundAddress="jms://topic:myTopic" />
<pattern:bridge name="transforming-bridge" ❷
inboundAddress="vm://transforming-bridge.in"
transformer-refs="byte-array-to-string"
responseTransformer-refs="string-to-byte-array"
outboundAddress="vm://echo-service.in" />
Simple Service
endpoint-ref="echo-service-channel"
component-class="com.mycompany.EchoComponent" />
<pattern:simple-service name="weather-forecaster-ws" ❷
address="http://localhost:6099/weather-forecast"
component-class="com.myompany.WeatherForecaster"
type="jax-ws" />
Web service proxy
inboundAddress="http://localhost:8090/weather-forecast"
outboundAddress="http://server1:6090/weather-forecast"
wsdlLocation="http://server1:6090/weather-forecast?wsdl" />