Min
Min

Reputation: 352

Spring Integration JMS Inbound Gateway reply channel has no subscriber

I have test with JMS Inbound Gateway in Spring Integration 5.1.3 enter image description here

But I got error as following:

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>

I configure the Inbound Gateway as following:

@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();
}

And, the Service Activator:

@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;
}

By the way, it works only if I remove outputChannel = "outputChannel" in Service Activator.

Is there any explanation for this issue, do I have any misunderstanding ?

Upvotes: 2

Views: 1190

Answers (1)

Gary Russell
Gary Russell

Reputation: 174554

You can't use DSL factories (Jms) like that, they are intended for use in a DSL flow

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

The DSL processing does all the wiring.

It works without the channel because a component without an output channel routes the reply to the replyChannel header.

If you don't want to use the DSL, you must wire up the inbound gateway directly as a bean instead of using the Jms factory.

Upvotes: 1

Related Questions