spring - How to send response from a Gateway in spring-integration
问题描述
I'm following the sample below to implement spring-integration gateway.
Issue: Not able to get response on the Gateway which is sent from a service-activator.
- Gateway reply-channel is "bestQuoteResponseChannel".
- Service-activator writes to the same channel.
All the custom methods are executed and response is composed but never gets sent out. Any idea what's missing here? My configuration also has a scatter-gather in the flow.
<!--Gateway:-->
<channel id="bestQuoteResponseChannel"/>
<gateway id="loanBrokerGateway"
default-request-channel="loanRequestsChannel"
service-interface="org.springframework.integration.samples.loanbroker.LoanBrokerGateway">
<method name="getBestLoanQuote" reply-channel="bestQuoteResponseChannel">
<header name="RESPONSE_TYPE" value="BEST"/>
</method>
</gateway>
<chain input-channel="loanRequestsChannel">
<header-enricher>
<header name="creditScore" expression="@creditBureau.getCreditReport(payload).score"/>
</header-enricher>
<recipient-list-router apply-sequence="true">
<recipient selector-expression="headers.creditScore > 800" channel="exclusiveBankChannel"/>
<recipient selector-expression="headers.creditScore > 750" channel="premiereBankChannel"/>
<recipient selector-expression="headers.creditScore > 700" channel="qualityBankChannel"/>
<recipient selector-expression="headers.creditScore > 650" channel="friendlyBankChannel"/>
<recipient channel="easyBankChannel"/>
</recipient-list-router>
</chain>
<!-- Messages are sent to the banks via bank channels and will be received and processed by an aggregator -->
<aggregator input-channel="loanQuotesChannel" output-channel="input" method="aggregateQuotes">
<beans:bean class="org.springframework.integration.samples.loanbroker.LoanQuoteAggregator"/>
</aggregator>
<service-activator ref="findBestQuoteService" method="findBestQuote" input-channel="input" output-channel="bestQuoteResponseChannel"/>
解决方案
首先,对于这种情况,您不需要reply-channel
网关上的 a ,因此您不需要output-channel
在服务激活器上使用它。当调用网关方法时,所有回复逻辑都应该放在replyChannel
框架始终填充的标头上。
很高兴看到你findBestQuoteService.findBestQuote
做了什么,因为LoanQuoteAggregator
它已经为我们做了一切:
/**
* Aggregates LoanQuote Messages to return a single reply Message.
*
* @param quotes list of loan quotes received from upstream lenders
* @param responseType header that indicates the response type
* @return the best {@link LoanQuote} if the 'RESPONSE_TYPE' header value is 'BEST' else all quotes
*/
public Object aggregateQuotes(List<LoanQuote> quotes,
@Header(value="RESPONSE_TYPE", required=false) String responseType) {
Collections.sort(quotes);
return ("BEST".equals(responseType)) ? quotes.get(0) : quotes;
}
那么,此后您的定制服务有什么意义呢?
还可以考虑为该org.springframework.integration
类别打开 DEBUG 级别,以查看您的消息是如何传播的。可能我们也会在日志中看到一些问题。
我看不出您的逻辑如何丢失replyChannel
标题,但我们需要更多信息进行调查。
推荐阅读
- ios - 如何刷新collectionView
- angular - 如何以角度隐藏引导模式
- php - Wordpress - 我如何使用另一个函数获取当前的作者数据
- c# - 动态充电DLL时反射TargetInvocationException错误
- c# - 在第 n 个位置将 JObject 添加到 JArray
- javascript - Nativescript 检测 TextField 上的焦点更改 - 代码背后
- python - 如何从 Flask 中运行 python 脚本
- r - 计算一天内第一次失败后的所有观察结果
- php - 在每次点击时使用 ajax 调用将从 mysql 获取的数据插入 div
- css - 使用带有 SASS & 符号的 CSS 前缀选择器