SourcePollingChannelAdapter创建

时间:2015-07-22 21:34:42

标签: java spring spring-integration

我使用spring和spring-integration。我需要为Feed解析创建SourcePollingChannelAdapter动态,并在Spring上下文中注册。

      QueueChannel channel = (QueueChannel) context.getBean("rssFeedChannel");
      SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter();
      adapter.setApplicationContext(context);
      adapter.setBeanName("adapter.1");
      FeedEntryMessageSource source = new FeedEntryMessageSource(new URL("https://spring.io/blog.atom"), "news");
      source.setApplicationContext(context);
      source.setBeanName("source");
      adapter.setSource(source);
      adapter.setOutputChannel(channel);
      adapter.setTrigger(new PeriodicTrigger(1000));
      adapter.start();

我的应用程序配置:

<int:poller default="true" fixed-rate="5000"/>

    <int:channel id="rssFeedChannel">
        <int:queue capacity="40"/>
    </int:channel>

    <file:outbound-channel-adapter id="file" mode="APPEND" charset="UTF-8" directory="/tmp/si" filename-generator-expression="'SpringBlog'"/>
    <!-- With this work -->
    <!--<feed:inbound-channel-adapter id="news" channel="rssFeedChannel" url="https://spring.io/blog.atom">-->
        <!--<int:poller fixed-rate="5000"/>-->
    <!--</feed:inbound-channel-adapter>-->

    <int:transformer input-channel="rssFeedChannel" expression="payload.title + ' @ ' + payload.link + '#{systemProperties['line.separator']}'" output-channel="file"/>

但没有任何内容写入文件。请帮忙。

1 个答案:

答案 0 :(得分:0)

  1. 您也必须将FeedEntryMessageSource作为bean。 applicationContext注射。

  2. 您忘记调用adapter.afterPropertiesSet()。对于FeedEntryMessageSource实例,BTW相同。

  3. 请从另一方面分享您的想法,以便采用这种手册方式。为什么不依靠标准的反转控制原理?