apache camel sql component - how to execute only once

浪尽此生 提交于 2019-12-24 08:39:35

问题


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&amp;action=stop&amp;async=true"/>
    </route>


来源:https://stackoverflow.com/questions/18544639/apache-camel-sql-component-how-to-execute-only-once

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!