Update sample-parent-context following changes to integration starter

See gh-5528
This commit is contained in:
Andy Wilkinson
2016-04-18 15:35:27 +01:00
parent a2489b01aa
commit b9d7a39693
3 changed files with 57 additions and 22 deletions

View File

@@ -16,20 +16,71 @@
package sample.parent;
import java.io.File;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.annotation.Bean;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.dsl.IntegrationFlow;
import org.springframework.integration.dsl.IntegrationFlows;
import org.springframework.integration.dsl.SourcePollingChannelAdapterSpec;
import org.springframework.integration.dsl.core.Pollers;
import org.springframework.integration.dsl.support.Consumer;
import org.springframework.integration.file.FileReadingMessageSource;
import org.springframework.integration.file.FileWritingMessageHandler;
@SpringBootApplication
@EnableConfigurationProperties(ServiceProperties.class)
public class SampleParentContextApplication {
@EnableAutoConfiguration
@ImportResource("integration-context.xml")
protected static class Parent {
@Bean
public FileReadingMessageSource fileReader() {
FileReadingMessageSource reader = new FileReadingMessageSource();
reader.setDirectory(new File("target/input"));
return reader;
}
@Bean
public DirectChannel inputChannel() {
return new DirectChannel();
}
@Bean
public DirectChannel outputChannel() {
return new DirectChannel();
}
@Bean
public FileWritingMessageHandler fileWriter() {
FileWritingMessageHandler writer = new FileWritingMessageHandler(
new File("target/output"));
writer.setExpectReply(false);
return writer;
}
@Bean
public IntegrationFlow integrationFlow(SampleEndpoint endpoint) {
return IntegrationFlows.from(fileReader(), new FixedRatePoller())
.channel(inputChannel()).handle(endpoint).channel(outputChannel())
.handle(fileWriter()).get();
}
private static class FixedRatePoller
implements Consumer<SourcePollingChannelAdapterSpec> {
@Override
public void accept(SourcePollingChannelAdapterSpec spec) {
spec.poller(Pollers.fixedRate(500));
}
}
}
public static void main(String[] args) throws Exception {