2015年7月9日星期四

Fuse_004:Fuse 快速上手之四:camel-log

环境:JBoss Fuse 6.2.0

1. 学习重点
(1)如何使用 timer
(2)如何修改 message body

2. camel-log.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'.

      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 id="log-example-context" xmlns="http://camel.apache.org/schema/blueprint" >

        <!--
          A very simple Camel route, that uses a timer to trigger a message every 5 second.

          The <setBody> sets a body into the Camel Message.

          The <log/> elements are used to add human-friendly business logging statements. They make it easier to see what the
          route is doing.
        -->
        <route id="log-route">
          <from uri="timer:foo?period=5s"/>
            <setBody>
                <simple>Hello from Fabric based Camel route!</simple>
            </setBody>
            <log message=">>> ${body} : ${sys.runtime.id}"/>
        </route>
    </camelContext>

</blueprint>

3. 编译、部署、卸载
(1)cd /Users/maping/Redhat/fuse/jboss-fuse-6.2.0.redhat-133/quickstarts/beginner/camel-log
(2)mvn clean install
(3)./fuse
(4)osgi:install -s mvn:org.jboss.quickstarts.fuse/beginner-camel-log/6.2.0.redhat-133
(5)osgi:list
(6)log:tail
(7)osgi:uninstall <id>

4. 编译、部署到 fabric、卸载
(1)fabric:create --wait-for-provisioning
(2)mvn fabric8:deploy
(3)fabric:container-create-child --profile quickstarts-beginner-camel.log root mychild
(4)fabric:container-connect mychild
(5)log:tail
(6)与 child container 断开连接:control + D
(7)fabric:container-stop mychild
(8)fabric:container-delete mychild




没有评论: