Mule ESB的component(三)——Java Component

Java Component

    参考Mule的用户开发手册,component分为三类:Simple Components、Java Components、Other Components。《Mule ESB的component(二)》涉及了Simple Components和Other Components(没有详细介绍),这篇将介绍Java Components,也就是我们常说的自定义Components。

1. 示例:

    Java Components主要处理业务逻辑,它通过实现Mule不同的接口,从而提供符合业务逻辑的方法入口,其中org.mule.api.lifecycle.Callable和org.mule.api.component.LifecycleAdapter:

        * org.mule.api.lifecycle.Callable 仅有一个方法onCall(eventContext),顾名思义它是在service被调用时进入该方法;

        * org.mule.api.component.LifecycleAdapter 针对org.mule.api.lifecycle.Lifecycle接口进行了扩充,实现LifecycleAdapter需要实现invoke、isDisposed、isStarted、initialise、start、stop、dispose等方法,这些方法即一个请求的生命周期。

2. entry point
   当你需要特定的请求进入指定的component时,entry point将会帮助你。
   Mule提供的entry point:array-entry-point-resolver、callable-entry-pointresolver、method-entry-pointresolver、no-arguments-entry-pointresolver、property-entry-pointresolver、reflection-entry-pointresolver、custom-entry-pointresolver
   entry point常用子元素:exclude-object-methods、exclude-entry-point、include-entry-point
   
   当Component没有设置entry point时,Mule会使用默认的配置(第三条和第四条没看懂,原文奉上),Mule in action中写到这个配置很复杂,原因是为了兼容Mule 1的版本:
       ■ A property-entry-point-resolver
       ■ A callable-entry-point-resolver
       ■ A reflection-entry-point-resolver configured to accept setter methods(they’re normally excluded)
       ■ A reflection-entry-point-resolver configured to accept setter methods and with transformation first disabled

    entry point的具体使用不在此处介绍,首先是因为api文档比我的英文水平好多了,其次是一段话:
    At this point, you might feel overwhelmed by the versatility of the entry point resolution
mechanism. The best hint we can give you at this point is not to overengineer your
configuration with armies of finely tuned entry point resolvers. Rely first on the default
set that Mule uses and add specific resolvers only if it’s not able to satisfy your needs.
    这段内容大概意思是,读者可能会对大量的entry point感到不知所措,作者给出的最好建议是: 先使用默认的配置,除非它不满足你的需要

3. 配置component
    Mule支持spring和mule的两种方式配置:
使用Mule配置:



spring配置 :


 
4. 使用池进行负载
    以下两种情况可以使用池:
      * 创建组件会消耗大量的资源
      * 组件是非线程安全的
    
    池属性配置:
    name                    |type                                       | required | default
    manxActive           |String                                     | no          |
    maxIdle                |String                                     | no          | 
    initialisationPolicy |NITIALISE_NONE                    | no          | INITIALISE_ONE
                                  INITIALISE_ONE
                                  INITIALISE_ALL
    exhaustedAction    |WHEN_EXHAUSTED_GROW   | no         | WHEN_EXHAUSTED
                                   WHEN_EXHAUSTED_WAIT
                                   WHEN_EXHAUSTED_FAIL 
    maxWait               |String                                      | no       | 

5. component的扩展
    component binding可以将一个接口(interface)的代理注入到component,从而实现component与Mule API的解耦。


 
6. component交互总图


猜你喜欢

转载自winnie825.iteye.com/blog/1740457