首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将多个RSS提要放入一个通道

将多个RSS提要放入一个通道
EN

Stack Overflow用户
提问于 2017-04-16 11:29:42
回答 2查看 491关注 0票数 0

我一直在研究使用使用多个RSS提要。我遵循了这里的集成指南:https://spring.io/guides/gs/integration/,这是很棒的。

是否有可能将多个入站通道适配器(用于多个提要)写入一个通道?

另外,是否可以在数据中使用通道适配器ID来标识提要(例如Spring )?

任何示例代码都会很棒。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-04-16 13:38:51

是的,只需给通道适配器一个id并命名通道(如果没有channel,则id成为适配器的通道名称)。您可以向同一个频道提供多个适配器。添加一个标题丰富她来识别源..。

代码语言:javascript
复制
<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,这将是.

代码语言:javascript
复制
@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();
}

编辑

动态流登记..。

代码语言:javascript
复制
@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客户端示例

票数 1
EN

Stack Overflow用户

发布于 2017-04-16 13:22:55

是的,您可以将多个通道适配器连接到同一个消息通道。实际上,任何生产者都可以发送到任何频道,并有关于附加信息的请求,我建议在每个提要入站适配器之后有一个标题丰富她,以填充所需的特性。在此之后,您可以发送到那个单一的通道进行处理。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43436750

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档