Spring集成网关"Dispatcher没有订阅者"

Che*_*tah 10 spring-integration

我得到了一个例外Dispatcher has no subscribers,outboundChannel无法弄清楚原因.我确信它很简单,我已将我的代码删除到下面的一个非常简单的示例:

我的背景是:

<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>
Run Code Online (Sandbox Code Playgroud)

我的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());
    }
}
Run Code Online (Sandbox Code Playgroud)

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

Gar*_*ell 6

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

添加<queue/>outboundChannel.

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