Spring集成网关“Dispatcher没有订阅者" [英] Spring integration gateway "Dispatcher has no subscribers"

查看:16
本文介绍了Spring集成网关“Dispatcher没有订阅者"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 outboundChannel 上遇到异常 Dispatcher has nosubscribes 并且无法弄清楚原因.我确信它很简单,我已经将我的代码剥离到下面的一个非常简单的示例中:

I am getting an exception Dispatcher has no subscribers on the outboundChannel and can't figure out why. I am sure its something simple, I have stripped back my code to a very simple sample below:

我的背景是:

<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 代码是:

My Java code is:

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 实际上正在处理请求.

Note: A breakpoint does tell me that the RequestService is actually handling the request.

推荐答案

receive() 没有 args 需要回复频道是一个 PollableChannel文档.

receive() with no args needs the reply channel to be a PollableChannel See the documentation.

添加到 outboundChannel.

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

Alternatively, You could change your gateway method to be String sendAndReceive(String in) and all will work as expected (and you can even remove the outboundChannel altogether).

这篇关于Spring集成网关“Dispatcher没有订阅者"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆