0

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

我检查了数据库日志,当我对有效载荷大小的值进行硬编码时,查询会被执行,但是当我使用 #[variable:salesforcecontactcount] 时,尽管驱动程序确实连接了,但查询并没有传递到服务器,它只是没有不要发送任何东西。

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

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', '', ?);

当我对值进行硬编码时,调试输出为:

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);

以下是相关代码:

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

编辑:好的,我想我越来越接近答案了,如果我将查询更改为 SELECT 而不是 INSERT,它可以很好地与传入的参数一起工作:

<jdbc-ee:query key="logRequestHistory" value="SELECT * FROM internal_request_history WHERE payloadsize = #[variable:salesforcecontactcount];"/>

附加编辑:如果我执行存储过程,我会得到与插入相同的“非结果”和相同的调试模式:

<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

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

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?

4

1 回答 1

0

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

当您使用 ArrayList 有效负载调用 jdbc:outbound-endpoint 但在 SQL 查询中使用 SESSION/INVOCATION 变量作为参数时,我注意到它对相关表没有影响(无插入/更新),但记录器记录“记录已更新”。将此 jdbc 调用的有效负载更改为其他类型的对象解决了该问题。为了保持开放的心态,请考虑: - 通过有效负载传递 SQL 查询参数 - 考虑消息丰富器

于 2016-02-26T08:34:03.283 回答