Created
March 5, 2018 19:27
-
-
Save dbuos/87bf588c0b4b89bd8967790f860c8598 to your computer and use it in GitHub Desktop.
Simple spring integration example to listen to a directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.example.demo; | |
| import org.springframework.beans.factory.annotation.Value; | |
| import org.springframework.context.annotation.Bean; | |
| import org.springframework.context.annotation.Configuration; | |
| import org.springframework.integration.dsl.IntegrationFlow; | |
| import org.springframework.integration.dsl.IntegrationFlows; | |
| import org.springframework.integration.file.dsl.Files; | |
| import java.io.File; | |
| import java.util.concurrent.TimeUnit; | |
| @Configuration | |
| public class SimpleSpringIntegrationExample { | |
| @Bean | |
| public IntegrationFlow fileIntegrationWatcher(@Value("${HOME}/in") File file){ | |
| return IntegrationFlows.from(Files.inboundAdapter(file) | |
| .preventDuplicates(true) | |
| .autoCreateDirectory(true), poller -> poller.poller(s -> s.fixedRate(1, TimeUnit.SECONDS))) | |
| .transform(File.class, File::getAbsolutePath) | |
| .handle(String.class, (payload, headers) -> { | |
| System.out.println("Archivo creado"); | |
| System.out.println(payload); | |
| return null; | |
| }).get(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment