Spring 集成 JMS 入站网关回复通道没有订阅者

Spring Integration JMS Inbound Gateway reply channel has no subscriber

我在 Spring Integration 5.1.3 中测试了 JMS Inbound Gateway

但是我得到如下错误:

Caused by: org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:138) ~[spring-integration-core-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:105) ~[spring-integration-core-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:73) ~[spring-integration-core-5.1.3.RELEASE.jar:5.1.3.RELEASE]

POM:

<dependencies>
    <dependency>
        <groupId>org.springframework.integration</groupId>
        <artifactId>spring-integration-jms</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-activemq</artifactId>
    </dependency>
</dependencies>

我将入站网关配置如下:

@Bean
JmsInboundGateway jmsInboundGateway(
    MessageChannel errorChannel,
    ConnectionFactory connectionFactory,
    DetailJmsProperties properties) {

    final Listener listener = properties.getListener();

    return Jms
        .inboundGateway(connectionFactory)
        .destination("request-queue")
        .requestChannel("inputChannel")
        .replyChannel("outputChannel")
        .defaultReplyQueueName("response-queue")
        .get();
}

还有,服务激活器:

@ServiceActivator(inputChannel = "inputChannel", outputChannel = "outputChannel")
public String process(String request) {
    String response = null;

    try {
        LOGGER.info("Received message content: [{}]", request);
        response = request + " was processed";
    }
    catch (Exception e) {
        LOGGER.error("Error", e);
    }

    return response;
}

顺便说一下,只有当我在 Service Activator 中删除 outputChannel = "outputChannel" 时它才有效。

这个问题有什么解释吗,我有什么误解吗?

您不能像那样使用 DSL 工厂 (Jms),它们旨在用于 DSL 流程

@Bean
IntegrationFLow flow()
    return IntegrationFlows.from(jmsInboundGateway())
            .handle("service", "process")
            .get();

DSL 处理完成所有布线。

它在没有通道的情况下工作,因为没有输出通道的组件将回复路由到 replyChannel header。

如果您不想使用 DSL,则必须将入站网关直接连接为 bean,而不是使用 Jms 工厂。