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

一 Mule自带的component

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


Mule ESB的component(二)——Component的使用_第1张图片

 

    1. bridge component

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


Mule ESB的component(二)——Component的使用_第2张图片

     定义: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:

Service Bridge
Service component configuration is optional in Mule 2.x. The default and implicit component used is PassThroughComponent . This component
automatically bridges inbound messages to the outbound phase and simply passes messages to the outbound routers. This approach is useful for
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 />:


Mule ESB的component(二)——Component的使用_第3张图片

 

    3. null component

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

package org.mule.component.simple;

import org.mule.api.MuleEventContext;
import org.mule.api.lifecycle.Callable;

/**
 * <code>NullComponent</code> is a service that is used as a placeholder. This
 * implementation will throw an exception if a message is received for it.
 */
public class NullComponent implements Callable
{

    public Object onCall(MuleEventContext context) throws Exception
    {
        throw new UnsupportedOperationException("This service cannot receive messages. Service is: "
                                                + context.getFlowConstruct().getName());
    }

}

 

使用方法


Mule ESB的component(二)——Component的使用_第4张图片

    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两类调用,由于对这两块技术是空白,所以大家自己研究吧= =!

 

你可能感兴趣的:(component)