首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >spring-integration-dsl:让Feed-Flow工作

spring-integration-dsl:让Feed-Flow工作
EN

Stack Overflow用户
提问于 2016-08-23 04:10:44
回答 1查看 178关注 0票数 0

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

但是,我想我在应用程序启动时遗漏了一点,但是什么也没有发生。我的意思是,beans是按照我的预期创建的,但是在那个handle()-method中没有日志记录:

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

}

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-23 04:20:45

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

此外,您不能将IntegrationFlow @Bean放在该作用域中-它会在内部生成一堆不在该作用域中的bean。

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

或者,即将推出的1.2 version of the DSL有一种动态注册流的机制。

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

https://stackoverflow.com/questions/39087914

复制
相关文章

相似问题

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