Apache ServiceMix学习【使用整合】1

1.     serviceMix 特点:
支持的协议有:
File;FTP;Http/s;jms;smtp;soap;tcp;xmpp
与其他引擎的支持:
Apache Camel;apache cxf;apache ode;drools;os workflow;pojos;quartz;scripting;saxon Xquery and xslt;ws-notification
支持的安全:
JAAS,WS-Security
与web 容器的集成
JBoss,Geronimo,jetty,tomcat,weblogic,websphere
 

2.     与Camel 集成
先查看是否存在camel相关features,没有则按照相应的bundles
接下来我们做一个例子:分别设置两个目录input和output,在input放入文件后则被传送到output中。而这个过程就是通过serviceMix调用camel router来完成
A. Blueprint xml file
下面是一个配置的router文件描述,你可以通过自己写文件,当然最好还是用可视化工具,后面我们再花时间聊聊这东东,这个时候就绕不开Enterprise Integration pattern 又是标准,老外厉害。
 我们这里直接先贴上文件:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint
    xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
 
    <camelContext xmlns="http://camel.apache.org/schema/blueprint">
        <route>
            <from uri="file:bgao/input" />
            <log message="happy day!!!" />
            <to uri="file:bgao/output" />
        </route>
    </camelContext>
</blueprint>
并命名为firstCamelRouter.xml
 
B. 配置到serviceMix
将文件放入到serviceMix的deploy中,这个时候后再serviceMix目录下发现bgao的目录并下面有个input文件夹,这时候如果在input文件夹放入一个文件,这bgao目录下会出现output目录并且将input目录的文件移到output上。通过log:display  可以查看到当前这个动作的日志。
 
通过karaf@root> osgi:list | grep xml
[  43] [Active     ] [GracePeriod ] [       ] [   60] activemq-broker.xml (0.0.0
)
[ 129] [Active     ] [            ] [       ] [   60] Apache ServiceMix :: Bundl
es :: xmlsec (1.4.5.1)
[ 138] [Active     ] [            ] [       ] [   60] Apache ServiceMix :: Bundl
es :: xmlbeans (2.4.0.4)
[ 142] [Active     ] [            ] [       ] [   60] Apache ServiceMix :: Bundl
es :: xmlresolver (1.2.0.3)
[ 163] [Active     ] [Created     ] [       ] [   60] firstCamelRouter.xml (0.0.
0)
得到当前ID为163;通过osgi:stop 163或者  osgi:start 163 来启动或者关闭当前bundle
 
3.     与ActiveMQ集成
先查看是否存在camel相关features, 没有则按照相应的bundles
我们做一个例子:
对两个文件进行文件移动,同时对MQ队列产生一个event 消息并捕获消息打出到日志。
第一个文件:firstMq.xml
<?xml version="1.0" encoding="UTF-8"?>
<blueprint
    xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
 
    <camelContext xmlns="http://camel.apache.org/schema/blueprint">
        <route>
            <from uri="file:bgao/mq/input" />
            <to uri="file:bgao/mq/output" />         
                <setBody>
                <simple>
                File Move Event (${file:name},${date:now:hh:MM:ss.SSS})
                </simple>
                </setBody>
                <to uri="activemq://event" />
        </route>         
    </camelContext>
</blueprint>
这时候,文件已经移到output,现在是event message都在队列里面,但还没有人去处理他,现在通过secondeMq里处理她。
设置第二个文件 secondMq.xml 放入deloy文件夹中
<?xml version="1.0" encoding="UTF-8"?>
<blueprint
    xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
 
    <camelContext xmlns="http://camel.apache.org/schema/blueprint">
        <route>
        <from uri="activemq://event" />
            <from uri="file:bgao/mq/input" />
            <to uri="log:events" />         
        </route>         
    </camelContext>
</blueprint>
启动当前这个bundle 然后打日志就发现有
2012-06-11 16:01:43,751 | INFO  | sConsumer[event] | events
      | ?                                   ? | 91 - org.apache.camel.camel-core
 - 2.8.4 | Exchange[ExchangePattern:InOnly, BodyType:String, Body:
                        File Move Event (address list20120130.xls,04:06:08.272)
                        ]
2012-06-11 16:01:43,751 | INFO  | sConsumer[event] | events
      | ?                                   ? | 91 - org.apache.camel.camel-core
 - 2.8.4 | Exchange[ExchangePattern:InOnly, BodyType:String, Body:
                        File Move Event (jms-1_1-fr-spec.pdf,04:06:08.469)
                        ]
2012-06-11 16:01:43,752 | INFO  | sConsumer[event] | events
      | ?                                   ? | 91 - org.apache.camel.camel-core
 - 2.8.4 | Exchange[ExchangePattern:InOnly, BodyType:String, Body:
                        File Move Event (新建文本文档 (3).txt,04:06:08.765)
 

猜你喜欢

转载自justice-jl.iteye.com/blog/1765532