0

这是一个来自 mysql 服务器的简单选择语句,并在控制台上显示输出。尽管我没有使用任何计时器,但结果却以某种方式循环打印。

<beans>
<context:component-scan base-package="com.java"/>
<bean destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource" id="dataSource">
<property value="com.mysql.jdbc.Driver" name="driverClassName"/>
<property value="jdbc:mysql://localhost:3306/world" name="url"/>
<property value="root" name="username"/>
<property value="mysql" name="password"/>
</bean>
<!-- configure the Camel SQL component to use the JDBC data source -->
<bean class="org.apache.camel.component.sql.SqlComponent" id="sql">
<property name="dataSource" ref="dataSource"/>
</bean>
<camel:camelContext>
<camel:route>
<camel:from uri="sql:select id from city where countryCode='AFG' and district ='Kabol' "/>
<camel:log message="${body[id]}"/>
<camel:to uri="stream:out"/>
</camel:route>
</camel:camelContext>
</beans>

客户端代码为:

public static void main(String rgs[]) throws InterruptedException{
        PropertyConfigurator.configure("C:/Users/payal.bansal/workspace/CamelOneProject/src/resources/log4j.properties"); 
        //AbstractApplicationContext ctx= new ClassPathXmlApplicationContext("resources/camel-configThree.xml");
        AbstractApplicationContext ctx= new ClassPathXmlApplicationContext("resources/camel-configEight.xml");
         Thread.sleep(5000);
         ctx.close();
    }
4

1 回答 1

0

默认情况下,from SQL 将每 500 毫秒重复一次 SQL 调用(其计划)。

如果您希望 SQL 只触发一次,请使用计时器

from timer
to sql

并将计时器配置为只运行一次。

于 2016-02-03T10:02:06.480 回答