`
longgangbai
  • 浏览: 7250770 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Mule ESB 学习笔记(6)配置模式

阅读更多

         为了节省时间,就不翻译了,摘抄重点总结下, 本文大部分摘抄自Mule ESB官网入门教程 Guide.pdf这本书中.

常用的配置定式简介

            Simple Service  : Exposes JAX-WS annotated components as SOAP web services. Exposes JAX-RS annotated beans as RESTful components.Can also handle JAXB, XML and raw content with simple POJO components.

            WebService Proxy : Proxies remote web services. Can perform transformations on the SOAP envelope. Can rewrite or redirect remote WSDLs to localones.

            Bridge : Establishes a direct conduit between an inbound endpoint and an outbound endpoint. Supports request-response and one-way bridging. Can perform transformations. Supports transactional bridging of inbound to outbound.

            Validator : Validates inbound messages against a defined acceptance filter. Returns an ACK or NACK response synchronously and dispatches valid messages asynchronously.

下面只总结 simple service webservice proxy 两种常用的配置定式的常用配置

   Simple service : 把组件发布成简单的mule service ,包括webservice

 

 

6. 配置模式

Mule 3.0版本提供了“pattern”的机制。Pattern总结了实际使用过程中的常见场景,以简化的服务配置方式提供。

6.1 简单服务模式simple service pattern

简单服务模式用于简化同步服务调用的配置,对应消息传递方式中的请求-响应方式。

图 简单服务模式

简单服务模式通过simple-service 元素配置,主要的元素属性包括:

属性 说明
address 服务监听的地址,如vm:in
component-class Component的实现类
type

direct: 默认;

jax-ws: component暴露为soap式的web servicecomponent必须基于jax-ws的注解),address一般为Http Transport;

jax-rs: component暴露为rest式的web servicecomponent必须基于@Path的注解),address一般为HttpServlet Transport

代码示例:

<simple-service name="simple-service" address="vm://simple.in"  
    component-class="demo.mule.umo.Echo" />

Mule针对服务请求接入可以做额外的处理,比如增加Transformer配置进行数据转换。

6.2 桥接模式bridge pattern

桥接模式用于在inbound endpointoutbound endpoint之间建立直接连接,不需要component提供业务逻辑。

图 桥接模式

桥接模式通过bridge元素配置,主要属性包括:

属性 说明
inboundAddress 服务请求接入地址
outboundAddress 服务接出的实际地址
exchange-pattern

request-response: 默认,返回处理结果;

one-way: 单向

transacted

true: 在向outbound endpoint分发时使用事务;

false: 不使用事务

代码示例:

 

<bridge name="queue-to-topic" transacted="true" inboundAddress="jms://myQueue"  
        outboundAddress="jms://topic:myTopic" />

 

Mule在接入、接出的过程中可以做额外的处理,比如增加Transformer配置进行数据转换。如果使用事务控制,对于异构的协议之间的事务需要有支持XA的事务控制器。

6.3 校验器模式validator pattern

校验器模式通过定义一个校验过滤器过滤服务请求,并同步返回ACKACKnowledge)或NACKNot Acknowledge)结果。通过校验的服务请求被异步分发给处理方。

图 校验器模式

校验器模式通过validator元素配置,主要属性包括:

属性 说明
inboundAddress 服务请求接入地址
outboundAddress 服务接出地址
ackExpression 表达式,用于构建服务请求被接收时的信息
nackExpression 表达式,用于构建服务请求被拒绝时的信息
errorExpression

@since 3.0.1

表达式,用于构建在服务请求分发出错时的信息
validationFilter-ref

过滤器的引用,也可以使用子元素指定

用于确定服务请求是否被接收

代码示例:

 

<validator name="integer-validator" inboundAddress="vm://validator.in"  
        ackExpression="#[string:GOOD:#[message:payload]@#[context:serviceName]]"  
        nackExpression="#[string:BAD:#[message:payload]@#[context:serviceName]]"  
        outboundAddress="vm://test-service.in">  
    <payload-type-filter expectedType="java.lang.Integer" />  
</validator>

注:Mule的表达式后续补充。

6.4 web服务代理模式web service proxy pattern

Web服务代理模式用于将Web Service请求直接转发至远程目标Web Service服务端,Mule本身不提供实际的Web Service

图 web服务代理模式

Web服务代理模式通过ws-proxy元素配置,主要属性包括:

属性 说明
inboundAddress Mule对外提供的地址
outboundAddress Web Service的实际地址

代码示例:

 

<ws:proxy name="ws-proxy"  
        inboundAddress="http://localhost:7006/services/Echo"  
        outboundAddress="http://localhost:8000/services/Echo?method=echo">  
</ws:proxy>

 

Mule在转发的过程中可以做额外的处理,比如增加Transformer配置进行数据转换。

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics