Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring integration 如何在spring集成数据库轮询器中从多个表中获取数据_Spring Integration_Spring Integration Dsl - Fatal编程技术网

Spring integration 如何在spring集成数据库轮询器中从多个表中获取数据

Spring integration 如何在spring集成数据库轮询器中从多个表中获取数据,spring-integration,spring-integration-dsl,Spring Integration,Spring Integration Dsl,我有一个db轮询器,可以从多个表中获取行。因此,我编写了两个轮询器,使用下面的代码独立获取数据,它工作正常,但下面的代码存在冗余问题。那么有没有更好的方法来实现这一点 //Poller 1 for table one: @Bean public MessageSource<Object> jdbcMessageSource() throws SQLException { return new JdbcPollingChannelAdapter(dat

我有一个db轮询器,可以从多个表中获取行。因此,我编写了两个轮询器,使用下面的代码独立获取数据,它工作正常,但下面的代码存在冗余问题。那么有没有更好的方法来实现这一点

//Poller 1 for table one:   
 
@Bean
    public MessageSource<Object> jdbcMessageSource() throws SQLException {
        return new JdbcPollingChannelAdapter(dataSourceConfig.getDataSource(), "select * from db.table_name_one");
    }
    @Bean
    public IntegrationFlow pollingFlow() throws Exception {
        return IntegrationFlows.from(jdbcMessageSource(),
                c -> c.poller(Pollers.fixedRate(10000)))
                .handle(List.class, (payload, headers) -> {
                    transferExecutor.handleMessage(payload);
                    return null;
                })
                .get();
    }

//Poller 2 for table two: 
    @Bean
        public MessageSource<Object> jdbcMessageSource1() throws SQLException {
            return new JdbcPollingChannelAdapter(dataSourceConfig.getDataSource(), "select * from db.table_name_two");
        }
        @Bean
        public IntegrationFlow pollingFlow1() throws Exception {
            return IntegrationFlows.from(jdbcMessageSource1(),
                    c -> c.poller(Pollers.fixedRate(10000)))
                    .handle(List.class, (payload, headers) -> {
                        transferExecutor.handleMessage(payload);
                        return null;
                    })
                    .get();
        }

   
//表1的轮询器1:
@豆子
public MessageSource jdbcMessageSource()引发SQLException{
返回新的JdbcPollingChannelAdapter(dataSourceConfig.getDataSource(),“select*from db.table_name_one”);
}
@豆子
public IntegrationFlow pollingFlow()引发异常{
返回IntegrationFlows.from(jdbcMessageSource(),
c->c.poller(poller.fixedRate(10000)))
.handle(List.class,(有效负载,标题)->{
transferExecutor.handleMessage(有效载荷);
返回null;
})
.get();
}
//表2的轮询器2:
@豆子
public MessageSource jdbcMessageSource1()引发SQLException{
返回新的JdbcPollingChannelAdapter(dataSourceConfig.getDataSource(),“select*from db.table_name_two”);
}
@豆子
public IntegrationFlow pollingFlow1()引发异常{
返回IntegrationFlows.from(jdbcMessageSource1(),
c->c.poller(poller.fixedRate(10000)))
.handle(List.class,(有效负载,标题)->{
transferExecutor.handleMessage(有效载荷);
返回null;
})
.get();
}

如果这些表中的数据完全不同,则您的解决方案是正确的。 因为您有不同的表,所以使用不同的服务来处理它们是非常合乎逻辑的

您将为这些表执行JPA,因此您可能会有不同的实体和不同的Spring数据存储库

但是,如果数据相似,您可能可以向DBA咨询如何为这两个表构建
JOIN
select,甚至在DB中有一个
视图
,以便从您的应用程序执行简单的查询


Spring集成绝对不能为您做任何事情。为与RDBMS的交互做一些繁重的工作并不是这个框架的责任。

如果像这样运行轮询器,它会在并行线程中运行吗?