Camel SQL -单个插入到批处理

uajslkp6  于 2023-03-18  发布在  Apache
关注(0)|答案(1)|浏览(100)

我正在使用Camel SQL。我正在尝试从Oracle收集数据并将其插入Snowflakes。以下是代码片段。

from(sql:select*...?dataSource=#oracleDataSource&repeatcount=1&batch=true)
.filter(ex -> filterDataMethod(ex))
.process(ex -> addHeadersForInsert(ex))
to(sql:insert into tableName (loadDate,col1 , col2 , col3) values (:#col1 , :#col2 , :#col3 , :#col4 )?dataSource=#snowflakesDataSource&repeatcount=1)

我尝试在From和To URI中添加batch=true,但代码不是以批处理方式运行,而是只插入单行。请让我知道是否有任何选项可以将其转换为批处理,以避免单个数据插入。
注意:我已经浏览了一些与此相关的帖子,但找不到任何与此相关的内容。
我按照上面提到的说明使用Iterator。它创建了重复的记录。

g9icjywg

g9icjywg1#

尝试后发现以下路线中的Batch = true将不会启用批处理模式。
1.数据需要通过手动过程批处理。我使用了聚合器,并从聚合器返回了数据列表。使用了 Camel 页面中提到的相同示例。路线:-
from().aggregate(常量(1),新的数组列表聚合策略()).completionSize(您喜欢的批处理大小).completionTimeout(500).to()
聚合类ArrayListAggregationStrategy类实现了聚合策略{

public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
        Object newBody = newExchange.getIn().getBody();
        ArrayList<Object> list = null;
        if (oldExchange == null) {
            list = new ArrayList<Object>();
            list.add(newBody);
            newExchange.getIn().setBody(list);
            return newExchange;
        } else {
            list = oldExchange.getIn().getBody(ArrayList.class);
            list.add(newBody);
            return oldExchange;
        }
    }
}

1.一旦数据以列表形式返回,就有另一个处理器将数据作为迭代器的HashMap〈〉返回,迭代器在主体中设置。
在此过程中,当路线中启用batch = true时,数据将插入到Batch中。

相关问题