我已经建立了一个简单的Spring集成流,它由以下步骤组成:
请遵守以下守则:
@Component
public class MyIntegrationFlow extends IntegrationFlowAdapter {
@Override
protected IntegrationFlowDefinition<?> buildFlow() {
return from(() -> List.of("pathVariable1", "pathVariable2"), c -> c.poller(Pollers.fixedDelay(5, TimeUnit.SECONDS)))
.split()
.handle(httpRequest(), c -> c.advice(new RequestHandlerRetryAdvice()))
.transform(Tranformers.fromJson(Foo.class))
.filter(payload -> payload.isValid())
.log()
.transform(Tranformers.toJson())
.channel(Source.OUTPUT); // output channel for kafka topic
}
private HttpMessageHandlerSpec httpRequest() {
return Http.outboundGateway("http://somehost:8080/{pathVariable}")
.httpMethod(GET)
.uriVariable("pathVariable", Message::getPayload)
.expectedResponseType(String.class);
}
}这是很好的工作,然而,我正在努力想出一些好的测试。
MessageSource?发布于 2019-07-01 17:08:36
问题太多了,有些问题需要解释得太广泛。无论如何,我认为您可以从及其文档开始。
我认为您可以考虑使用Spring中的Mock MVC及其MockMvcClientHttpRequestFactory来注入基于HttpMessageHandlerSpec的HttpRequestExecutingMessageHandler。
嗯,我想相同的模拟MVC端点可以验证它被调用了多少次,并且在最初的几次失败中启动了该重试。
这正是Spring测试框架的一部分,它的MockIntegration.mockMessageSource()和MockIntegrationContext:https://docs.spring.io/spring-integration/docs/5.1.6.RELEASE/reference/html/#mockintegration
或者您可以使用前面提到的MockIntegration.mockMessageHandler()来验证卡夫卡的端点是否被调用。或者使用Spring项目中的Embedded Kafka:https://docs.spring.io/spring-kafka/docs/2.2.7.RELEASE/reference/html/#embedded-kafka-annotation
https://stackoverflow.com/questions/56839416
复制相似问题