首页 \ 问答 \ 消息模板接收让Dispatcher没有订阅频道(Message Template receive gives Dispatcher has no subscribers for channel)

消息模板接收让Dispatcher没有订阅频道(Message Template receive gives Dispatcher has no subscribers for channel)

这是我的弹簧整合入站和出站,从终点获取列表。

<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方法来获取来自Web_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'

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


This is my spring-integration inbound and out bound which gets a list from a end point.

<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>

This is my recipient-list-router which send backs the list to requestor and also saves the list in another end point.

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

I am also trying to call the outbound gateway from java code and trying to get the response from toWeb_List channel by using receive method on MessageTemplate, which is giving me error

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"));

error

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

Any Idea what I am doing wrong here.


原文:https://stackoverflow.com/questions/49410896
更新时间:2022-05-23 07:05

最满意答案

您无法使用MessagingGateway.receive() DirectChannel

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");

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

真的,请尝试解释你想要做什么。

UPDATE

如果您打算从HTTP Inbound和其他类似的请求回复地点重复使用<int:recipient-list-router> ,则应考虑放弃reply-channel并仅依赖头中的replyChannel

我的意思是可以有这样的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>或plain <int:gateway>入站请求 - 回复组件完全填充。

查看参考手册中的更多信息。


You can't use DirectChannel for the 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");

Another issue that reply-channel="toWeb_List" has to be registered as correlator in the Inbound Gateway to be able to receive messages, as Gary pointed. And that is done on demand, on the first request. That's why you get that Dispatcher has no subscribers.

And really, please, try to explain what you would like to do.

UPDATE

If you are going to reuse that <int:recipient-list-router> from the HTTP Inbound and from some other similar request-reply place, you should consider to drop off usage of the reply-channel and just rely on the replyChannel in headers.

I mean there can be that toWeb_List channel bean definition, but should not use it from the reply-channel. In this case your config should be like this:

<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"/>

The bridge is such a components to shift message from input channel to the output one, if present. Otherwise it consults MessageHeaders for the replyChannel value. And this is is populated exactly via those Inbound request-reply components such as <http:inbound-gateway> or plain <int:gateway> when you call directly from Java.

See more information in the Reference Manual.

相关问答

更多