问题
I'm trying to apply Spring Cloud Contract to a Reactive API built with Spring Webflux. Basically be able to send a Flux and receive a response Flux from an API in the style of:
@RequestMapping("/endlessecho")
public Flux<String> endlessEcho(Flux<String> input) {
return input;
}
I can however find no information online or in the documentation on whether I can do this with Spring Cloud Contract.
Is it even possible to write a Contract for this? Will it be able to feed wiremock and generate the appropriate JUnit tests?
回答1:
With this commit (https://github.com/spring-cloud-samples/spring-cloud-contract-samples/commit/f7030148a9337d4c7184f7c8e27c271d9b89681b) I've added a WebFlux example to the Spring Cloud COntract Samples.
It's enough to define the contract as usual, pass the EXPLICIT
mode for testMode
parameter in the plugin setup. Instead of RestASsuredMockMvc
you have to use the standard RestAssured
static URI
field to set up the URI of the app that is using WebFlux
. You need to setup the whole Spring Context and bind to a port and that's pretty much it.
In the project called consumer
there's a test that uses the stubs from the producer-webflux
project. From the Stub Runner's perspective, there's no change in how the stubs are started.
来源:https://stackoverflow.com/questions/49885765/spring-cloud-contract-for-webflux-reactive-apis