消息模板接收给出Dispatcher没有频道

时间:2018-03-21 15:51:04

标签: spring-integration

这是我的spring-integration入站和出站,从终点获取列表。

<http:inbound-gateway id="webListGateway"
        request-channel="fromWeb_List" 
        reply-channel="toWeb_List" 
        path="/api/profile/V1/get"
        supported-methods="GET">
       <http:header name="container" expression="#pathVariables.container"/>
       <http:header name="groupName" expression="#pathVariables.groupName"/>
       <http:header name="userId" expression="#pathVariables.userId"/>
      </http:inbound-gateway>

    <int:header-enricher input-channel="fromWeb_List" output-channel="toCloud_List">
        <int:header name="apikey" value=“1234”/>
    </int:header-enricher>

    <http:outbound-gateway id="profileListGateway"
        request-channel="toCloud_List"
        reply-channel="sync_preferences"
        url=“localhost:8081/containers/{container}/groups/{groupName}/values/hierarchy/{userId}"
        http-method="GET"
        expected-response-type="java.lang.String"
        charset="UTF-8"
        extract-request-payload="false"
        header-mapper="headerMapper"
        encode-uri="true" >
        <http:uri-variable name="container" expression="headers.container"/>
        <http:uri-variable name="groupName" expression="headers.groupName"/>
        <http:uri-variable name="userId" expression="headers.userId"/>
    </http:outbound-gateway>

这是我的收件人列表路由器,它将列表发送回请求者,并将列表保存在另一个端点。

<int:recipient-list-router id="syncRouter" input-channel="sync_preferences">
     <int:recipient channel="toWeb_List"/>
    <int:recipient channel="toCloud_Save"/>
</int:recipient-list-router>

我也试图从java代码调用出站网关,并尝试通过在MessageTemplate上使用receive方法从toWeb_List通道获取​​响应,这给了我错误

MessagingTemplate template = new MessagingTemplate();
        Message<String> message1 = MessageBuilder.withPayload("")
                .setHeader("container", “fwd”)
                .setHeader("groupName", “foo”)
                .setHeader("userId", “user”)
                .build();
        template.send((MessageChannel) CONTEXT.getBean("fromWeb_List"),message1);
        PreList pre = (PreList) template.receive((MessageChannel)CONTEXT.getBean("toWeb_List"));

错误

Dispatcher has no subscribers for channel 'application:springboot.toWeb_List'

任何想法我在这里做错了什么。

1 个答案:

答案 0 :(得分:1)

您无法将DirectChannel用于MessagingGateway.receive()

protected final Message<?> doReceive(MessageChannel channel, long timeout) {
    Assert.notNull(channel, "MessageChannel is required");
    Assert.state(channel instanceof PollableChannel, "A PollableChannel is required to receive messages");

另一个问题是reply-channel="toWeb_List"必须在入站网关中注册为correlator以便能够接收消息,正如Gary指出的那样。这是在第一次请求时按需完成的。这就是你得到的原因 Dispatcher has no subscribers

真的,拜托,试着解释一下你想做什么。

<强>更新

如果您要从HTTP Inbound和其他类似的请求 - 回复地点重用<int:recipient-list-router>,您应该考虑放弃reply-channel的使用并仅依赖replyChannel 1}}在标题中。

我的意思是可以有toWeb_List通道bean定义,但不应该使用reply-channel。在这种情况下,您的配置应如下所示:

<int:recipient-list-router id="syncRouter" input-channel="sync_preferences">
     <int:recipient channel="toWeb_List"/>
    <int:recipient channel="toCloud_Save"/>
</int:recipient-list-router>

<int:bridge input-channel="toWeb_List"/>

bridge是将消息从输入通道转移到输出通道(如果存在)的组件。否则,它会MessageHeaders查询replyChannel值。当您直接从Java调用时,这是通过那些入站请求 - 回复组件(例如<http:inbound-gateway>或普通<int:gateway>)完全填充的。

请参阅Reference Manual

中的详细信息