我正在尝试使用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).
答案 0 :(得分:0)
根据您的配置,您不是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
将执行相同的操作。