Mule的消息处理配置

 

1.消息传输模式:请求响应、单向
2.过滤器-filter:
        (1) 使用位置:可用于任何位置,比如golobal级别,spring bean级别
        (2) 分类:and、or、not,将多个过滤器结合使用。
        (3) wildcard filter 通配符过滤器.
      通过"."去匹配。如"message.event."匹配"jms.events.customer" and "jms.events.receipts",不匹配"jms.events.queue",多个表达式用,隔开。如"jms.events., jms.actions."
        (4)Expression filter 表达式过滤器
      可以计算一个范围的表达式。它支持一些基本的表达式类型,如header, payload (payload type), regex和wildcard.
        (5)Regex filter 正则表达式过滤器
          正则表达式匹配字符串消息。 使用的是Java正则表达式(java.util.regex.Pattern)。
           (6)Message property filter消息属性过滤器
          与消息的属性相匹配的过滤器。这可以非常有用,因为消息属性代表了所有和底层传输消息有关的元数据信息,比如        http消息的header。该模式应作为一个键/值对,如“属性名=值”来表示。比较多个属性,可以使用AND,OR,和NOT逻辑过滤      器。默认情况下,大小写敏感。
           (7)Payload type filter 有效负载类型的过滤器
               匹配payload的类型。
                      (8)Custom filter 自定义过滤器
                      (9)Encryption security filter 加密安全过滤器
               提供基于口令的加密过滤器。
                      (10)Jxpath filter Jxpath过滤器
               使用JXPath,基于XPath表达式过滤消息。
            (11)Jaxen filter Jaxen的过滤器
                基于XPath表达式路由消息。 一般速度比JXPath过滤器快,应是使用XPath过滤器时的首选。
            (12)Custom filter 自定义过滤器  
   3.路由器   
        (1)all : 发送相同的消息到多个端点。

        所有目标返回的消息(如果有)都聚集在一起,构成从这种处理器的响应消息。

<all>
    <jms:endpoint queue="test.queue" >
    <http:endpoint host="10.192.111.11"/>
    <tcp:endpoint host="10.192.111.12"/>
</all>

        (2)Async: 异步路由 P192
        (3)Choice:选择路由
        (4)Collection Aggregator:集合聚集
        (5)Collection Splitter:集合分离
        (6)Custom Aggregator:自定义分离器
        (7)Custom Processor:自定义处理器
        (8)First Successful:首次成功 .
        遍历其子消息处理器,将接收到的消息顺序发给子处理器,直到消息处理成功。如果不成功,则抛出异常。
        成功的定义:
                如果,子处理器抛出异常,则失败。
                否则,子处理器返回的消息包含异常的有效载荷,也失败。
                      子处理器返回的消息不包含异常的有效载荷,则成功。
                      如果子处理器不返回消息(如单向端点),则成功。
         3.0.1新增

<first-successful failureExpression="exception-type:java.net.SocketTimeoutException">
<http:outbound-endpoint address="http://localhost:6090/weather-forecast" />
   <http:outbound-endpoint address="http://localhost:6091/weather-forecast" />
   <vm:outbound-endpoint path="dead-letter-queue" />

</first-successful>



         3.1.0新增failureExpression属性:可使用mule表达式来定义一个故障,即自定义路由器的行为。


<first-successful failureExpression="exception-type:java.net.SocketTimeoutException">
    <http:outbound-endpoint address="http://localhost:6090/weather-forecast" />
    <http:outbound-endpoint address="http://localhost:6091/weather-forecast" />
    <vm:outbound-endpoint path="dead-letter-queue" />
</first-successful>

          (9)Idempotent Message Filter 幂等消息过滤器
                通过消息ID过滤重复的消息。
                默认存储消息id到本地文件中,也可以通过实现ObjectStore存储消息到数据库中。


<idempotent-message-filter idExpression="#[message:id]">
   <simple-text-file-store directory="D:/idempotent" />
</idempotent-message-filter>


                另外有一子元素,也可将消息ID保存到,内存中。<in-memory-store>.
                如果不配置store,默认使用InMemoryObjectStore。
          (10)Idempotent Secure Hash Message Filter 幂等安全哈希消息过滤器
              通过消息内容过滤重复的消息。
              使用消息摘要算法计算消息本身的哈希值,确保服务收到的消息唯一。是在表示消息的整个字节数组上进行的哈希             计算。不能有任何多余的前后空格。默认使用SHA26算法,也可用其它算法

<idempotent-secure-hash-filter
        messageDigestAlgorithm="SHA26">
        <simple-text-file-store directory="./idempotent" />

</idempotent-secure-hash-filter>


           (11)Message Chunk Aggregator 消息块聚合
                根据消息ID,将分块的消息重新聚合。
           (12)Message Chunk Splitter 消息分割成块
           (13)Message Filter 消息过滤器
           (14)Processor Chain 处理器链
           (15)Recipient List 接收者列表
                将消息发送给符合表达式指定的多个端点。
<recipient-list enableCorrelation="ALWAYS" evaluator="header"
        expression="myRecipients" />

           (16)Resequencer 重新排序
                将收到的消息按照correlation序列属性排序,并将这些消息按正确的序列发布。
                timeout和fileOnTimeout属性决定集合聚集中的所有消息何时接收。
<resequencer timeout="6000" failOnTimeout="false"/>

           (17)WireTap 窃取消息
                将收到的消息路由到一个额外的端点。复制消息到指定端点。

<wire-tap>
        <vm:outbound-endpoint path="tapped.channel" />

</wire-tap>


        4.消息增强

               

                1)源消息系统中提供的是邮政编码,目标系统中需要两个字母的国家。
<flow name="orderProcessingFlow">
        <inbound-endpoint ref="orderEndpoint" />
        <enricher target="#[variable:state]">
                <outbound-endpoint ref="stateLookup" />
        </enricher>
        <outbound-endpoint ref="orderStep2" />
</flow>

        先去一个端点中查找国家,添加到源消息中。再将增强后的消息(包括原来的邮政编码)发送到目的        端点。
        注意:3.1只支持flow的varibles和消息的headers。
            2)也可只选择返回结果中的部分内容进行增强
              
<flow name="orderProcessingFlow">
        <inbound-endpoint ref="orderEndpoint" />
        <enricher target="#[variable:paymentValidated]" source="/authorizenet/authorization/@valid">
                <authorizenet:authorize cardNumber="/order/cc/number" />
        </enricher>
        <outbound-endpoint ref="orderStep2" />
</flow>

                这个只选取返回的身份证明下的合法属性来增强到消息。
             3)可选取多个值
<flow name="orderProcessingFlow">
    <inbound-endpoint ref="orderEndpoint" />
    <enricher>
        <authorizenet:authorize cardNumber="/order/cc/number" />
        <enrich target="#[variable:paymentValidated]" source="/authorizenet/authorization/@valid" />
        <enrich target="#[variable:paymentAuthCode]" source="/authorizenet/authorization/code" />
    </enricher>
    <outbound-endpoint ref="orderStep2" />
</flow>

使用<enrich>时,enricher中不能再使用属性。

               
                
                



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值