Apache Camel의 Live Reload를 사용해 봤습니다.

5912 단어 apache-camel
Live Reload 기능은
Apache Camel을 정의하는 route의 XML 파일이 변경되면 route를 자동으로 다시 로드하는 기능이 있습니다.
2017년 5월에 발매된 v2를 찾아봤어요.19.0 이상.
나는 전혀 눈치채지 못했다.지금까지의 고생은 도대체
다음은 발매노트.
에서 발췌 Apache Camel 2.19 release notes
Introduced ReloadStrategy as SPI which allows custom providers to implement logic for triggering live reloads of Camel routes.
The Camel Maven Plugin now allows to live reload route changes from XML files when running Camel. This can also be enabled from the Main class.
XML DSL만 지원되며 Java DSL은 지원되지 않습니다.Java DSL의 경우 Spring Boot DevTools를 사용하면 됩니다(시도되지 않음).
Live Reload를 사용해 봤습니다.
1초마다 출력 로그의 샘플 응용을 LiveReload로 테스트해 보십시오.
다음은 애니메이션gif의 제작입니다.
(ScreenToGif를 사용했습니다. 직관적이며 사용법도 편리합니다.)

위gif에서 최초로 출력된 로그 저장 파일을 변경하면route가 다시 불러옵니다.
그런 다음 실행 간격을 1초에서 5초로 변경합니다.
이용 방법
주요 항목.
다음 코드를 추가하여 파일 수정을 시작하는 디렉터리를 감시합니다.
main.setFileWatchDirectory("src/main/resources/META-INF/spring");
주 프로그램은 전체적으로 다음과 같다.
TestMain.java
package sample;

import org.apache.camel.spring.Main;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TestMain {

    Logger logger = LoggerFactory.getLogger("sample.TestMain");

    public static void main(String[] args) throws Exception {
        Main main = new Main();
        main.setApplicationContextUri("META-INF/spring/camel-context.xml");
        main.setFileWatchDirectory("src/main/resources/META-INF/spring");
        main.run();
    }
}
다음은 카멜-context.xml로route를 정의합니다.
1초마다 로그에'test'의 단순한route를 출력합니다.
camel-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:camel="http://camel.apache.org/schema/spring"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans.xsd
          http://camel.apache.org/schema/spring
          http://camel.apache.org/schema/spring/camel-spring.xsd">

    <camelContext
        xmlns="http://camel.apache.org/schema/spring">

        <route id="mainRoute">
            <from uri="timer://run?delay=1000&amp;period=1000" />
            <log message="test" />
        </route>
    </camelContext>
</beans>
그리고 응용 프로그램,camel-context를 실행합니다.저장된 xml을 수정하면 애니메이션gif에서 최초로 소개한 LiveReload를 시도할 수 있습니다.
최후
지금까지route를 다시 쓸 때마다 프로그램을 다시 시작하기 때문에 번거롭지만, 드디어 환경이 갖추어졌다.(더 일찍 알았더라면!)
하지만 Java DSL로 route를 쓰면 사용할 수 없습니다.
요즘은 XML에 낙서를 하는 것이 유행하지 않기 때문에 아무도 사용하지 않을 것이다.
이번에 캠el 스탠드에서 라이브 리로드 기능을 시도했고, 캠el Maven Plugin, 스프링 부트도 이용할 수 있다.
참고 자료
공식 웹 사이트 - Camel Example Reload
https://github.com/apache/camel/tree/master/examples/camel-example-reload
Camel Live Reload of XML routes by JBoss Developer
http://planet.jboss.org/post/camel_live_reload_of_xml_routes

좋은 웹페이지 즐겨찾기