Spring Integration 没有输出通道或回复通道

Posted

技术标签:

【中文标题】Spring Integration 没有输出通道或回复通道【英文标题】:Spring Integration no output-channel or replyChannel 【发布时间】:2022-01-17 04:18:49 【问题描述】:

我正在处理一个场景,我必须在第一次调用中获取令牌,然后在第二次调用中验证该令牌。

我的 spring 集成文件看起来像

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:integration="http://www.springframework.org/schema/integration"
       xmlns:ws="http://www.springframework.org/schema/integration/ws"
       xmlns:http="http://www.springframework.org/schema/integration/http"
       xsi:schemaLocation="http://www.springframework.org/schema/integration/http http://www.springframework.org/schema/integration/http/spring-integration-http.xsd
       http://www.springframework.org/schema/integration/ws http://www.springframework.org/schema/integration/ws/spring-integration-ws.xsd
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd">

    <!-- Entry channel into this flow is ucipTopupChannel -->

    <integration:transformer id="ayobaSmsRequestTransformer"
                             input-channel="ayobaSMSChannel"
                             output-channel="ayobaSmsTransformerOutputChannel"
                             ref="ayobaSmsTransformer"
                             method="ayobaSmsRequestTransform" />

    <integration:channel id="ayobaSmsTransformerOutputChannel" />

    <integration:header-value-router id="ayobaSmsValidationRouter" input-channel="ayobaSmsTransformerOutputChannel" header-name="VALIDATION">
        <integration:mapping value="FAILED" channel="ayobaSmsValidationFailedChannel"  />
        <integration:mapping value="PASSED" channel="ayobaSmsValidationRouterOutputChannel" />
    </integration:header-value-router>

    <integration:channel id="ayobaSmsValidationFailedChannel" />

    <integration:service-activator input-channel="ayobaSmsValidationFailedChannel" ref="validationFailedServiceActivator" />

    <integration:channel id="ayobaSmsValidationRouterOutputChannel" />

    <integration:object-to-json-transformer id="ayobaJsonTransformer"
                                            input-channel="ayobaSmsValidationRouterOutputChannel"
                                            output-channel="ayobaJsonChannel"
                                            object-mapper="customObjectMapper"
                                            content-type="application/json" />

    <integration:channel id="ayobaJsonChannel" />

    <http:outbound-gateway id="ayobaSmsOutboundGateway"
                           extract-request-payload="true"
                           url-expression="headers['url']"
                           request-channel="ayobaJsonChannel"
                           reply-channel="ayobaSmsOutputChannel"
                           mapped-request-headers="contentType,ERSREFERENCE,Authorization"
                           expected-response-type="java.lang.String"
                           rest-template="ayobaRestTemplate" />

    <integration:transformer id="ayobaSmsResponseTransformer"
                             input-channel="ayobaSmsOutputChannel"
                             ref="ayobaSmsTransformer"
                             method="ayobaSmsResponseTransform" />

    <integration:channel id="ayobaSmsOutputChannel" />


</beans>

但现在我必须检查 tokenExpiry,我试图为其保存额外的通话,但我遇到了错误

原因:org.springframework.messaging.core.DestinationResolutionException:没有可用的 output-channel 或 replyChannel 标头

我的配置文件看起来像

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:integration="http://www.springframework.org/schema/integration"
       xmlns:ws="http://www.springframework.org/schema/integration/ws"
       xmlns:http="http://www.springframework.org/schema/integration/http"
       xsi:schemaLocation="http://www.springframework.org/schema/integration/http http://www.springframework.org/schema/integration/http/spring-integration-http.xsd
       http://www.springframework.org/schema/integration/ws http://www.springframework.org/schema/integration/ws/spring-integration-ws.xsd
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd">

    <!-- Entry channel into this flow is ucipTopupChannel -->

    <integration:transformer id="ayobaSmsRequestTransformer"
                             input-channel="ayobaSMSChannel"
                             output-channel="ayobaSmsTransformerOutputChannel"
                             ref="ayobaSmsTransformer"
                             method="ayobaSmsRequestTransform" />

    <integration:channel id="ayobaSmsTransformerOutputChannel" />

    <integration:header-value-router id="ayobaSmsValidationRouter" input-channel="ayobaSmsTransformerOutputChannel" header-name="VALIDATION">
        <integration:mapping value="FAILED" channel="ayobaSmsValidationFailedChannel"  />
        <integration:mapping value="PASSED" channel="ayobaSmsValidationRouterOutputChannel" />
        <integration:mapping value="CACHED" channel="ayobaSmsOutputChannel" />
    </integration:header-value-router>

    <integration:channel id="ayobaSmsValidationFailedChannel" />

    <integration:service-activator input-channel="ayobaSmsValidationFailedChannel" ref="validationFailedServiceActivator" output-channel="ayobaSmsOutputChannel" requires-reply="false" />

    <integration:channel id="ayobaSmsValidationRouterOutputChannel" />

    <integration:object-to-json-transformer id="ayobaJsonTransformer"
                                            input-channel="ayobaSmsValidationRouterOutputChannel"
                                            output-channel="ayobaJsonChannel"
                                            object-mapper="customObjectMapper"
                                            content-type="application/json" />


    <integration:channel id="ayobaJsonChannel1" />

    <http:outbound-gateway id="ayobaSmsOutboundGateway"
                           extract-request-payload="true"
                           url-expression="headers['url']"
                           request-channel="ayobaJsonChannel"
                           reply-channel="ayobaSmsOutputChannel"
                           mapped-request-headers="contentType,ERSREFERENCE,Authorization"
                           expected-response-type="java.lang.String"
                           rest-template="ayobaRestTemplate" />

    <integration:channel id="ayobaJsonChannel" />

    <http:outbound-gateway id="ayobaSmsOutboundGateway"
                           extract-request-payload="true"
                           url-expression="headers['url']"
                           request-channel="ayobaJsonChannel"
                           reply-channel="ayobaSmsOutputChannel"
                           mapped-request-headers="contentType,ERSREFERENCE,Authorization"
                           expected-response-type="java.lang.String"
                           rest-template="ayobaRestTemplate" />

    <integration:transformer id="ayobaSmsResponseTransformer"
                             input-channel="ayobaSmsOutputChannel"
                             ref="ayobaSmsTransformer"
                             method="ayobaSmsResponseTransform" />

    <integration:channel id="ayobaSmsOutputChannel" />


</beans>

现在,我很吃惊,因为对于最后一个频道ayobaSmsResponseTransformer,它在验证调用中工作正常并且不会出错,但对于我的缓存令牌调用,它会抛出异常。

【问题讨论】:

请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。 【参考方案1】:

你的

<integration:transformer id="ayobaSmsResponseTransformer"
                         input-channel="ayobaSmsOutputChannel"
                         ref="ayobaSmsTransformer"
                         method="ayobaSmsResponseTransform" />

没有output-channel 定义,因此当您从ayobaSmsValidationRouter 路由时,它会尝试解析邮件中不存在的replyChannel 标头。

您只显示了一个ayobaSmsRequestTransformer,但不清楚是什么向它的ayobaSMSChannel 发送消息。

也许你有一个&lt;gateway&gt; 在其方法上带有各自的消息合同。也许你有一个void 用于那个CACHED 令牌。从这里看,您似乎没有使用最新的 Spring Integration。

有关更多信息,请参阅文档:https://docs.spring.io/spring-integration/docs/current/reference/html/messaging-endpoints.html#gateway

从 5.4 版开始,当网关方法返回类型为 void 时,如果没有显式提供这样的标头,则框架会将 replyChannel 标头填充为 nullChannel bean 引用。这允许丢弃来自下游流的任何可能的回复,以满足单向网关合同。

并查看最新版本升级:https://spring.io/projects/spring-integration#learn

【讨论】:

以上是关于Spring Integration 没有输出通道或回复通道的主要内容,如果未能解决你的问题,请参考以下文章

测试 Spring-Integration 与订阅者通道

在 Spring Integration DSL 中使用带有丢弃通道的过滤器

Spring Integration DSL,从消息通道轮询

Spring Integration - 入站通道适配器执行下游通道并行处理

如何在 Spring Integration DSL 中为通道设置多个消息处理程序?

Spring Integration 的 XMPP 通道适配器