ServiceMix - [Quickstart]4.添加ActiveMQ

Adding ActiveMQ to the 'Mix

开箱即用,每一个Apache ServiceMix Instance(实例)会带一个嵌入的ActiveMQ JMS broker(代理)。它使得在同一机器上的Camel route之间使用持久化的消息进行通信变得简单。它也可以让你跨Instance(实例)路由,用来实现clustering(集群)和load-balancing(负载均衡)。

Our scenario

本方案中,我们也会在两个文件夹之间移动文件。但不会直接记录日志,我们打算发送一个event JMS message(JMS消息事件)到队列中。之后我们会创建第二个Camel route来获得event(事件)并将它写入日志。

Moving files and sending event messages

修改在上一个主题中我们已经创建的XML。在第一个Blueprint XML中包含了一个可以移动文件的Camel route。在这之后我们添加一部分新的内容,让它可以产生event messages(消息事件)并把它发送到可以调用这些event(事件的)ActiveMQ queue(队列中)。

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <camelContext xmlns="http://camel.apache.org/schema/blueprint">
      <route>
        <from uri="file:camel/input"/>
        <!--<log message="Moving ${file:name} to the output directory"/>-->
        <to uri="file:camel/output"/>
		<setBody>
			<simple>FileMovedEvent(file:${file:name},timestamp:${date:now:hh:MM:ss.SSS})</simple>
		</setBody>
		<to uri="activemq://events"/>
      </route>
    </camelContext>
</blueprint>

如何使用shell console来观察被部署bundle的状态,相信读了上一个主题你应该已经掌握。 

Receiving the event messages

上面的XML被部署之后,你已经注意到没有任何任何事件被记录在日志中。event message已经被发送到ActiveMQ queue,但是还没有人去收这些事件。让我们继续在创建第二个Blueprint XML。我把它命名为sample2.xml。

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <camelContext xmlns="http://camel.apache.org/schema/blueprint">
      <route>
        <from uri="activemq://events"/>
        <to uri="log:events"/>
      </route>
    </camelContext>
</blueprint>

这个文件一被部署,马上你在日中就会见到刚才拷贝文件的消息。


11:09文件被拷贝,11:53才写入日志,两个过程是异步的。

Using the shell to manage the routes

你可以通过命令来启动或者停止这两个routes。重要的是你可以在文件被处理过程中停止event handler route(事件处理路由),而后当你重新启动,马上就得到那些被处理文件的消息。它实现了两个过程异步进行,这个具有现实意义。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值