2015年7月9日星期四

Fuse_001:入门级例子之一:camel-cbr

环境:JBoss Fuse 6.2.0

1. 学习重点
(1) Content Based Router EIP。

2. cbr.xml
(1)设计图

(2)源码
<?xml version="1.0"?>
<!--
    JBoss, Home of Professional Open Source
    Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual
    contributors by the @authors tag. See the copyright.txt in the
    distribution for a full listing of individual contributors.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->
<!--
   This is the OSGi Blueprint XML file defining the Camel context and routes.  Because the file is in the
   OSGI-INF/blueprint directory inside our JAR, it will be automatically activated as soon as the bundle is installed.

   The root element for any OSGi Blueprint file is 'blueprint' - you also see the namespace definitions for both the Blueprint
   and the Camel namespaces.
-->
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/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
             http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">

    <!--
      The namespace for the camelContext element in Blueprint is 'http://camel.apache.org/schema/blueprint'. Additionally,
      we can also define namespace prefixes we want to use them in the XPath expressions in our CBR.

      While it is not required to assign id's to the <camelContext/> and <route/> elements, it is a good idea
      to set those for runtime management purposes (logging, JMX MBeans, ...)
    -->
    <camelContext xmlns="http://camel.apache.org/schema/blueprint" xmlns:order="http://fabric8.com/examples/order/v7"
        id="cbr-example-context">

        <!--
          When this route is started, it will automatically create the work/cbr/input directory where you can drop the
          file that need to be processed.

          The <log/> elements are used to add human-friendly business logging statements. They make it easier to see what the
          route is doing.

          The <choice/> element contains the content based router. The two <when/> clauses use XPath to define the criteria
          for entering that part of the route. When the country in the XML message is set to UK or US, the file will be
          moved to a directory for that country. The <otherwise/> element ensures that any file that does not meet the
          requirements for either of the <when/> elements will be moved to the work/cbr/output/others directory.
        -->
        <route id="cbr-route">
            <from uri="file:work/cbr/input" />
            <log message="Receiving order ${file:name}" />
            <choice>
                <when>
                    <xpath>/order:order/order:customer/order:country = 'UK'</xpath>
                    <log message="Sending order ${file:name} to the UK" />
                    <to uri="file:work/cbr/output/uk" />
                </when>
                <when>
                    <xpath>/order:order/order:customer/order:country = 'US'</xpath>
                    <log message="Sending order ${file:name} to the US" />
                    <to uri="file:work/cbr/output/us" />
                </when>
                <otherwise>
                    <log message="Sending order ${file:name} to another country" />
                    <to uri="file:work/cbr/output/others" />
                </otherwise>
            </choice>
            <log message="Done processing ${file:name}" />
        </route>
    </camelContext>

</blueprint>

3. 编译、部署、卸载
(1)cd /Users/maping/Redhat/fuse/jboss-fuse-6.2.0.redhat-133/quickstarts/beginner/camel-cbr
(2)mvn clean install
(4)./fuse
(5)osgi:install -s mvn:org.jboss.quickstarts.fuse/beginner-camel-cbr/6.2.0.redhat-133
(6)osgi:list
(7)cp /Users/maping/Redhat/fuse/jboss-fuse-6.2.0.redhat-133/quickstarts/beginner/camel-cbr/src/main/fabric8/data/* /Users/maping/Redhat/fuse/jboss-fuse-6.2.0.redhat-133/work/cbr/input
(8)cd /Users/maping/Redhat/fuse/jboss-fuse-6.2.0.redhat-133/work/cbr/output
(9)osgi:uninstall <id>

没有评论: