我是 Spring Integration 的新手,我正在尝试使用 HttpRequestExecutingMessageHandler 和 HttpRequestHandlingMessagingGateway。处理程序正在发送一个 POST 请求并期待回复。网关正在使用该请求。它工作正常,但处理程序没有得到回复。我不知道如何设置我的流程,我可以直接发回回复并继续我的流程。
@Bean
public HttpRequestExecutingMessageHandler httpOutbound() {
HttpRequestExecutingMessageHandler handler = Http.outboundGateway(restUrl)
.httpMethod(HttpMethod.POST)
.messageConverters(new MappingJackson2HttpMessageConverter())
.mappedRequestHeaders("Content-Type")
.get();
handler.setExpectReply(true);
handler.setOutputChannel(httpResponseChannel());
return handler;
}
@Bean
public HttpRequestHandlingMessagingGateway httpRequestGateway() {
HttpRequestHandlingMessagingGateway gateway = new HttpRequestHandlingMessagingGateway(true);
RequestMapping mapping = new RequestMapping();
mapping.setMethods(HttpMethod.POST);
mapping.setPathPatterns(httpRequestHandlingPathPattern);
gateway.setRequestMapping(mapping);
gateway.setErrorChannel(errorChannel());
gateway.setReplyChannel(replyChannel());
gateway.setRequestChannel(requestChannel());
gateway.setRequestPayloadTypeClass(DocumentConverterInput.class);
return gateway;
}
@Bean
public IntegrationFlow documentConverterFlow() {
return IntegrationFlows
.from(requestChannel())
.publishSubscribeChannel(publishSubscribeSpec ->
publishSubscribeSpec.subscribe(flow -> flow
.enrichHeaders(headerEnricherSpec -> headerEnricherSpec.header("http_statusCode", HttpStatus.OK))
.channel(replyChannel())))
.enrichHeaders(headerEnricherSpec ->
headerEnricherSpec.headerExpression(Constants.DOCUMENT_CONVERTER_INPUT, "payload"))
.handle(Jms.outboundAdapter(jmsTemplate(connectionFactory)))
.get();
}
我的 HttpRequestExecutingMessageHandler 已成功发布请求。HttpRequestHandlingMessagingGateway 已成功使用它。起初我有一个错误“超时内没有收到回复”,所以我添加了一个publishSubscriberChannel。我不知道这是否是正确的方法,但我找不到显示如何正确回复的工作示例。
我上面的代码正在运行,但没有将回复发送回 HttpRequestExecutingMessageHandler!
我的目标是收到请求消息并直接发回 200 OK。之后我想继续我的集成流程,做一些事情并将结果发送到队列。
有什么建议么?