spring-integration - Spring 集成网关 "Dispatcher has no subscribers"

标签 spring-integration

我遇到异常 Dispatcher has no subscribersoutboundChannel并且不知道为什么。我确信它很简单,我已经将我的代码剥离到下面的一个非常简单的示例中:

我的上下文是:

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

最佳答案

receive()没有参数需要回复 channel 是 PollableChannelthe documentation .

添加 <queue/>outboundChannel .

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

关于spring-integration - Spring 集成网关 "Dispatcher has no subscribers",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23696630/

相关文章:

java - 我可以向 jms :listener-container? 注入(inject)一些东西吗

java - Spring IntegrationFlow 过滤器和转换

java - 如何在java dsl中设置消息驱动的入站适配器的恢复间隔?

spring-batch - 带重试的 sftp channel 出站适配器

Java Spring 集成邮件 - IllegalArgumentException : 'taskScheduler' must not be null

java - Spring Integration 如何与 Web 服务( Jersey )交互?

java - 如何在 Spring Integration 中的异常路由器中使用根本原因异常类型

spring-batch - Spring Batch - Web 服务到 Web 服务分块

spring-integration - Spring Integration 同步/异步消息流