Apache Camel

https://camel.apache.org/

  • set in application.properties file :

    camel.springboot.main-run-controller = true

File Operation in Apache Camel

@Override
    public void configure() throws Exception {
        log.info("---- starting ----");
        moveAllFile();
        //moveSpecificFile("file");
        //moveSpecificFileWithContent("hello");
        //processFile();
        //multiFileProcessor();
        log.info("---- end ----");
    }

    public void moveAllFile() {
        from("file:/home/uday/a").log("--- moved ---")
                .to("file:/home/uday/b");
    }

    public void moveSpecificFile(String fileName) {
        from("file:/home/uday/a")
                .filter(header(Exchange.FILE_NAME).startsWith(fileName))
                .to("file:/home/uday/b");
    }

    public void moveSpecificFileWithContent(String content) {
        from("file:/home/uday/a")
                .filter(body().startsWith(content))
                .to("file:/home/uday/b");
    }

    public void processFile() {
        from("file:/home/uday/a")
                .process(p -> {
                    String body = p.getIn().getBody(String.class);
                    StringBuilder sb = new StringBuilder();
                    Arrays.stream(body.split(" "))
                        .forEach(s -> sb.append(s).append(","));
                    p.getIn().setBody(sb);
                }).to("file:/home/uday/b");
    }

    public void multiFileProcessor() {
        from("file:/home/uday/a/").unmarshal().csv().split(body()
        .tokenize(",")).choice()
                .when(body().contains("closed"))
                    .to("file:/home/uday/b?fileName=closed.csv")
                .when(body().contains("pending"))
                    .to("file:/home/uday/b?fileName=pending.csv")
                .when(body().contains("waiting"))
                    .to("file:/home/uday/b?fileName=waiting.csv");
    }

More file operation

Multicast

Spilt

Aggregation

Routing Slip

Error Handling

Active MQ

Kafka

Using Time

Rest API

Last updated

Was this helpful?