JMSqueue,queue.
Camel:,queue.(Camel in Action)
1,因为要用JMS,这里介绍一个open source的activeMQ,可以从http://activemq.apache.org/download.html 下载,下载后解压,bin目录有一个activemq.bat文件,在命令行里运行activemq 启动activeMQ,如果能从从浏览器里访问 http://localhost:8161/admin/activeMQ成功启动了.
2,在Camel里实现上图所示的路由:JAVAactiveMQ的jar包配置到classpath下,Java代码如下:
privatestatic
privatestatic
privatestatic
publicstaticvoidthrows
new
new
"jms"
new
publicvoid
"file:d:/temp/inbox"
"jms:queue:TOOL.DEFAULT"
booleantrue
while
25000
Camelbinary messageactiveMQ'TOOL.DEFAULT'queue .
textmessage:from("file:d:/temp/inbox").convertBodyTo(String.class).to("jms:queue:TOOL.DEFAULT");
Camelqueue.
privatestatic
privatestatic
privatestatic
privatestaticboolean
privatestaticint
publicstaticvoidthrows
new
"TOOL.DEFAULT"
1000
ifinstanceof
elseifnull
bytenewbyte[(int
new
}
,上面的路由也可以通过Spring配置实现:
<beanid="jms"class="org.apache.camel.component.jms.JmsComponent">
<propertyname="connectionFactory">
<beanclass="org.apache.activemq.ActiveMQConnectionFactory">
<propertyname="brokerURL"value="failover://tcp://localhost:61616"/>
</bean>
</property>
</bean>
<camelContextxmlns="http://camel.apache.org/schema/spring">
<route>
<fromuri="file:d:/temp/inbox"/>
<touri="jms:queue:TOOL.DEFAULT"/>
</route>
</camelContext>