【问题标题】:Apache Camel select then insertApache Camel 选择然后插入
【发布时间】:2013-08-29 09:44:27
【问题描述】:

我对 Apache Camel 非常陌生,我希望创建一个简单的应用程序,它从 mysql db 1 读取 200 个产品,然后将产品插入 mysql db 2。不需要更改数据,它只是一个一次批量选择,然后批量插入。

我一直在查看使用 sql 组件的 camel-sql-example 项目。我喜欢它的结构方式,所以我尝试以这个示例项目为基础。

谁能帮我找到一个很好的例子,或者给我一个粗略的指示我的骆驼路线(春天原型)应该是什么样子?

这样的事情正确吗?

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
          http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

  <bean id="sourceDataSource" class="org.apache.commons.dbcp.BasicDataSource">
    ...
  </bean> 

  <bean id="targetDataSource" class="org.apache.commons.dbcp.BasicDataSource">
    ...
  </bean>     

  <!-- configure the Camel SQL component to use the JDBC data source -->
  <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>

  <bean id="productBean" class="org.apache.camel.example.sql.ProductBean"/>

  <camelContext xmlns="http://camel.apache.org/schema/spring">
    <propertyPlaceholder location="classpath:sql.properties" id="placeholder"/>

    <route id="processProduct-route">
        <from uri="sourceSql:{{sql.selectProduct}}"/>
        <to uri="targetSql:{{sql.insertProduct}}"/>
        <log message="${body}"/>
    </route>
</camelContext>

谢谢

【问题讨论】:

    标签: sql database apache-camel


    【解决方案1】:

    我今天对此进行了测试,我上面指定的内容似乎有效!我没想到的是,这条路线只是循环并继续运行多次。我只需要它运行一次。我正在研究如何实现这一目标。

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-01
    • 2018-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-25
    • 2023-03-26
    相关资源
    最近更新 更多