我正在尝试使用Java DSL编写一些伪代码来连接两个不同数据库中的两个相同的表。
例如,我在MySQL和PostgreSQL数据库中有一个Person表。想看到所有行的联合。有人可以就如何实现它提出任何建议吗?
更新:我尝试的是路由定义中的代码
from(sql:select name, age from person?datasource=xyz).to(direct:foo);
from(sql:select name, age from person?datasource=abc).to(direct:foo);
from(direct:foo).to(stream:out);
上面提取数据并组合成一个通道,但是,我想做删除重复,过滤行等操作。我不知道该怎么做。也许需要Aggregator组件?
这看起来很简单 - 你只需要记住两件事。
那么,只有这样,你才能将它们聚合在一起。
如果我要捅它,这将是一个开始。我想利用SQL component的能力来指定应该存储SQL结果的特定标头。从那里我发现在聚合之后使用简单的处理器来处理两个记录并执行我想要的任何逻辑更容易一些跟他们。
from("sql:select name, age from person?datasource=xyz&outputHeader=MySqlDataSet&outputType=Person")
.to("direct:foo");
from("sql:select name, age from person?datasource=abc&outputHeader=PostgresDataSet&outputType=Person")
.to("direct:foo");
from("direct:foo")
.aggregate(constant(true), new GroupedExchangeAggregationStrategy())
.completionFromBatchConsumer()
.process(exchange -> {
// now you have control over the exchange which has both exchanges
// which has both properties you require.
// manipulate, merge, and dedupe here to your heart's content.
});