javaapache-camelfile-watcher

Apache Camel File-Watch Without Spring


I am trying to use Apache Camel File-Watch feature.

However I notice all example are used along with Spring.

Is there anyway to make use of this feature without Spring ?

Thank you for any potential input.

Best regards.


Solution

  • Apache Camel is a standalone integration framework to easily integrate different systems using well know and established EIP (Enterprise Integration Patterns).

    It is not tied to Spring in any way at its core and has different deployment / integration models out of which is Spring / Spring Boot for the sake of easing its adoption and configuration for Spring framework users.

    Out of the runtime contexts, you can use for example Camel Main component to run your application having a File Watch component setup to watch the /tmp/ directory change events:

    The main application would look like the following:

    public class FileWatchApplication {
    
        private FileWatchApplication() {
        }
    
        public static void main(String[] args) throws Exception {
            // use Camels Main class
            Main main = new Main(FileWatchApplication.class);
            // now keep the application running until the JVM is terminated (ctrl + c or sigterm)
            main.run(args);
        }
    }
    

    A simple RouteBuilder setting up your File Watch component would look like the following (note that it must be within the same (or child) package of the FileWatchApplication class):

    public class FileWatchRouteBuilder extends RouteBuilder {
    
        @Override
        public void configure() throws Exception {
            // snippet configuration from the official documentation
            from("file-watch:///tmp/")
                    .log("File event: ${header.CamelFileEventType} occurred on file ${header.CamelFileName} at ${header.CamelFileLastModified}");
        }
    }