我刚开始使用Apache Camel,我想尝试同步两个表。两个表都有两列,分别是“id”和“name”。该方案将查询第一个表,检查第二个表中每个记录的存在,并插入不存在的每个记录。这里是我的尝试:使用Apache Camel同步两个表
<camel:camelContext id="test">
<camel:route>
<camel:from uri="timer://kickoff?period=5s"/>
<camel:to uri="sql:select id, name from table1?dataSourceRef=dataSource"/>
<camel:split>
<camel:simple>body</camel:simple>
<camel:to uri="sql:select * from table2 where id = #?dataSourceRef=dataSource" />
<camel:choice>
<camel:when>
<camel:simple>${header.CamelSqlRowCount} == 0</camel:simple>
<camel:to uri="sql:insert into table2 (id, name) values (#, #)?dataSourceRef=dataSource" />
</camel:when>
</camel:choice>
<camel:to uri="mock:result" />
</camel:split>
</camel:route>
</camel:camelContext>
这里的问题是,我到insert into table2
,原来消息的时间(包含数据的一个)丢失,因为我不得不做出另一个查询在此期间(其中我检查第二个表中的数据)。我的方法很好,我如何检索包含数据的消息?
这帮了我。对于Postgresql,我做了“插入......在冲突时更新集...”。 – Mustafa