我为使用spring cloud starter stream rabbit编写了一个测试类,当我只运行receiver并从rabbitmq发送消息时,它可以工作;但是当我运行test sender类时,出现了一个错误:org.springframework.messaging。MessageDeliveryException:Dispatcher没有频道的订阅者,我应该怎么做才能更正?
我的步骤:
首先,运行SpringbootApplication;其次,运行JUnit测试
spring boot starter父2.1.3.RELEASE JDK8 rabbitmq utf8
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.springcloud</groupId>
<artifactId>stream-hello</artifactId>
<version>1.0</version>
<name>stream-hello</name>
<description>SpringCloud Project</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR1</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
SinkReceiver.java
@EnableBinding({Sink.class})
public class SinkReceiver {
private static Logger logger = LoggerFactory.getLogger(SinkReceiver.class);
@StreamListener(Sink.INPUT)
public void receive(Object payload) {
logger.info("Received: " + payload);
}
}
StreamHelloApplication.java
@SpringBootApplication
public class StreamHelloApplication {
public static void main(String[] args) {
SpringApplication.run(StreamHelloApplication.class, args);
}
}
StreamHelloApplicationTests.java
@RunWith(SpringRunner.class)
@EnableBinding(value = {StreamHelloApplicationTests.SinkSender.class})
public class StreamHelloApplicationTests {
@Autowired
private SinkSender sinkSender;
@Test
public void sinkSenderTester() {
sinkSender.output().send(MessageBuilder.withPayload("produce a message : sinkSenderTest").build());
}
public interface SinkSender {
String OUTPUT = "input";
@Output(SinkSender.OUTPUT)
MessageChannel output();
}
}
application.properties
spring.application.name=stream-hello
#config rabbitmq
spring.rabbitmq.host=localhost
spring.rabbitmq.port=35672
spring.rabbitmq.username=admin
spring.rabbitmq.password=123456
我希望junit测试可以成功运行,但运行时会出现错误。堆栈跟踪如下:
org.springframework.messaging.MessageDeliveryException: Dispatcher has no subscribers for channel 'org.springframework.context.support.GenericApplicationContext@68ceda24.input'.; nested exception is org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers, failedMessage=GenericMessage [payload=byte[34], headers={contentType=application/json, id=fc0a6890-4945-142b-55cd-668b0d3f22ed, timestamp=1555817595975}], failedMessage=GenericMessage [payload=byte[34], headers={contentType=application/json, id=fc0a6890-4945-142b-55cd-668b0d3f22ed, timestamp=1555817595975}]
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:461)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:401)
at com.springcloud.StreamHelloApplicationTests.sinkSenderTester(StreamHelloApplicationTests.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
Caused by: org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers, failedMessage=GenericMessage [payload=byte[34], headers={contentType=application/json, id=fc0a6890-4945-142b-55cd-668b0d3f22ed, timestamp=1555817595975}]
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:138)
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:105)
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:73)
... 34 more
您的绑定接口未绑定到任何内容。“输入”通道已创建,但没有订阅者。你的接收器甚至都不是测试的一部分。对于测试,请阅读用户手册的测试,尤其是新的测试活页夹。以上部分也包含完整的工作样本。
您可以帮助进行spring集成配置吗。 收到消息后,我收到: 我的代码: 我有类似的JmsInboudGateway配置,用于其他没有.requestChannel和.replyChannel的队列。 如果不是注入请求通道bean,而是用文本名称声明它,得到了这个 以及更多的文字宣传问题。
我已经完成了以下配置和java代码,以向Kafka主题发送消息。我只想发信息。 我正在使用Spring boot和kafka集成 Kafka应用程序已从Docker启动 Spring Boot应用程序通过简单的配置连接kafka 波姆。xml 应用yml 消息通道Bean 日志事件发布程序 Restendpoint发布消息 下面是我在执行其余endpoint时得到的异常跟踪。
我的应用程序成功发送Kafka消息,但只有在Kafka初始化后。在此之前,我得到错误“Dispatcher没有订阅者”。如何等待订阅者完成频道注册? 17.165 SenderClass已创建 17.816初始化类,@PostConstruct启动PollingTask 24.781PollingTask发送第一条Kafka消息 24.816第一个错误:“Dispatcher没有订阅服务器” 25
我正在创建一个API来发布和使用来自RabbitMQ的消息。在我当前的设计中,发布者将发出一个POST请求。我的API会将POST请求路由到Exchange。这样,发布者在发布时就不必知道服务器地址、exchange名称等。 现在消费者部分是我不确定如何继续的地方。 开始时不会排队。当一个新的消费者想要订阅一个主题时,那么我将创建一个队列并将其绑定到交换。我需要一些问题的答案- 一旦我为使用者创建
我正试图为我的主要活动编写一个仪器测试。我遵循了这里给出的答案。但是Android Studio找不到任何测试。我在androidTest文件夹中有applicationTest.java类。以下是这堂课的内容: 这个测试类出了什么问题?还是测试?我没有得到任何错误,它只是没有找到任何测试运行。运行ApplicationTest后,输出以以下行结束: 以下是该应用程序的build.gradle文件
问题内容: 跟随Redis Pub / Sub 这工作正常,我可以使用以下任何语言发布消息 使用,我可以验证此请求是否已正确发布 当我将订阅者 块 添加到 其他类(侦听器类)中的 该频道时,问题就开始了,如下所示 中的,还表明侦听器已正确订阅 问题是,当我将订户侦听器类添加到相同的Rails应用程序时…它停止工作,导致侦听Redis服务器并停止执行任何其他代码…它只是坐在那里侦听。 因此,有一种方