Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用SpringCloudTest测试SpringCloud流_Java_Spring_Rest_Spring Cloud Stream_Spring Boot Test - Fatal编程技术网

Java 使用SpringCloudTest测试SpringCloud流

Java 使用SpringCloudTest测试SpringCloud流,java,spring,rest,spring-cloud-stream,spring-boot-test,Java,Spring,Rest,Spring Cloud Stream,Spring Boot Test,我在我的spring boot应用程序中定义了一些流生产者(@Output)和消费者(@Input),只要我的rest端点。现在我想使用 @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) 首先,我想知道这是否可行。 对于其余部分,我正在自动连接TestRestTemplate,一切正常: @Autowired private TestR

我在我的spring boot应用程序中定义了一些流生产者(
@Output
)和消费者(
@Input
),只要我的rest端点。现在我想使用

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
首先,我想知道这是否可行。 对于其余部分,我正在自动连接TestRestTemplate,一切正常:

@Autowired
private TestRestTemplate restTemplate;
但对于我尝试使用的流:

@ClassRule
public static RabbitTestSupport rabbitTestSupport = new RabbitTestSupport();
这使我能够识别兔子是否起来了,这很好,但当我试着去做的时候

 @Autowired
private MessageChannel myProducer;
和发送消息,我没有收到任何错误,但我的应用程序不会使用这些消息

我觉得制作人和消费者都是作为我的应用程序的一部分启动的,而不是在一个解耦的环境中启动的,因此这不起作用

生产者和消费者在不同的应用程序中工作良好,因此它似乎与测试配置有关

有什么想法吗?是否有人使用
@SpringBootTest
在同一测试中测试了REST和Streams,因为我找不到任何引用

我在这里添加了一个复制器:

一些建议:

以及测试:

它使用以下属性:


我将感谢你能提供的任何帮助

你能再解释一点吗
我的应用程序不使用消息
。我这样问是因为不清楚您是如何使用消息的,您的应用程序是在侦听还是在http端点,然后使用源输出通过代理发送数据?然后你有一个接收器输入来使用它们?

我使用这个库在我的应用程序中使用cucumber/gherkin轻松地测试spring云消息:

是的。因此,我有一个spring boot应用程序,带有@Input(HISTORY_CONSUMER)SubscribableChannel historyConsumer();并正确设置EnableBinding()注释。因为当我从不同的应用程序发送消息时,消息会被消耗。但当我使用@SpringBootTest通过测试发送消息并创建新的@Output(HISTORY_PRODUCER)MessageChannel historyProducer()时;在测试中,这似乎不起作用。你有没有测试过这种互动?我假设这是每个人都想做的事情我想我知道发生了什么。您的频道有不同的名称。因此,生产者消息将被发送到与消费订户不同的队列。您可以尝试使用
spring.cloud.stream.bindings.historyProducer.destination=sharedName
spring.cloud.stream.bindings.historyConsumer.destination=sharedName
覆盖它们,这样两者都将绑定到相同的目标。我为这些频道提供了正确的配置。我已经在生产了,但我认为消费者和生产者的配置是混淆的。我的应用程序中有一个application.properties,然后我需要为测试生产者的测试添加另一个application.properties。我将尝试创建一个复制器并在此处发布链接我在此处添加了一个复制器:您应该能够在不到2分钟的时间内看到该项目的问题。如果你需要更多的澄清,请告诉我。我很感谢你的帮助,我正在克隆回购协议,但是第一件事是对boot2.0的依赖。对于Stream,您可以恢复到boot 1.5.4和Ditmars 1.3吗?boot2.0可能仍然存在一些问题,我希望在研究这个问题时减少变量的数量。我们在boot 2.0中遇到的一个主要问题是环境和属性解析,所以我暂时退一步。解决:主要问题是将测试绑定添加到类路径,它与rabbit mq提供程序重叠,这导致消息永远不会到达正在运行的应用程序。我的存储库中的测试显示了这些组件的正确工作,我可能会就此写一篇博文,因为我在任何地方都找不到任何这样的例子。