发布
社区首页 >问答首页 >如何正确地将变量传递给Mule JDBC出站端点

如何正确地将变量传递给Mule JDBC出站端点
EN

Stack Overflow用户
提问于 2013-10-22 03:17:26
回答 1查看 1.7K关注 0票数 0

我试图将一个调用变量传递给动态jdbc查询,但没有成功。如果我在查询中用硬编码的整数(即: 1)替换变量salesforcecontactcount,它就能正常工作。在调试时,如果我在查询上放置一个断点,它将显示变量正在正确填充。我没有收到任何错误,查询只是没有运行。对我做错了什么有什么建议吗?

我检查了数据库日志,当我硬编码payloadsize的值时,查询就会被删除,但是当我使用#变量:salesforcecontactcount时,查询不会被传递给服务器,尽管驱动程序确实连接了,但它只是没有发送任何内容。

在查看调试输出时,我在使用变量时看到如下内容:

代码语言:javascript
代码运行次数:0
复制
DEBUG 2013-10-22 00:44:58,048 [[salesforce_integration].dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.PreparedSqlCommandExecutor: Preparing batch for: INSERT INTO internal_request_history (executedon, source, type, payload, payloadsize) VALUES (now(), 'salesforce', 'contact', '', ?);
DEBUG 2013-10-22 00:44:58,048 [[salesforce_integration].dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.PreparedSqlCommandExecutor: Executing batch for: INSERT INTO internal_request_history (executedon, source, type, payload, payloadsize) VALUES (now(), 'salesforce', 'contact', '', ?);
DEBUG 2013-10-22 00:44:58,048 [[salesforce_integration].dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.PreparedSqlCommandExecutor: Command executed successfully: INSERT INTO internal_request_history (executedon, source, type, payload, payloadsize) VALUES (now(), 'salesforce', 'contact', '', ?);

当我硬编码该值时,调试输出是:

代码语言:javascript
代码运行次数:0
复制
DEBUG 2013-10-22 00:48:16,186 [[salesforce_integration].dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.PreparedSqlCommandExecutor: Filling input parameters for: INSERT INTO internal_request_history (executedon, source, type, payload, payloadsize) VALUES (now(), 'salesforce', 'contact', '', 9);
DEBUG 2013-10-22 00:48:16,186 [[salesforce_integration].dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.PreparedSqlCommandExecutor: SQL: INSERT INTO internal_request_history (executedon, source, type, payload, payloadsize) VALUES (now(), 'salesforce', 'contact', '', 9); input params: []
DEBUG 2013-10-22 00:48:16,186 [[salesforce_integration].dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.PreparedSqlCommandExecutor: Registering output parameters for: INSERT INTO internal_request_history (executedon, source, type, payload, payloadsize) VALUES (now(), 'salesforce', 'contact', '', 9);
DEBUG 2013-10-22 00:48:16,186 [[salesforce_integration].dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.PreparedSqlCommandExecutor: Executing update: INSERT INTO internal_request_history (executedon, source, type, payload, payloadsize) VALUES (now(), 'salesforce', 'contact', '', 9);
DEBUG 2013-10-22 00:48:16,188 [[salesforce_integration].dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.PreparedSqlCommandExecutor: Command executed successfully: INSERT INTO internal_request_history (executedon, source, type, payload, payloadsize) VALUES (now(), 'salesforce', 'contact', '', 9);

以下是相关代码:

代码语言:javascript
代码运行次数:0
复制
<message-properties-transformer scope="invocation" doc:name="Store Retrieved Objects">
  <add-message-property key="salesforcecontactcount" value="#[payload.size()]"/>
</message-properties-transformer>

<jdbc-ee:outbound-endpoint exchange-pattern="request-response" queryKey="logRequestHistory"  queryTimeout="-1" connector-ref="aclu_ads_db" doc:name="Log the Request">
  <jdbc-ee:query key="logRequestHistory" value="INSERT INTO internal_request_history (executedon, source, type, payload, payloadsize) VALUES (now(), 'salesforce', 'contact', '', #[variable:salesforcecontactcount]);  "/>
</jdbc-ee:outbound-endpoint>

<logger message="count: #[salesforcecontactcount]" level="INFO" doc:name="LoggerMessage"></logger>

编辑: OK,我想我离答案越来越近了,如果我将查询更改为SELECT而不是INSERT,那么传递给它的参数很好:

代码语言:javascript
代码运行次数:0
复制
<jdbc-ee:query key="logRequestHistory" value="SELECT * FROM internal_request_history WHERE payloadsize = #[variable:salesforcecontactcount];"/>

ADDITIONALEDIT:如果执行存储过程,就会得到与insert相同的“非结果”和相同的调试模式:

代码语言:javascript
代码运行次数:0
复制
<jdbc-ee:outbound-endpoint exchange-pattern="one-way" queryKey="logRequestHistory"  queryTimeout="-1" connector-ref="aclu_ads_db" doc:name="Log the Request">
   <jdbc-ee:query key="logRequestHistory" value="CALL create_log('salesforce', 'contact', #[variable:salesforcecontactcount]);" />
</jdbc-ee:outbound-endpoint>

    DEBUG 2013-10-22 06:55:00,576 [[salesforce_integration].aclu_ads_db.dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.CallableSqlCommandExecutor: Preparing batch for: { CALL create_log('salesforce', 'contact', ?); }
    DEBUG 2013-10-22 06:55:00,576 [[salesforce_integration].aclu_ads_db.dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.CallableSqlCommandExecutor: Executing batch for: { CALL create_log('salesforce', 'contact', ?); }
    DEBUG 2013-10-22 06:55:00,577 [[salesforce_integration].aclu_ads_db.dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.CallableSqlCommandExecutor: Command executed successfully: { CALL create_log('salesforce', 'contact', ?); }
    DEBUG 2013-10-22 06:55:00,577 [[salesforce_integration].aclu_ads_db.dispatcher.01] com.mulesoft.mule.transport.jdbc.sqlstrategy.BatchUpdateSqlStatementStrategy: Batch duration: 0.006

如果我硬编码对数据库的调用,这就是调试的结果:

代码语言:javascript
代码运行次数:0
复制
DEBUG 2013-10-22 07:10:47,067 [[salesforce_integration].aclu_ads_db.dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.CallableSqlCommandExecutor: Filling input parameters for: { CALL create_log('salesforce', 'contact', 5) }
DEBUG 2013-10-22 07:10:47,068 [[salesforce_integration].aclu_ads_db.dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.CallableSqlCommandExecutor: SQL: { CALL create_log('salesforce', 'contact', 5) } input params: []
DEBUG 2013-10-22 07:10:47,068 [[salesforce_integration].aclu_ads_db.dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.CallableSqlCommandExecutor: Registering output parameters for: { CALL create_log('salesforce', 'contact', 5) }
DEBUG 2013-10-22 07:10:47,068 [[salesforce_integration].aclu_ads_db.dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.CallableSqlCommandExecutor: Executing: { CALL create_log('salesforce', 'contact', 5) }
DEBUG 2013-10-22 07:10:47,069 [[salesforce_integration].aclu_ads_db.dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.CallableSqlCommandExecutor: Command executed successfully: { CALL create_log('salesforce', 'contact', 5) }
DEBUG 2013-10-22 07:10:47,069 [[salesforce_integration].aclu_ads_db.dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.CallableSqlCommandExecutor: Processing resultSets for: { CALL create_log('salesforce', 'contact', 5) }
DEBUG 2013-10-22 07:10:47,069 [[salesforce_integration].aclu_ads_db.dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.CallableSqlCommandExecutor: Processed resultsets: 0
DEBUG 2013-10-22 07:10:47,070 [[salesforce_integration].aclu_ads_db.dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.CallableSqlCommandExecutor: Processing output parameters for: { CALL create_log('salesforce', 'contact', 5) }
DEBUG 2013-10-22 07:10:47,070 [[salesforce_integration].aclu_ads_db.dispatcher.01] com.mulesoft.mule.transport.jdbc.sqlstrategy.ExecuteSqlStatementStrategy: Obtained result: {}

我认为问题归结于所谓的战略。如何阻止查询使用BatchUpdateSqlStatementStrategy?

EN

回答 1

Stack Overflow用户

发布于 2016-02-26 08:34:03

@AlexGad -确实,这是Mule-EE的一个问题,我注意到Mule-CE工作得很好。

当您使用ArrayList有效负载调用jdbc:出站端点但在SQL查询中使用会话/调用变量作为参数时,我注意到它对所讨论的表(没有插入/更新)没有任何影响,但是记录器记录“记录更新”。将此jdbc调用的有效负载更改为其他类型的对象解决了这个问题。要保持开放的心态,请考虑:通过-passing SQL查询参数而不是通过-consider消息丰富器。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19508378

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档