【问题标题】:Spring integration gateway "Dispatcher has no subscribers"Spring集成网关“调度程序没有订阅者”
【发布时间】:2014-05-16 13:40:06
【问题描述】:

我在outboundChannel 上遇到异常Dispatcher has no subscribers,但不知道为什么。我确信它很简单,我已将我的代码剥离为下面的一个非常简单的示例:

我的上下文是:

<bean id="requestService"
    class="com.sandpit.RequestService" />

<integration:channel id="inboundChannel" />

<integration:service-activator id="service"
    input-channel="inboundChannel"
    output-channel="outboundChannel"
    ref="requestService"
    method="handleRequest" />

<integration:channel id="outboundChannel" />

<integration:gateway id="gateway"
    service-interface="com.sandpit.Gateway"
    default-request-channel="inboundChannel"
    default-reply-channel="outboundChannel" />

<bean class="com.sandpit.GatewayTester">
    <property name="gateway"
        ref="gateway" />
</bean>

我的 Java 代码是:

public interface Gateway {

    String receive();
    void send(String message);
}

public class RequestService {

    public String handleRequest(String request) {

        return "Request received: " + request;
    }
}

public class GatewayTester implements ApplicationListener<ContextRefreshedEvent> {

    private Gateway gateway;

    public void setGateway(Gateway gateway) {

        this.gateway = gateway;
    }

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {

        gateway.send("Hello world!");
        System.out.println("FROM SERVICE: " + gateway.receive());
    }
}

注意:断点确实告诉我 RequestService 实际上正在处理请求。

【问题讨论】:

    标签: spring-integration


    【解决方案1】:

    receive() 没有 args 需要回复通道是 PollableChannel 参见 the documentation

    &lt;queue/&gt; 添加到outboundChannel

    或者,您可以将网关方法更改为String sendAndReceive(String in),一切都会按预期工作(您甚至可以完全删除outboundChannel)。

    【讨论】:

    • 出于兴趣,我的实际代码中间有一个转换器。我认为这意味着我仍然需要outboundChannel,因为来自RequestService的转换是不同的。
    • 正确 - 但最终消费者可以简单地省略output-channel,它将返回网关(使用请求/回复时)。如果您正在使用异步(就像您一样),或者如果您想记录(或做其他事情)回复,您通常只需要回复通道。
    • 谢谢 - 这个回复回答了我的另一个问题。
    猜你喜欢
    • 2013-08-16
    • 2015-11-02
    • 2013-09-25
    • 1970-01-01
    • 2017-04-10
    • 2018-02-19
    • 2020-04-22
    • 1970-01-01
    • 2016-12-31
    相关资源
    最近更新 更多