Spring integration 是否可以从数据源为每个实体配置轮询器?
我正在通过spring集成开发一个多属性的微服务。我从数据库中获取每个属性的登录凭据,如登录表。登录表包含以下字段;LOGIN.username、LOGIN.pass和LOGIN.period(轮询周期)。如果我想使用基于LOGIN.period字段的不同轮询器配置使micro服务正常工作,我该怎么做Spring integration 是否可以从数据源为每个实体配置轮询器?,spring-integration,spring-integration-dsl,Spring Integration,Spring Integration Dsl,我正在通过spring集成开发一个多属性的微服务。我从数据库中获取每个属性的登录凭据,如登录表。登录表包含以下字段;LOGIN.username、LOGIN.pass和LOGIN.period(轮询周期)。如果我想使用基于LOGIN.period字段的不同轮询器配置使micro服务正常工作,我该怎么做 @Bean public IntegrationFlow start() { return IntegrationFlows .fr
@Bean
public IntegrationFlow start() {
return IntegrationFlows
.from(() -> DAO.getLoginList()) // from a web service.
.split() // splits the each login credentials for each property.
.channel("X_CHANNEL") // subscribes to a channel todo business logic.
.get();
}
是否可以实现一个组件,根据数据库中的LOGIN.period值在不同的轮询器配置中生成工作流?请展示您如何从数据库中获取该信息 但是,如果您认为DB中可能有多个记录,并且希望对所有记录使用多个轮询器,那么您需要查看动态流注册:
因此,您从数据库读取数据,在循环中为每个记录创建
IntegrationFlow
,并根据记录中的数据配置轮询器。基于Artem Bilan的回答,我实现了IntegrationFlowContext和IntegrationFlow实例
@Autowired
IntegrationFlowContext flowContext;
@Bean
public void setFlowContext() {
List<Login> loginList = DAO.getLoginList(); // a web service
loginList.forEach(e -> {
IntegrationFlow flow = IntegrationFlows.from(() -> e, c -> c.poller(Pollers.fixedRate(e.getPeriod(), TimeUnit.SECONDS, 5)))
.channel("X_CHANNEL")
.get();
flowContext.registration(flow).register();
});
}
@Autowired
集成流上下文流上下文;
@豆子
public void setFlowContext(){
List loginList=DAO.getLoginList();//一个web服务
登录列表。forEach(e->{
IntegrationFlow=IntegrationFlows.from(()->e,c->c.poller(Pollers.fixedRate(e.getPeriod(),TimeUnit.SECONDS,5)))
.频道(“X_频道”)
.get();
flowContext.registration(flow.register();
});
}
我正在通过web服务从登录表获取登录凭据。好的,我从(()->DAO.getLoginList())//从web服务看到了。
。因此,听起来您仍然有一些动态,因此动态的IntegrationFlowContext
和IntegrationFlow
实例是您的选择。你无法在应用程序启动时获得这些信息,也无法调整轮询器bean。对于您的用例来说,当您从DAO调用中获得拆分结果时,确实需要在运行时执行此操作。。。