apache camel如何从sql-component获取标头属性 [英] apache camel how to get header attributes from sql-component

查看:155
本文介绍了apache camel如何从sql-component获取标头属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Apache Camel的新手,我一直想编写一个应用程序,该应用程序从一个数据库中获取数据并将其插入到另一个数据库中.我正在使用sql组件,并试图找出如何使用spring dsl从消息标头中抓取CamelSqlUpdateCount,CamelSqlRowCount和CamelSqlQuery.

I'm new to Apache Camel and I've stared to write an application that grabs data from one database and inserts it to another database. I'm using the sql component and am trying to figure out how to grab the CamelSqlUpdateCount, CamelSqlRowCount and CamelSqlQuery from the message header using spring dsl.

我知道我可以使用它来获取数据中的属性....

I know that I can get attributes in the data using this....

<log message="Processing product ${body[product_id]}"/>

但是当我尝试在插入后像这样从头文件中获取数据时...

But when I try to grab data from my header after my insert like this...

<from uri="sourceSql:{{sql.selectProduct}}"/>
<log message="SELECT,${header.CamelSqlQuery},${header.CamelSqlRowCount}" loggingLevel="INFO" logName="db_log"/>
<to uri="targetSql:{{sql.insertProductOrig}}"/>     
<log message="INSERT,CONV_ORIG,${header.CamelSqlQuery},${header.CamelSqlUpdateCount}" loggingLevel="INFO" logName="db_log"/> 

它又变空了.在获得有关在路由中打开跟踪以查看消息标题中返回的内容的建议之后,我可以看到那些标题属性不存在.我正在连接到sql server以进行选择,并插入mysql.有谁知道可能出什么问题了?

it comes back empty. After getting advice on turning on a trace in my route to see what is coming back in the message headers I can see that those header attributes are not there. I am connecting to sql server to select and mysql to insert. does anyone know what might be wrong?

我已经附加了跟踪的一些示例输出...

I've attached some sample output from the trace...

2013-09-04,21:11:55.615,MacBook-local >>> (processProduct-route) from(sourceSql://SELECT%20TOP%205%20product_id%20FROM%20product_) --> log[SELECT,${header.CamelSqlQuery},${header.CamelSqlRowCount}] <<< Pattern:InOnly, Headers:{breadcrumbId=MacBook-local}, BodyType:org.springframework.util.LinkedCaseInsensitiveMap, Body:{product_id=273}
    2013-09-04,21:11:55.625,MacBook-local >>> (processProduct-route) log[SELECT,${header.CamelSqlQuery},${header.CamelSqlRowCount}] --> multicast <<< Pattern:InOnly, Headers:{breadcrumbId=MacBook-local}, BodyType:org.springframework.util.LinkedCaseInsensitiveMap, Body:{product_id=273}
    2013-09-04,21:11:55.644,MacBook-local >>> (processProduct-route) from(sourceSql://SELECT%20TOP%205%20product_id%20FROM%20product_) --> targetSql://insert%20into%20conv_stg_product_%20(product_id)%20values%20(:%23product_id) <<< Pattern:InOnly, Headers:{breadcrumbId=MacBook-local}, BodyType:org.springframework.util.LinkedCaseInsensitiveMap, Body:{product_id=273}
    2013-09-04,21:11:55.646,MacBook-local >>> (processProduct-route) from(sourceSql://SELECT%20TOP%205%20product_id%20FROM%20product_) --> log[INSERT,CONV_STG,${header.CamelSqlQuery},${header.CamelSqlUpdateCount}] <<< Pattern:InOnly, Headers:{breadcrumbId=MacBook}, BodyType:org.springframework.util.LinkedCaseInsensitiveMap, Body:{product_id=273}
    2013-09-04,21:11:55.642,MacBook >>> (processProduct-route) from(sourceSql://SELECT%20TOP%205%20product_id%20FROM%20product_) --> log[INSERT,CONV_ORIG,${header.CamelSqlQuery},${header.CamelSqlUpdateCount}] <<< Pattern:InOnly, Headers:{breadcrumbId=MacBook}, BodyType:org.springframework.util.LinkedCaseInsensitiveMap, Body:{product_id=273}

这是sql语句的样子...

Here are what the sql statements look like...

sql.selectProduct=SELECT TOP 5 product_id FROM product_
sql.insertProductOrig=insert into conv_orig_product_ (product_id) values (:#product_id)

这里是我的POM的摘录,以显示我正在使用的jdbc驱动程序...

Here is an extract from my POM to show what jdbc drivers I am using...

<!-- SQL Server database driver -->
<dependency>
    <groupId>net.sourceforge.jtds</groupId>
    <artifactId>jtds</artifactId>
    <version>1.3.0</version>
</dependency>  

<!-- MySQL database driver -->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.9</version>
</dependency>

谢谢

推荐答案

这看起来像是最终用户问题.

This looks like an end user issue.

2013-09-04,21:11:55.625,MacBook-local >>> (processProduct-route) log[SELECT,${header.CamelSqlQuery},${header.CamelSqlRowCount}] --> multicast <<< Pattern:InOnly, Headers:{breadcrumbId=MacBook-local}, BodyType:org.springframework.util.LinkedCaseInsensitiveMap, Body:{product_id=273}

跟踪日志中的详细信息表明正在使用多播EIP(请参见上文).并且当您这样做时,多播会复制传入的消息(原始消息),并且每个接收者都会获得该原始"消息的副本.这样就可以解释为什么这些标头不存在,因为原始副本没有SQL更新标头.

The details from the trace logging indicates a multicast EIP is in use (see above). And when you do that then the multicast copied the incoming message (original message), and each receiver gets a copy of that "original" message. So that would explain why these headers is not there, as the original copy does not have the SQL update headers.

因此删除多播,只使用一条直线管道即可.

So remove the multicast and just use a straight pipeline.

您可以在此处阅读有关多播和管道的信息

You can read about multicast and pipeline here

  • http://camel.apache.org/multicast.html
  • http://camel.apache.org/pipes-and-filters.html

这篇关于apache camel如何从sql-component获取标头属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆