我创建/创建了一个简单的Apache Camel程序,用于将数据从源数据库移动到目标数据库。我已经配置了一条路线来完成这项工作!问题是它只是每隔一秒左右继续执行root。我只希望它执行一次。
我一直在使用计时器repeatCount,但不能完全正确。任何人都可以帮我尝试重新说出我下面的内容,以便它只执行一次。
<bean id="sourceSql" class="org.apache.camel.component.sql.SqlComponent">
<property name="dataSource" ref="sourceDataSource"/>
</bean>
<bean id="targetSql" class="org.apache.camel.component.sql.SqlComponent">
<property name="dataSource" ref="targetDataSource"/>
</bean>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<propertyPlaceholder location="classpath:sql.properties" id="placeholder"/>
<route id="processProduct-route">
<description>route that process the orders by picking up new rows from the database
and when done processing then update the row to mark it as processed</description>
<from uri="sourceSql:{{sql.selectProduct}}"/>
<to uri="targetSql:{{sql.insertProduct}}"/>
<log message="${body}"/>
</route>
提前致谢
答案 0 :(得分:6)
您可以停止路线的路线,请参阅:http://camel.apache.org/how-can-i-stop-a-route-from-a-route.html
虽然在Camel 2.11之后,您也可以向控制总线端点发送消息,这可以更简单。因此,您可以在路径的endp发送到此端点。
<route id="processProduct-route">
<description>route that process the orders by picking up new rows from the database
and when done processing then update the row to mark it as processed</description>
<from uri="sourceSql:{{sql.selectProduct}}"/>
<to uri="targetSql:{{sql.insertProduct}}"/>
<log message="${body}"/>
<to uri="controlbus:route?routeId=processProduct-route&action=stop&async=true"/>
</route>