Mule ESB的component(二)——Component的使用

来源:互联网 发布:sql注入攻击检测工具 编辑:程序博客网 时间:2024/04/26 10:52

一 Mule自带的component

打开mule的核心jar包mule-core-3.0.0.jar,可以看到如下结构,期中simple中的component即mule自带的component:


 

    1. bridge component

    mule中的每一个service中都会包含一个bridge component,它被隐式的引用了:


     定义:This is the bridge component. As its name suggests, it bridges its inbound router to its outbound router, but doesn’t perform any particular operation on the message.

    从定义中看,bridge component的作用是将message从inbound传递到outbound中,期间它对message没有任何操作。

 

    在《Mule-ESB-3-User-Guide》中找到一段关于PassThroughComponent的描述,bridge component的默认实现类应该就是PassThroughComponent:

Java代码  收藏代码
  1. Service Bridge  
  2. Service component configuration is optional in Mule 2.x. The default and implicit component used is PassThroughComponent . This component  
  3. automatically bridges inbound messages to the outbound phase and simply passes messages to the outbound routers. This approach is useful for  
  4. bridging endpoints if you want to pass a message from one transport to another.  

 

    2. echo component和log component

    两者都是为了记录信息,从源码中分析,两者的关联是EchoComponent extends LogComponent,前者调用父类的方法进行日志输出。两者的差别是:echo将message的信息全部输出,而log会默认截取前100个长度的信息。

 

    使用方法如下图,log component使用<log-component />替换<echo-component />:


 

    3. null component

    从源码中可以看到,当NullComponent接收到信息时,会抛出一个异常:

Java代码  收藏代码
  1. package org.mule.component.simple;  
  2.   
  3. import org.mule.api.MuleEventContext;  
  4. import org.mule.api.lifecycle.Callable;  
  5.   
  6. /** 
  7.  * <code>NullComponent</code> is a service that is used as a placeholder. This 
  8.  * implementation will throw an exception if a message is received for it. 
  9.  */  
  10. public class NullComponent implements Callable  
  11. {  
  12.   
  13.     public Object onCall(MuleEventContext context) throws Exception  
  14.     {  
  15.         throw new UnsupportedOperationException("This service cannot receive messages. Service is: "  
  16.                                                 + context.getFlowConstruct().getName());  
  17.     }  
  18.   
  19. }  

 

使用方法


    4. StaticComponent

    这个没有找到先关的资料,从api中可以看到该类的描述:

    A service that will return a static data object as a result. This is useful for testing with expected results. The data returned can be read from a file or set as a property on this service.

 

    这个component应该是mule用于测试时设置期望数据的组件。

 

二 远程调用

    mule支持远程调用,它支持RPC和REST两类调用,由于对这两块技术是空白,所以大家自己研究吧= =!

0 0
原创粉丝点击