[英]How to set several message handlers for channel in spring integration DSL?
我编写了我的第一个 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;
}
}
但我不知道如何添加一个额外的处理程序来将结果写入文件。
我怎样才能实现它?
补充问题:
元数据密钥是什么意思?
有一个publishSubscribeChannel()
放置在流中,您可以在那里为多个子流添加subscribe()
。 他们每个人都将获得相同的消息进行处理。 如果您还在配置中添加了一个Executor
,该过程将并行发生:
.publishSubscribeChannel(s -> s
.applySequence(true)
.subscribe(f -> f
.handle((p, h) -> "Hello"))
.subscribe(f -> f
.handle((p, h) -> "World!"))
);
在文档中查看更多信息: https : //docs.spring.io/spring-integration/docs/5.2.0.BUILD-SNAPSHOT/reference/html/dsl.html#java-dsl-subflows
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.