2014-06-10 16:13:19 +08:00
|
|
|
/*
|
2019-03-11 23:01:59 +08:00
|
|
|
* Copyright 2012-2019 the original author or authors.
|
2014-06-10 16:13:19 +08:00
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
2019-03-20 22:54:00 +08:00
|
|
|
* https://www.apache.org/licenses/LICENSE-2.0
|
2014-06-10 16:13:19 +08:00
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package sample.parent;
|
|
|
|
|
|
2016-04-18 22:35:27 +08:00
|
|
|
import java.io.File;
|
2016-11-04 04:49:02 +08:00
|
|
|
import java.util.function.Consumer;
|
2016-04-18 22:35:27 +08:00
|
|
|
|
2014-06-10 16:13:19 +08:00
|
|
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
2014-11-07 05:50:45 +08:00
|
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
2014-06-10 16:13:19 +08:00
|
|
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
|
|
|
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
2016-04-18 22:35:27 +08:00
|
|
|
import org.springframework.context.annotation.Bean;
|
2019-03-11 23:01:59 +08:00
|
|
|
import org.springframework.context.annotation.Configuration;
|
2016-04-18 22:35:27 +08:00
|
|
|
import org.springframework.integration.channel.DirectChannel;
|
|
|
|
|
import org.springframework.integration.dsl.IntegrationFlow;
|
|
|
|
|
import org.springframework.integration.dsl.IntegrationFlows;
|
2016-11-04 04:49:02 +08:00
|
|
|
import org.springframework.integration.dsl.Pollers;
|
2016-04-18 22:35:27 +08:00
|
|
|
import org.springframework.integration.dsl.SourcePollingChannelAdapterSpec;
|
|
|
|
|
import org.springframework.integration.file.FileReadingMessageSource;
|
|
|
|
|
import org.springframework.integration.file.FileWritingMessageHandler;
|
2014-06-10 16:13:19 +08:00
|
|
|
|
2014-11-07 05:50:45 +08:00
|
|
|
@SpringBootApplication
|
2014-06-10 16:13:19 +08:00
|
|
|
@EnableConfigurationProperties(ServiceProperties.class)
|
|
|
|
|
public class SampleParentContextApplication {
|
|
|
|
|
|
2018-05-26 06:57:29 +08:00
|
|
|
public static void main(String[] args) throws Exception {
|
2019-06-08 15:16:27 +08:00
|
|
|
new SpringApplicationBuilder(Parent.class).child(SampleParentContextApplication.class).run(args);
|
2018-05-26 06:57:29 +08:00
|
|
|
}
|
|
|
|
|
|
2019-03-11 23:01:59 +08:00
|
|
|
@Configuration
|
2014-06-10 16:13:19 +08:00
|
|
|
@EnableAutoConfiguration
|
|
|
|
|
protected static class Parent {
|
2014-07-03 05:43:43 +08:00
|
|
|
|
2016-04-18 22:35:27 +08:00
|
|
|
@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() {
|
2019-06-08 15:16:27 +08:00
|
|
|
FileWritingMessageHandler writer = new FileWritingMessageHandler(new File("target/output"));
|
2016-04-18 22:35:27 +08:00
|
|
|
writer.setExpectReply(false);
|
|
|
|
|
return writer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
public IntegrationFlow integrationFlow(SampleEndpoint endpoint) {
|
2019-06-08 15:16:27 +08:00
|
|
|
return IntegrationFlows.from(fileReader(), new FixedRatePoller()).channel(inputChannel()).handle(endpoint)
|
|
|
|
|
.channel(outputChannel()).handle(fileWriter()).get();
|
2016-04-18 22:35:27 +08:00
|
|
|
}
|
|
|
|
|
|
2019-06-08 15:16:27 +08:00
|
|
|
private static class FixedRatePoller implements Consumer<SourcePollingChannelAdapterSpec> {
|
2016-04-18 22:35:27 +08:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void accept(SourcePollingChannelAdapterSpec spec) {
|
|
|
|
|
spec.poller(Pollers.fixedRate(500));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-10 16:13:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|