Apache Camel

Apache Camel ™ is a versatile open-source integration framework based on known Enterprise Integration Patterns.

Apache Camel

连接activemq收发消息

public class TemporaryConsumer {

    public static void main(String[] args) throws Exception {
        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");

        CamelContext context = new DefaultCamelContext();
        context.addComponent("jms", JmsComponent.jmsComponent(connectionFactory));
        context.addRoutes(new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("file:E:\\test").convertBodyTo(String.class).to("jms:queue:firstQueue");
                from("jms:queue:firstQueue").log("${body}").to("file:E:\\test\\destination");
            }
        });

        context.start();
        Thread.sleep(Integer.MAX_VALUE);
    }
}

将一个xml文件放入test文件夹下,发送到firstQueue,再从firstQueue中拿到消息放入destination文件夹下。
终端打印信息

 INFO | Apache Camel 2.16.2 (CamelContext: camel-1) is starting
 INFO | JMX is enabled
 INFO | Loaded 185 type converters
 INFO | Runtime endpoint registry is in extended mode gathering usage statistics of all incoming and outgoing endpoints (cache limit: 1000)
 INFO | AllowUseOriginalMessage is enabled. If access to the original message is not needed, then its recommended to turn this option off as it may improve performance.
 INFO | StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
 INFO | Route: route1 started and consuming from: Endpoint[file://E:%5Ctest]
 INFO | Route: route2 started and consuming from: Endpoint[jms://queue:firstQueue]
 INFO | Total 2 routes, of which 2 is started.
 INFO | Apache Camel 2.16.2 (CamelContext: camel-1) started in 0.571 seconds
 INFO | <note>
<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body>Don't forget the meeting!</body>
</note>

pom.xml

<dependencies>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-all</artifactId>
            <version>5.13.3</version>
        </dependency>

        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
            <version>2.17.3</version>
        </dependency>

    </dependencies>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值