Is it possible to configure poller for each entity from a data source?

Viewed 123

I'm developing a multi property micro service by spring integration. I'm getting each property's login credentials from database like LOGIN table. LOGIN table has these fields; LOGIN.username, LOGIN.pass and LOGIN.period(poller's period). If I want to make work the micro service with different poller configurations based on LOGIN.period field, how can I do that?

    @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();
    }

Is it possible to implement a component to make work flow in different poller configurations based on the LOGIN.period value from database?

2 Answers

Based on the Artem Bilan's answer, I've implement the IntegrationFlowContext and IntegrationFlow instances;

    @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();
        });
    }

Related