Skip to content

Instantly share code, notes, and snippets.

@kunupat
Created April 21, 2021 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kunupat/51ee3f986ab22738dbf427172c968971 to your computer and use it in GitHub Desktop.
Save kunupat/51ee3f986ab22738dbf427172c968971 to your computer and use it in GitHub Desktop.
import java.io.File;
import java.io.FilenameFilter;
import org.apache.camel.builder.RouteBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class FilesAggregatorRoute extends RouteBuilder {
@Autowired
FileAggregationStrategy fileAggregationStrategy;
@Override
public void configure() throws Exception {
String inputFilePath = System.getProperty("user.home") + "/data/out/jsons/";
String outputFilePath = System.getProperty("user.home") + "/data/out/processed/";
File file = new File(inputFilePath);
int numberOfFiles= file.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.endsWith(".json");
}
}).length;
System.out.println(numberOfFiles);
from("direct:start")
.noAutoStartup()
.loop(numberOfFiles)
.pollEnrich("file:" + inputFilePath + "?noop=true",fileAggregationStrategy)
.to("file:" + outputFilePath + "?fileName=customers.json")
.routeId("filesAggregationRoute");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment