Created
August 25, 2018 09:39
-
-
Save madan712/58ccdde9f52f7278d9592392372f23c9 to your computer and use it in GitHub Desktop.
ApplicationConfig.java for Simple spring integration with springboot
This file contains 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.javaxp; | |
import java.io.File; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.integration.annotation.InboundChannelAdapter; | |
import org.springframework.integration.annotation.Poller; | |
import org.springframework.integration.annotation.ServiceActivator; | |
import org.springframework.integration.channel.DirectChannel; | |
import org.springframework.integration.config.EnableIntegration; | |
import org.springframework.integration.core.MessageSource; | |
import org.springframework.integration.file.filters.SimplePatternFileListFilter; | |
import org.springframework.messaging.MessageChannel; | |
import org.springframework.messaging.MessageHandler; | |
@Configuration | |
@EnableIntegration | |
public class ApplicationConfig { | |
public static final String POLLING_LOCATION = "D:\\pollingLocation"; | |
public static final String FILE_PATTERN = "*.txt"; | |
public static final String OUTPUT_LOCATION = "D:\\outputLocation"; | |
@Bean | |
public MessageChannel fileChannel() { | |
return new DirectChannel(); | |
} | |
@Bean | |
@InboundChannelAdapter(value = "fileChannel", poller = @Poller(fixedDelay = "1000")) | |
public MessageSource<File> fileReadingMessageSource() { | |
File directory = new File(POLLING_LOCATION); | |
SimplePatternFileListFilter filter = new SimplePatternFileListFilter(FILE_PATTERN); | |
return new FilePoller(directory, filter); | |
} | |
@Bean | |
@ServiceActivator(inputChannel = "fileChannel") | |
public MessageHandler fileWritingMessageHandler() { | |
return new FileHandler(OUTPUT_LOCATION); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment