我们正在使用spring-cloud-stream
开发一个项目,rabbitmq
作为消息代理和gradle
。
出于测试目的,我们正在运行一个带有rabbitmq实例的docker容器。
application.yaml:
spring
rabbitmq:
host: localhost
我有这个测试:
@DirtiesContext(classMode = BEFORE_EACH_TEST_METHOD)
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = RANDOM_PORT)
public class TasksProcessorIT {
@Test
public void shouldConsumeDeleteUserTask() {
userRepository.insert(INITIAL_USER).block();
final AtomicReference<Message<?>> msgRef = new AtomicReference<>();
inboundEventsChannel.subscribe(msgRef::set);
outboundTasksChannel.send(DELETE_USER_TASK);
await().atMost(FIVE_SECONDS)
.untilAtomic(msgRef, notNullValue());
final Message<?> receivedEvent = msgRef.get();
assertNotNull(receivedEvent);
assertEquals(USER_DELETED, typeHeader(receivedEvent));
assertNull(userRepository.findAll().blockFirst());
}
}
它在Intelij Runner上运行,但在调用gradle test
时失败,我想知道为什么......
这是记录的原因:
Caused by: org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers
答案 0 :(得分:0)
问题可能是您在不同测试之间的RabbitMQ队列中有一些数据,但由于您完全在测试方法中订阅了该通道,这可能已经很晚了,因为监听器容器已经消耗了消息( s)从队列中。
考虑在两次测试之间清理队列以进行测试。