Skip to content

Instantly share code, notes, and snippets.

@dbuos
Created March 5, 2018 19:27
Show Gist options
  • Select an option

  • Save dbuos/87bf588c0b4b89bd8967790f860c8598 to your computer and use it in GitHub Desktop.

Select an option

Save dbuos/87bf588c0b4b89bd8967790f860c8598 to your computer and use it in GitHub Desktop.
Simple spring integration example to listen to a directory
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