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>
發佈了119 篇原創文章 · 獲贊 78 · 訪問量 20萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章