我正在通过spring集成开发一个多属性微服务。我正在从数据库中获取每个属性的登录凭据,如登录表。LOGIN表包含以下字段: LOGIN.username、LOGIN.pass和LOGIN.period(轮询者的句号)。如果我想让微服务基于LOGIN.period字段使用不同的轮询器配置,我该怎么做呢?
@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值在不同的轮询器配置中创建工作流?
发布于 2020-09-29 23:39:13
请展示一下如何从数据库中获取信息。
但是,如果您的观点是在DB中可能有多个记录,并且希望所有记录都有多个轮询器,那么您需要考虑一下动态流注册:https://docs.spring.io/spring-integration/docs/5.3.2.RELEASE/reference/html/dsl.html#java-dsl-runtime-flows
因此,您从DB读取数据,在循环中为每个记录创建IntegrationFlow,并根据记录中的数据配置它们的轮询器。
发布于 2020-09-30 01:21:35
基于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();
});
}https://stackoverflow.com/questions/64122660
复制相似问题