我编写了我的第一个spring集成应用程序,该应用程序从spring RSS中读取数据并将其记录到控制台:
@Configuration
@EnableIntegration
@IntegrationComponentScan
public class DslConfig {
@Bean
public IntegrationFlow feedFlow() throws MalformedURLException {
return IntegrationFlows.from(inBoundFeedDataAdapter(), configurer -> configurer.poller(Pollers.fixedDelay(1000)))
.channel(newsChannel())
.transform(source -> {
SyndEntry e = ((SyndEntry) source);
return e.getTitle() + " " + e.getLink();
})
.handle(messageHandler())
.get();
}
@Bean
public FeedEntryMessageSourceSpec inBoundFeedDataAdapter() throws MalformedURLException {
return Feed.inboundAdapter(new URL("https://spring.io/blog.atom"), "some_key");
}
@Bean
public MessageChannel newsChannel() {
return new DirectChannel();
}
@Bean
public MessageHandler messageHandler() {
return System.out::println;
}
}
但是我不知道如何添加一个额外的处理程序以将结果写入文件。
如何实现?
其他问题:
元数据键是什么意思?
答案 0 :(得分:2)
在流程中放置一个publishSubscribeChannel()
,您可以在其中添加subscribe()
用于几个子流程。他们每个人都将得到相同的消息来处理。如果您还向配置中添加Executor
,则该过程将并行进行:
.publishSubscribeChannel(s -> s
.applySequence(true)
.subscribe(f -> f
.handle((p, h) -> "Hello"))
.subscribe(f -> f
.handle((p, h) -> "World!"))
);