ServiceMix(四) bundles之间的简单沟通

本文介绍如何使用Apache Camel将文件操作与ActiveMQ消息队列集成,通过配置Blueprint实现文件移动后触发消息发送,并在另一端接收消息进行日志记录。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

   这篇的基础是上一篇Camel相关的内容,在http://servicemix.apache.org/docs/4.3.0-SNAPSHOT/quickstart/quickstart.pdf这书中,这部分的内容叫做AddingActiveMQ to the'Mix,其实就是在上一篇的基础上,把记录日志的功能拆成两部,在完成文件的转移后,朝activemq的队列中发送一个事件,然后从另一个bundles里接收该事件并写到日志中。
   原来的blueprint.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">
<camelContextxmlns="http://camel.apache.org/schema/blueprint">
<route>
<fromuri="file:activemq/input"/>
<touri="file:activemq/output"/>
<setBody>
<simple>
FileMovedEvent(file: ${file:name}, timestamp:${date:now:hh:MM:ss.SSS})
</simple>
</setBody>
<to uri="activemq://events" />
</route>
</camelContext>
</blueprint>
-----------------------------------------------------------------------------
然后再增加一个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">
<camelContextxmlns="http://camel.apache.org/schema/blueprint">
<route>
<from uri="activemq://events"/>
<to uri="log:events"/>
</route>
</camelContext>
</blueprint>
-----------------------------------------------------------------------------
心得:
   这部分内容比较简单,基本上有点语言基础就能看懂这个过程吧。两个xml的内容是自动部署的,应该很好理解这个过程。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值