0

我已经在我的 Spring Boot 应用程序中定义了一些流生产者(@Output)和消费者(@Input),只要我的休息端点。现在我想测试 REST + Streams 使用

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)

首先我想知道这是否可能。对于 REST,我正在自动连接 TestRestTemplate,一切正常:

@Autowired
private TestRestTemplate restTemplate;

但是对于我正在尝试使用的流:

@ClassRule
public static RabbitTestSupport rabbitTestSupport = new RabbitTestSupport();

这使我能够识别 Rabbit 是否启动,这工作正常,但是当我尝试

 @Autowired
private MessageChannel myProducer;

并发送消息,我没有收到任何错误,但我的应用程序不会使用这些消息。

我感觉生产者和消费者都是作为我的应用程序的一部分而不是在分离的上下文中启动的,因此这不起作用。

生产者和消费者在不同的应用程序中工作正常,所以这似乎与测试配置有关。

有任何想法吗?是否有人设法在同一个测试中同时测试 REST 和 Streams,@SpringBootTest因为我找不到任何参考。

我在这里添加一个复制器: https ://github.com/Salaboy/test-spring-cloud-streams/

一些指针: https ://github.com/Salaboy/test-spring-cloud-streams/blob/master/src/main/java/org/salaboy/streams/SampleApplication.java#L40

和测试: https ://github.com/Salaboy/test-spring-cloud-streams/blob/master/src/test/java/org/salaboy/streams/MyAppStreamsTest.java

它使用这些属性: https ://github.com/Salaboy/test-spring-cloud-streams/blob/master/src/test/resources/test-application.properties

我将不胜感激您能提供的任何帮助。

4

2 回答 2

0

你能再解释一下吗messages are not consumed by my apps。我之所以问,是因为不清楚您是如何使用消息的,您的应用程序是在侦听还是 http 端点,然后使用 Source 输出通过代理发送数据?然后你有一个接收器输入来消耗它们?

于 2017-07-16T14:33:57.743 回答
0

我使用这个库在我的应用程序中使用 cucumber/gherkin 轻松测试 spring 云消息:https ://github.com/RedFroggy/spring-cucumber-messaging

于 2021-03-17T14:03:32.400 回答