簡體   English   中英

如何解決簡單消息生成器的“分派器沒有訂閱者”錯誤?

[英]How to fix “Dispatcher has no subscribers” error for a simple message producer?

我正在嘗試使用Spring Integration創建一個簡單的JMS生產者。 誰能幫我解釋為什么我收到“調度程序沒有訂閱者”錯誤的信息?

我在本地使用ActiveMQ,並根據我的ActiveMQ日志,在運行測試應用程序時都會創建隊列和會話。 但是沒有消息進來。

我的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);

}

測試碼

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

錯誤堆棧跟蹤

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).

根據您的配置,您不是JMS生產者, <jms:message-driven-channel-Adapter是JMS使用者。 請閱讀其文檔: https : //docs.spring.io/spring-integration/docs/5.1.4.RELEASE/reference/html/#jms

對於生產者,您需要使用jms:outbound-channel-Adapter代替。

這正是您有例外的原因,因為您是在沒有訂閱者的情況下通過網關將消息發送到通道的。 當消息顯示在該JMS目標上時,您的<jms:message-driven-channel-Adapter將執行相同的操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM