问题
I've created/creating a simple Apache Camel program to move data from a source db to a target db. I have configured a route to do this and it works! The problem is that it just keeps executing the root every second or so. I only want it to execute once.
I've been playing around with the timer repeatCount but can't quite get the root right. Can anyone help me to try and re-word what i have below so that it only executes once.
<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>
Thanks in advance
回答1:
You can stop a route from a route, see: http://camel.apache.org/how-can-i-stop-a-route-from-a-route.html
Though in Camel 2.11 onwards you can also send a message to a controlbus endpoint which can be simpler. So you can send to this endpoint at the endp of the route.
<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>
来源:https://stackoverflow.com/questions/18544639/apache-camel-sql-component-how-to-execute-only-once