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

时间:2013-10-22 03:17:26

标签: jdbc mule

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

我检查了数据库日志,当我对payloadsize的值进行硬编码时,查询得到了解决,但是当我使用#[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];"/>

ADDITIONALEDIT:如果我执行存储过程,我会得到与插入相同的'非结果'和相同的调试模式:

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

1 个答案:

答案 0 :(得分:0)

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

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