代码之家  ›  专栏  ›  技术社区  ›  Ramesh Reddy

如何使用Camel连接来自不同数据源的两个相同表?

  •  -1
  • Ramesh Reddy  · 技术社区  · 6 年前

    更新:我尝试的是路由定义中的以下代码

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

    上面的获取数据并合并到一个通道中,但是,我想做一些操作,比如删除重复项,过滤行等等。在那里我不知道怎么做。可能需要聚合器组件?

    1 回复  |  直到 6 年前
        1
  •  2
  •   Makoto    6 年前

    这看起来很简单,你只需要记住两件事。

    • 你有来自两个地方的数据。
    • 之前

    那么 ,只有这样,才能将它们聚合在一起。

    如果我要尝试一下,这将是一个开始。我想利用 SQL component

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