gpt4 book ai didi

java - Spring 集成服务激活器不发送空回复

转载 作者:搜寻专家 更新时间:2023-11-01 02:37:38 27 4
gpt4 key购买 nike

我有一个非常简单的集成流程:

    <int:gateway id="integrationGateway"
service-interface="com.wheeler.fits.returns.messaging.MessagingGateway"
default-request-channel="transactionMatcher">
<int:method name="publishReturnedTransaction" request-channel="transactionMatcher"/>
</int:gateway>

<int:channel id="transactionMatcher"/>
<int:service-activator input-channel="transactionMatcher" requires-reply="true">
<bean class="com.wheeler.fits.returns.domain.MatchTransactionToOriginal">
<constructor-arg ref="achTransactionMapper"/>
<constructor-arg ref="bankTransactionDao"/>
<constructor-arg ref="clientMapper"/>
<constructor-arg ref="oldAchTransactionMapper"/>
</bean>
</int:service-activator>

服务激活器正在调用的方法尝试将消息中的数据与数据库中的某些数据进行匹配。如果是,则返回匹配的数据。如果没有,它将返回 null

如果我不设置 required-reply=truenull 回复似乎会从集成流程中消失,导致服务接口(interface)永远不会返回,从而导致要挂起的应用程序。如果我确实设置了 required-reply=true,我至少得到了一个异常,但应用程序仍然挂起,因为网关的服务接口(interface)永远不会返回:

[org.springframework.integration.handler.ReplyRequiredException: No reply produced by handler 'org.springframework.integration.config.ServiceActivatorFactoryBean#0', and its 'requiresReply' property is set to true.,

在 spring 集成引用资料的任何地方似乎都没有记录这种行为。我希望我的服务激活器将 null 传递回网关,以便网关可以使用 null 进行回复。

这是我的网关服务接口(interface):

public interface MessagingGateway {

RawMessageData publishReturnedTransaction(ReturnedTransactionData returnedTransactionData) throws ChannelPublishException;
}

如何让它像处理任何其他消息一样处理 null

最佳答案

Service Activator 中有一些关于此事的信息章节:

The Service Activator is one of those components that is not required to produce a reply message. If your method returns null or has a void return type, the Service Activator exits after the method invocation, without any signals. This behavior can be controlled by the AbstractReplyProducingMessageHandler.requiresReply option, also exposed as requires-reply when configuring with the XML namespace. If the flag is set to true and the method returns null, a ReplyRequiredException is thrown.

您还可以在 JIRA 中找到一些讨论.

一般来说,null 有效负载在消息传递中没有意义,必须像 ReplyRequiredException 一样被视为终端信号或错误。

对于您的用例,您应该考虑从您的服务激活器返回一些 RawMessageData 实例,您可以将其视为 null

关于java - Spring 集成服务激活器不发送空回复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43524745/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com