Polling from file using Java DSL - compile error when adding Files.inboundAdapter

青春壹個敷衍的年華 提交于 2019-12-31 06:00:43

问题


I am using Spring Integration Java DSL v. 1.2.2 and following some examples I try to write a code to poll a folder

    return IntegrationFlows
            .from(Files.inboundAdapter(new File("/tmp/foo")))
            .handle((p, h) -> fileProcessor.process(p))
            .get();

This code can not be compiled because

"Cannot resolve method 'from(org.springframework.integration.dsl.
   file.FileInboundChannelAdapterSpec)'"

How this can be fixed and how fixed-interval polling can be added?


回答1:


Not clear what's going on in your IDE, but we have this sample in test-cases:

@Bean
public IntegrationFlow fileToFile() {
    return IntegrationFlows.from(Files.inboundAdapter(new File("/tmp/in"))
                    .autoCreateDirectory(true)
                    .patternFilter("*.txt"),
            e -> e.poller(Pollers.fixedDelay(5000)))
            .transform(Transformers.fileToString())
            .transform("payload.replaceAll('\r\n', '\n')")
            .handle(Files.outboundAdapter("'/tmp/out'")
                    .autoCreateDirectory(true))
            .get();
}

The fixedDelay() is an answer to your second question about fixed-interval.

https://github.com/spring-projects/spring-integration-java-dsl/blob/master/src/test/java/org/springframework/integration/dsl/samples/file2file1/FileChangeLineSeparator.java



来源:https://stackoverflow.com/questions/44524793/polling-from-file-using-java-dsl-compile-error-when-adding-files-inboundadapte

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!