1
votes

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.

  1. Gateway reply-channel is "bestQuoteResponseChannel".
  2. 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"/>
2

2 Answers

0
votes

First of all for such a scenario you don't need a reply-channel on a gateway and therefore you don't need that output-channel on the service activator. All the reply logic should land on the replyChannel header which is always populated by the framework when gateway method is called.

It would be great to see what your findBestQuoteService.findBestQuote does since the LoanQuoteAggregator does everything for us already:

/**
 * 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;
}

So, what is the point of your custom service thereafter?

Also consider to turn on DEBUG level for the org.springframework.integration category to see how your messages are traveling. Possibly we will see some issue in logs, too.

I don't see how your logic could lose a replyChannel header, but we need more info to investigate.

0
votes

I had scatter-gather in the spring-integration flow before it sends reply to the Gateway. That was somehow was preventing it to send the response to Gateway.

Changes made: I replaced scatter-gather component with the publish-subscribe channel and aggregator combination. It worked fine after this change.

https://docs.spring.io/spring-integration/docs/5.3.0.M1/reference/html/scatter-gather.html#scatter-gather-namespace