How to fix "Dispatcher has no subscribers" error for a simple message producer?

2

I'm trying to create a simple JMS producer using Spring Integration. Can any one help me to explain why I'm getting "Dispatcher has no subscribers" error?

I'm using ActiveMQ locally and based on my ActiveMQ log, both queue and session are created when I run my test application. But there is no message comes in.

My spring-integration-config.xml

<bean id="jmsConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
        <property name="targetConnectionFactory">
            <bean class="org.apache.activemq.ActiveMQConnectionFactory">
                <property name="brokerURL" value="tcp://localhost:51515"/>
            </bean>
        </property>
        <property name="sessionCacheSize" value="10"/>
        <property name="cacheConsumers" value="false"/>
    </bean>

    <bean id="hwQueue" class="org.apache.activemq.command.ActiveMQQueue">
        <constructor-arg value="hello_world_channel"/>
    </bean>

    <integration:channel id="hwOutboundChannel"/>

    <jms:message-driven-channel-adapter id="hwOutboundAdapter" destination="hwQueue" connection-factory="jmsConnectionFactory"
                                        channel="hwOutboundChannel"/>

    <integration:gateway id="hwOutboundGateway" service-interface="com.veeva.mc.sisandbox.service.SiGateway"
                         default-request-channel="hwOutboundChannel"/>

SiGateway.java

public interface SiGateway {

    void send(String message);

}

Test code

@SpringBootApplication
@EnableIntegration
public class SiSandboxApplication implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(SiSandboxApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        AbstractApplicationContext context = new ClassPathXmlApplicationContext(
                "spring-integration-config.xml");

        SiGateway gateway = (SiGateway) context.getBean("hwOutboundGateway");
        gateway.send("Hello World");
        context.close();
    }
}

Error stack trace

2019-04-11 18:04:37.362 DEBUG 9170 --- [           main] faultConfiguringBeanFactoryPostProcessor : 
Spring Integration global properties:

spring.integration.endpoints.noAutoStartup=
spring.integration.taskScheduler.poolSize=10
spring.integration.channels.maxUnicastSubscribers=0x7fffffff
spring.integration.channels.autoCreate=true
spring.integration.channels.maxBroadcastSubscribers=0x7fffffff
spring.integration.readOnly.headers=
spring.integration.messagingTemplate.throwExceptionOnLateReply=false

2019-04-11 18:04:37.362 DEBUG 9170 --- [           main] .s.i.c.GlobalChannelInterceptorProcessor : No global channel interceptors.
2019-04-11 18:04:37.363  INFO 9170 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
2019-04-11 18:04:37.363  INFO 9170 --- [           main] o.s.i.channel.PublishSubscribeChannel    : Channel 'org.springframework.context.support.ClassPathXmlApplicationContext@1af05b03.errorChannel' has 1 subscriber(s).
2019-04-11 18:04:37.363  INFO 9170 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : started _org.springframework.integration.errorLogger
2019-04-11 18:04:37.363  INFO 9170 --- [           main] ProxyFactoryBean$MethodInvocationGateway : started hwOutboundGateway
2019-04-11 18:04:37.363  INFO 9170 --- [           main] o.s.i.gateway.GatewayProxyFactoryBean    : started hwOutboundGateway
2019-04-11 18:04:37.364  INFO 9170 --- [           main] ishingJmsMessageListener$GatewayDelegate : started org.springframework.integration.jms.ChannelPublishingJmsMessageListener$GatewayDelegate@56febdc
2019-04-11 18:04:37.552  INFO 9170 --- [           main] o.s.i.jms.JmsMessageDrivenEndpoint       : started hwOutboundAdapter
2019-04-11 18:04:37.561 DEBUG 9170 --- [           main] o.s.integration.channel.DirectChannel    : preSend on channel 'hwOutboundChannel', message: GenericMessage [payload=Hello World, headers={id=58f33457-fa61-553c-3e9d-525784a2c199, timestamp=1555031077560}]
2019-04-11 18:04:37.564  INFO 9170 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-04-11 18:04:37.572 ERROR 9170 --- [           main] o.s.boot.SpringApplication               : Application run failed

java.lang.IllegalStateException: Failed to execute CommandLineRunner
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:816) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
    at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:797) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:324) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
    at t.h.w.sisandbox.SiSandboxApplication.main(SiSandboxApplication.java:20) [classes/:na]
Caused by: org.springframework.messaging.MessageDeliveryException: Dispatcher has no subscribers for channel 'org.springframework.context.support.ClassPathXmlApplicationContext@1af05b03.hwOutboundChannel'.; nested exception is org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers, failedMessage=GenericMessage [payload=Hello World, headers={id=58f33457-fa61-553c-3e9d-525784a2c199, timestamp=1555031077560}]
    at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77) ~[spring-integration-core-5.1.4.RELEASE.jar:5.1.4.RELEASE]
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:461) ~[spring-integration-core-5.1.4.RELEASE.jar:5.1.4.RELEASE]
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:401) ~[spring-integration-core-5.1.4.RELEASE.jar:5.1.4.RELEASE]
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:187) ~[spring-messaging-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:166) ~[spring-messaging-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:47) ~[spring-messaging-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:109) ~[spring-messaging-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.messaging.core.AbstractMessageSendingTemplate.convertAndSend(AbstractMessageSendingTemplate.java:151) ~[spring-messaging-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.messaging.core.AbstractMessageSendingTemplate.convertAndSend(AbstractMessageSendingTemplate.java:143) ~[spring-messaging-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.integration.gateway.MessagingGatewaySupport.send(MessagingGatewaySupport.java:413) ~[spring-integration-core-5.1.4.RELEASE.jar:5.1.4.RELEASE]
    at org.springframework.integration.gateway.GatewayProxyFactoryBean.invokeGatewayMethod(GatewayProxyFactoryBean.java:533) ~[spring-integration-core-5.1.4.RELEASE.jar:5.1.4.RELEASE]
    at org.springframework.integration.gateway.GatewayProxyFactoryBean.doInvoke(GatewayProxyFactoryBean.java:473) ~[spring-integration-core-5.1.4.RELEASE.jar:5.1.4.RELEASE]
    at org.springframework.integration.gateway.GatewayProxyFactoryBean.invoke(GatewayProxyFactoryBean.java:463) ~[spring-integration-core-5.1.4.RELEASE.jar:5.1.4.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) ~[spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at com.sun.proxy.$Proxy55.send(Unknown Source) ~[na:na]
    at t.h.w.sisandbox.SiSandboxApplication.run(SiSandboxApplication.java:29) [classes/:na]
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:813) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
    ... 5 common frames omitted
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.4.RELEASE.jar:5.1.4.RELEASE]
    at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:105) ~[spring-integration-core-5.1.4.RELEASE.jar:5.1.4.RELEASE]
    at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:73) ~[spring-integration-core-5.1.4.RELEASE.jar:5.1.4.RELEASE]
    ... 22 common frames omitted

2019-04-11 18:04:37.576  INFO 9170 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : Removing {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
2019-04-11 18:04:37.576  INFO 9170 --- [           main] o.s.i.channel.PublishSubscribeChannel    : Channel 'application.errorChannel' has 0 subscriber(s).
java
spring-integration
spring-jms
asked on Stack Overflow Apr 12, 2019 by Tao Dong

1 Answer

0

According to you config you don’t do JMS producer, the <jms:message-driven-channel-Adapter is a JMS consumer. Please, read their documentation: https://docs.spring.io/spring-integration/docs/5.1.4.RELEASE/reference/html/#jms.

For producer you need to use jms:outbound-channel-Adapter instead.

And that’s exactly a reason why you have that exception because you send a message over Gateway to the channel without subscriber. Your <jms:message-driven-channel-Adapter is going to do the same when a message appears on that JMS destination.

answered on Stack Overflow Apr 12, 2019 by Artem Bilan

User contributions licensed under CC BY-SA 3.0