【问题标题】:spring-integration-dsl: Make Feed-Flow Workspring-integration-dsl:使 Feed-Flow 工作
【发布时间】:2016-08-23 04:37:21
【问题描述】:

我正在尝试使用一组已配置的 RSS 提要编写 RSS 提要阅读器。我认为一个好的方法是通过编写原型-@Bean 并使用配置中找到的每个 RSS-feed 调用它来解决这个问题。

但是,我想我在应用程序启动时在这里遗漏了一点,但没有任何反应。我的意思是 bean 是按照我的预期创建的,但是 handle()-method 中没有发生日志记录:

@Component
public class HomeServerRunner implements ApplicationRunner {

    private static final Logger logger = LoggerFactory.getLogger(HomeServerRunner.class);

    @Autowired
    private Configuration configuration;

    @Autowired
    private FeedConfigurator feedConfigurator;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        List<IntegrationFlow> feedFlows = configuration.getRssFeeds()
            .entrySet()
            .stream()
            .peek(entry -> System.out.println(entry.getKey()))
            .map(entry -> feedConfigurator.feedFlow(entry.getKey(), entry.getValue()))
            .collect(Collectors.toList());
        // this one appears in the log-file and looks good
        logger.info("Flows: " + feedFlows);
    }

}

@Configuration
public class FeedConfigurator {

    private static final Logger logger = LoggerFactory.getLogger(FeedConfigurator.class);

    @Bean
    @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    public IntegrationFlow feedFlow(String name, FeedConfiguration configuration) {
        return IntegrationFlows
                .from(Feed
                        .inboundAdapter(configuration.getSource(), getElementName(name, "adapter"))
                        .feedFetcher(new HttpClientFeedFetcher()),
                        spec -> spec.poller(Pollers.fixedRate(configuration.getInterval())))
                .channel(MessageChannels.direct(getElementName(name, "in")))
                .enrichHeaders(spec -> spec.header("feedSource", configuration))
                .channel(getElementName(name, "handle"))
        //
        // it would be nice if the following would show something:
        //
                .handle(m -> logger.debug("Payload: " + m.getPayload()))
                .get();
    }

    private String getElementName(String name, String postfix) {
        name = "feedChannel" + StringUtils.capitalize(name);
        if (!StringUtils.isEmpty(postfix)) {
            name += "." + postfix;
        }
        return name;
    }

}

这里缺少什么?似乎我需要以某种方式“启动”流程。

【问题讨论】:

    标签: rss spring-integration spring-dsl


    【解决方案1】:

    原型 bean 需要在某处“使用” - 如果您在任何地方都没有对它的引用,则不会创建任何实例。

    此外,您不能在该范围内放置 IntegrationFlow @Bean - 它会在内部生成一堆不在该范围内的 bean。

    请参阅答案 to this questionits follow-up,了解一种可用于创建具有不同属性的多个适配器的技术。

    另外,即将推出的1.2 version of the DSL 具有动态注册流的机制。

    【讨论】:

      猜你喜欢
      • 2021-06-07
      • 2017-12-31
      • 2022-07-11
      • 2017-12-22
      • 2018-03-24
      • 1970-01-01
      • 1970-01-01
      • 2017-12-23
      • 1970-01-01
      相关资源
      最近更新 更多