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

194 views Asked by At

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

There are 2 answers

2
Artem Bilan On BEST ANSWER

Show, please, how you get that info from the data base.

But if your point that you may have several records in DB and you want to have several pollers for all of them, then you need to take a look dynamic flow registrations: https://docs.spring.io/spring-integration/docs/5.3.2.RELEASE/reference/html/dsl.html#java-dsl-runtime-flows

So, you read data from the DB, create IntegrationFlow in the loop for every record and configure their pollers according the data from the record.

0
ytWho On

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