gpt4 book ai didi

java - 如何修复简单消息生成器的 "Dispatcher has no subscribers"错误?

转载 作者:行者123 更新时间:2023-11-30 12:06:19 34 4
gpt4 key购买 nike

我正在尝试使用 Spring Integration 创建一个简单的 JMS 生产者。任何人都可以帮我解释为什么我收到“Dispatcher 没有订阅者”错误吗?

我在本地使用 ActiveMQ,并且基于我的 ActiveMQ 日志,队列和 session 都是在我运行测试应用程序时创建的。但是没有消息进来。

我的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反而。

这正是您出现该异常的原因,因为您通过网关向没有订阅者的 channel 发送消息。你的<jms:message-driven-channel-Adapter当一条消息出现在该 JMS 目标上时,将执行相同的操作。

关于java - 如何修复简单消息生成器的 "Dispatcher has no subscribers"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55643135/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com