一、MEL语法
#[表达式]
例:
#[server.dateTime] 取服务器时间
#[1 + 1] 取计算结果
#[1 + 1 == 2] 取判断结果
#[message.inboundProperties['http.query.params']['uId']] //获取HTTP请求中参数名为'uId'的值
#[message.inboundProperties.city] //取XML配置中ID为'city'的值
#[message.inboundProperties['city']] //同上
#[xpath('/user/username').text] //取xpath下的XML文件中user节点下的子节点username值
二、Message结构
The Mule message is the data that passes through an application via one or more flows. It consists of two main parts:
-
The message header, which contains metadata about the message //主要用来存放源数据类似报文头里存放编码信息等
-
The message payload, which contains your business-specific data. //Payload主要用于存放业务数据,相当于报文的报文体部分
A Mule message is, itself, embedded within a Mule message object.
Some Mule message objects may contain variables, attachments, and exception payloads.
However, as attachments and exception payloads are not frequently used or manipulated, this overview document does not include details about them.
关于Mule Message的结构参见:Mule Message 快戳!
1.Message中的Properties
Properties主要分为Inbound properties (输入)和 Outbound properties (输出)
Inbound properties are immutable, are automatically generated by the message source and cannot be set or manipulated by the user.
They contain metadata specific to the message source that prevents scrambling of data formats or other processing mishaps later in the message’s lifecycle.
A message retains its inbound properties only for the duration of the flow; when a message passes out of a flow, its inbound properties do not follow it (see image below).
Inbound properties在Flow A中携带信息进入到消息处理器,当进入Flow B中时信息会丢失。MEL写法#[messsage.inboundProperties]
Outbound properties are mutable;
they are set during the course of a flow and can become inbound properties when the message passes from the outbound endpoint of one flow to the inbound endpoint of a different flow via a transport.
They contain metadata similar to that of an inbound property, but an outbound property is applied after the message enters the flow.
Outbound properties can be set automatically by Mule or a user can set them by manually inserting one or more transformer elements in the flow.
Note that if the message is passed to a new flow via a flow-ref rather than a connector, the outbound properties remain outbound properties rather than being converted to inbound properties (see image below).
Flow A中信息处理器把欲传递到Flow B的信息写入到Outbound properties中,作为Flow B的Inbound properties完成信息传递。MEL写法#[messsage.outboundProperties]
2.Message中的Variables
Variables are user-defined metadata about a message. Variables have three scopes:
-
Flow variables apply only to the flow in which they exist. //只在同一个Flow中使用, MEL写法#[sessionVars]
-
Session variables apply across all flows within the same application. //在同一个application中使用, MEL写法#[flowVars]
-
Record variables apply only to records processed as part of a batch. //只能在batch中使用
Variables are temporary pieces of information about a message that are meant to be used by the application that is processing it, rather than passed along with the message to its destination.
Thus, variables are more likely to be set by humans, whereas properties are more likely to be set and invoked by systems.
However, there are no strict rules about how properties and variables should be used.
三、MuleESB内置四大对象
1.server对象: #[server.dataTime]
2.mule对象: #[mule.version]
3.app对象: #[app.name]
4.message对象: #[message.payload]
四大对象详情: MuleESB四大对象
注:对象属性的有些是只读的其余是可读写的。