Spring Integration
https://docs.spring.io/spring-integration/reference/html/dsl.html#java-dsl
Feed Data to File
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| @Configuration @EnableIntegration public class IntegrationFlowConfig {
@Bean public MessageChannel directChannel() { return new DirectChannel(); }
@SneakyThrows @Bean public IntegrationFlow feedToChannelIntegrationFlow() { UrlResource urlResource = new UrlResource("https://spring.io/blog.atom"); FeedEntryMessageSource messageSource = new FeedEntryMessageSource(urlResource, "myKey"); return IntegrationFlows.from(messageSource, c -> c.poller(Pollers.fixedRate(5000))) .transform("payload.title + ' @ ' + payload.link + ';'") .channel(directChannel()) .get(); }
@Bean public IntegrationFlow channelToFileIntegrationFlow() { FileWritingMessageHandler messageHandler = new FileWritingMessageHandler(new File("src/main/resources/integration")); messageHandler.setFileExistsMode(FileExistsMode.APPEND); messageHandler.setCharset(Charsets.UTF_8.toString()); messageHandler.setExpectReply(false); return IntegrationFlows.from(directChannel()) .handle(messageHandler) .get();
}
}
|
Title: Spring Integration
Author: Jiandong
Date: 2022-04-18
Last Update: 2025-02-23
Blog Link: https://mjd507.github.io/2022/04/18/Spring-Integration/
Copyright Declaration: Please refer carefully, most of the content I have not fully mastered.