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

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

问题描述

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

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

但是当我像这样插入后尝试从标题中获取数据时...

<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 来插入.有谁知道可能出了什么问题?

我附上了一些来自跟踪的示例输出...

2013-09-04,21:11:55.615,MacBook-local >>>(processProduct-route) from(sourceSql://SELECT%20TOP%205%20product_id%20FROM%20product_) -->日志[SELECT,${header.CamelSqlQuery},${header.CamelSqlRowCount}] <<<模式:InOnly,标题:{breadcrumbId=MacBook-local},BodyType:org.springframework.util.LinkedCaseInsensitiveMap,Body:{product_id=273}2013-09-04,21:11:55.625,MacBook 本地 >>>(processProduct-route) log[SELECT,${header.CamelSqlQuery},${header.CamelSqlRowCount}] -->多播<<<模式:InOnly,标题:{breadcrumbId=MacBook-local},BodyType:org.springframework.util.LinkedCaseInsensitiveMap,Body:{product_id=273}2013-09-04,21:11:55.644,MacBook 本地 >>>(processProduct-route) from(sourceSql://SELECT%20TOP%205%20product_id%20FROM%20product_) -->targetSql://insert%20into%20conv_stg_product_%20(product_id)%20values%20(:%23product_id) <<模式:InOnly,标题:{breadcrumbId=MacBook-local},BodyType:org.springframework.util.LinkedCaseInsensitiveMap,Body:{product_id=273}2013-09-04,21:11:55.646,MacBook 本地 >>>(processProduct-route) from(sourceSql://SELECT%20TOP%205%20product_id%20FROM%20product_) -->日志[INSERT,CONV_STG,${header.CamelSqlQuery},${header.CamelSqlUpdateCount}] <<<模式:InOnly,标题:{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_) -->日志[INSERT,CONV_ORIG,${header.CamelSqlQuery},${header.CamelSqlUpdateCount}] <<<模式:InOnly,标题:{breadcrumbId=MacBook},BodyType:org.springframework.util.LinkedCaseInsensitiveMap,Body:{product_id=273}

这里是sql语句的样子...

sql.selectProduct=SELECT TOP 5 product_id FROM product_sql.insertProductOrig=插入 conv_orig_product_ (product_id) 值 (:#product_id)

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

<依赖><groupId>net.sourceforge.jtds</groupId><artifactId>jtds</artifactId><version>1.3.0</version></依赖><!-- MySQL 数据库驱动程序--><依赖><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.9</version></依赖>

谢谢

解决方案

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

<块引用>

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

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

因此删除多播并使用直管道.

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

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"/> 

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}

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)

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>

thanks

解决方案

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}

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

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

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