Search code examples
javaapache-camel

Apache Camel reading file from aws S3


I am trying to read a csv file from AWS S3 and print on console, but it is not working.

public class Example {

  public static void main(String[] args) throws Exception {
    var camelContext = new DefaultCamelContext();

    camelContext.addRoutes(new MainRoute());
    camelContext.start();
    Thread.sleep(10_000);
    camelContext.stop();
  }
}


public class MainRoute extends RouteBuilder {

  @Override
  public void configure() {
    var s3Url = String.format(
        "aws2-s3://mybucket.com?"
            + "prefix=etl/hello.csv&useDefaultCredentialsProvider=true&deleteAfterRead=false&maxMessagesPerPoll=1");

    System.out.println("start route");
    from(s3Url).marshal().csv().log("log message").end();

    System.out.println("finish route");
  }
}

I tried using marshal().csv()

I tried using only: from(s3Url).log("log message").end();

Only "start route" and "finish route" is printed, "log message" is never printed.

Versions:

Apache camel: 3.19.0, Java:17

CSV content:

Name,age
myName,31

What should I do in order to read the csv content and print in console?


Solution

  • I found the the cause.

    I had to put log libraries on the classpath in order to work to log, the default java logging was not enough to work, I do not know why.

    I put this in my pom file:

    <!-- logging -->
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-api</artifactId>
      <version>${log4j2.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-core</artifactId>
      <version>${log4j2.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-slf4j-impl</artifactId>
      <version>${log4j2.version}</version>
    </dependency>