【问题标题】:Best way to deal with a stored procedure that's doesn't return any result处理不返回任何结果的存储过程的最佳方法
【发布时间】:2017-03-17 10:46:34
【问题描述】:

我在我的项目中使用 Spring Integration。我有一个存储过程,它插入一行并且不返回任何结果。如果我使用int-jdbc:stored-proc-outbound-gateway,流程只会终止并且不会连接到下一个频道。

DEBUG [org.springframework.jdbc.core.JdbcTemplate.doInCallableStatement] CallableStatement.execute() returned 'false'   
DEBUG [org.springframework.jdbc.core.JdbcTemplate.doInCallableStatement] CallableStatement.getUpdateCount() returned 0  
DEBUG [org.springframework.jdbc.core.JdbcTemplate.extractReturnedResults] CallableStatement.getUpdateCount() returned -1

我的要求是即使存储过程没有返回任何结果,也要继续流程。最好的处理方法是什么?

更新

在Artem响应后,我已经通过以下方式配置了存储过程出站通道适配器:

<int:service-activator  ref="msgHandler" method="buildRequestBasedDataSource" input-channel="PQPutUserBAInformation-SPCall2" output-channel="PQPutUserBAInformation-publishSubscribeChannel"/>
    <!-- PQPutUserBAInformation Channel -->

        <int:publish-subscribe-channel id="PQPutUserBAInformation-publishSubscribeChannel"  />

        <int-jdbc:stored-proc-outbound-channel-adapter
                        id="PQPutUserBAInformation-AWD-StoredProcedure2" 
                        channel="PQPutUserBAInformation-publishSubscribeChannel" 
                        data-source="routingDataSource" 
                        stored-procedure-name="ZSPPQINSERTUSERIDBA"
                        ignore-column-meta-data="true"  
                        use-payload-as-parameter-source = "false" >

                        <int-jdbc:sql-parameter-definition name="P_USERID" direction="IN" type="VARCHAR" />

                        <int-jdbc:parameter name="P_USERID" expression="#xpath(payload, '//CurrentUserID')" />
        </int-jdbc:stored-proc-outbound-channel-adapter>

        <!-- Service Activator to build the Message from the Stored Procedure ResultSet -->
    <int:service-activator input-channel="PQPutUserBAInformation-publishSubscribeChannel" ref="msgHandler" method="buildMessageFromExtSysResponse" />       

【问题讨论】:

  • 重复问题。看这里。我问了同样的事情:) stackoverflow.com/questions/42676147/…
  • 如果我的存储过程在插入记录的过程中失败了,那么我需要错误信息。所以,在这种情况下,你的问题可能对我没有帮助。
  • 您是否在存储过程中发现异常并吞下它?您应该能够将 oracle 异常传播回网关,然后使用错误通道。这就是我为我的错误所做的。
  • 我明白你的意思。我正在以任何方式处理错误。你能告诉我你是如何配置publish-subscribe-channel的吗?
  • 我使用的是直接渠道。然而,spring 集成示例 github 应该有很多关于 pub sub 的示例。我发现返回一个用于更新存储过程操作的布尔值或在这种情况下表示执行的删除次数的整数值也是一个很好的设计。

标签: spring-integration


【解决方案1】:

考虑改用stored-proc-outbound-channel-adapter

要在之后继续流程,您应该考虑使用 publish-subscribe-channel 作为该适配器的输入。并让更多订阅者在信息流中继续前进。

实现相同行为的另一种方法是recipient-list-router

【讨论】:

  • 抱歉,我的回复延迟了。这些天我都在度假。我添加了int-jdbc:stored-proc-outbound-channel-adapterint:publish-subscribe-channel,但我遇到了异常,java.lang.IllegalArgumentException: An output channel was provided, but the final handler in the chain does not implement the MessageProducer interface.
  • 你没有告诉我们你使用chain。当然,如果你要使用 Outbound 通道适配器,你必须打破它
  • outbound-channel-adapter 是单向的。没有output。这是任何outbound-channel-adapter 的规则。流动在这里完全停止。如果您的过程有时会返回结果,则在 stored-proc-outbound-channel-adapter 中会忽略它。
  • 你可以在这里找到一些关于存储过程的示例:github.com/spring-projects/spring-integration-samples/tree/…
  • 是的!现在很好。而且您通过publish-subscribe-channel 和第二个订阅者的“程序后处理”也是正确的。请记住,相同的消息将被发送到第二个`, that has been sent to the stored-proc adapter. That is nature of the publish-subscribe-channel`。在 EIP 书籍和 Spring 集成参考手册中查看更多信息。
猜你喜欢
  • 1970-01-01
  • 2021-03-22
  • 2011-05-16
  • 2016-08-06
  • 1970-01-01
  • 1970-01-01
  • 2015-09-29
  • 2015-06-19
相关资源
最近更新 更多