Spring Integration DSL动态入站通道

时间:2015-10-13 22:34:42

标签: spring-integration dsl

是否可以在运行时使用spring-integration-dsl?

注册MessageSources

在我的情况下,我想创建多个FileReadingMessageSources(基于来自UI的输入),然后将有效负载发送到特定的channel / jms路由(从元数据或用户输入读取)

另一个问题是,是否可以动态注册IntegrationFlows?

1 个答案:

答案 0 :(得分:3)

这有点棘手,需要一些Spring基础知识知识,但是有可能:

@Service
public static class MyService {

    @Autowired
    private AutowireCapableBeanFactory beanFactory;

    @Autowired
    @Qualifier("dynamicAdaptersResult")
    PollableChannel dynamicAdaptersResult;

    public void pollDirectories(File... directories) {
        for (File directory : directories) {
            StandardIntegrationFlow integrationFlow = IntegrationFlows
                    .from(s -> s.file(directory),
                            e -> e.poller(p -> p.fixedDelay(1000))
                                    .id(directory.getName() + ".adapter"))
                    .transform(Transformers.fileToString(),
                            e -> e.id(directory.getName() + ".transformer"))
                    .channel(this.dynamicAdaptersResult)
                    .get();
            this.beanFactory.initializeBean(integrationFlow, directory.getName());
            this.beanFactory.getBean(directory.getName() + ".transformer", Lifecycle.class).start();
            this.beanFactory.getBean(directory.getName() + ".adapter", Lifecycle.class).start();
        }
    }

}

请调查我的样本,并告诉我你不清楚的事情。