我一直在研究使用使用多个RSS提要。我遵循了这里的集成指南:https://spring.io/guides/gs/integration/,这是很棒的。
是否有可能将多个入站通道适配器(用于多个提要)写入一个通道?
另外,是否可以在数据中使用通道适配器ID来标识提要(例如Spring )?
任何示例代码都会很棒。
发布于 2017-04-16 13:38:51
是的,只需给通道适配器一个id并命名通道(如果没有channel,则id成为适配器的通道名称)。您可以向同一个频道提供多个适配器。添加一个标题丰富她来识别源..。
<feed:inbound-channel-adapter id="spring"
channel="springblog" url="http://spring.io/blog.atom" auto-startup="${auto.startup:true}">
<int:poller fixed-rate="5000"/>
</feed:inbound-channel-adapter>
<int:header-enricher input-channel="springblog" output-channel="news">
<int:header name="source" value="spring.blog"/>
</int:header-enricher>
<int:transformer
input-channel="news"
expression=
"headers['source'] + ':' + payload.title + ' @ ' + payload.link + '#{systemProperties['line.separator']}'"
output-channel="file"/>
<file:outbound-channel-adapter id="file"
mode="APPEND"
charset="UTF-8"
directory="/tmp/si"
filename-generator-expression="'${feed.file.name:SpringBlog}'"/>使用更新的Java而不是XML,这将是.
@Bean
public IntegrationFlow blog() throws Exception {
return IntegrationFlows
.from(new FeedEntryMessageSource(new URL(BLOG_URI), "blog"), e -> e.id("blog").poller(Pollers.fixedDelay(5000)))
.enrichHeaders(h -> h.header("source", "spring.blog"))
.channel("news")
.get();
}
@Bean
public IntegrationFlow newsFlow() {
return IntegrationFlows.from("news")
.transform("headers['source'] + ':' + payload.title + ' @ ' + payload.link + '" + newline + "'") // SpEL
.handle(Files.outboundAdapter(new File("/tmp/si/"))
.fileNameExpression("'SpringBlogDSL'")
.fileExistsMode(FileExistsMode.APPEND))
.get();
}编辑
动态流登记..。
@Autowired
private IntegrationFlowContext flowContext;
...
IntegrationFlow newFLow = IntegrationFlows
.from(new FeedEntryMessageSource(new URL(BLOG_URI), "blog"), e -> e.id("blog").poller(Pollers.fixedDelay(5000)))
.enrichHeaders(h -> h.header("source", "spring.blog"))
.channel("news")
.get();
this.flowContent.registration(newFlow).register();有关完整的示例,请参阅动态tcp客户端示例。
发布于 2017-04-16 13:22:55
是的,您可以将多个通道适配器连接到同一个消息通道。实际上,任何生产者都可以发送到任何频道,并有关于附加信息的请求,我建议在每个提要入站适配器之后有一个标题丰富她,以填充所需的特性。在此之后,您可以发送到那个单一的通道进行处理。
https://stackoverflow.com/questions/43436750
复制相似问题