Spring integration IntegrationFlow HttpRequestHandlingMessagingGateway直接回复

Spring integration IntegrationFlow HttpRequestHandlingMessagingGateway直接回复,spring-integration,spring-integration-dsl,spring-integration-http,Spring Integration,Spring Integration Dsl,Spring Integration Http,我是Spring集成新手,我正在尝试使用HttpRequestExecutingMessageHandler和HttpRequestHandlingMessagingGateway。处理程序正在发送POST请求,并期望得到答复。网关正在使用该请求。它工作正常,但处理程序没有收到回复。我不知道如何设置我的流程,我可以直接发送回复并继续我的流程 @Bean public HttpRequestExecutingMessageHandler httpOutbound() { HttpRequest

我是Spring集成新手,我正在尝试使用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。之后,我想继续我的集成流程,做一些事情并将结果发送到队列


<建议> < /P> < P>对于刚才的代码> 200 OK < /Cord>响应,您需要考虑配置<代码> HythPrimththand Link MasgIGeGeor <代码> > <代码>通过这种方式,它将作为入站通道适配器工作,但由于HTTP始终是请求-响应,它将只执行以下操作
setStatusCodeIfNeeded(response,httpEntity)
和客户端的
HttpRequestExecutingMessageHandler
将得到一个空的,但
OK
response

但不确定您的
频道(replyChannel())
为什么不能按预期工作。这可能是因为您将请求
palyoad
返回到一条回复消息中,该消息最终成为HTTP响应,但不知怎的,它在那里失败了,可能是在转换过程中

更新


下面是一个简单的Spring引导应用程序,演示了一个应答和处理场景:

谢谢您的回答。我试试看。你说:“对于200个OK响应,你需要考虑配置一个HTTPREQuththand Link MeasAgEngutialGutlook,带有一个PosiTrePrime= false。”如果我还想获得其他http状态,比如状态处理程序,该怎么办?我如何构建我的流程来实现这一点?那么它确实必须是一个网关(
newhttprequesthandlingmessaginggateway()
)。考虑返回一个空字符串作为响应。在
.channel(replyChannel())
之前做一些简单的
.transform()
你能举个例子吗?在那之后,我会把它作为一个正确的答案。会帮我很多忙的!请在我的答案中查找更新。抱歉耽搁了。一直忙于发布:感谢回复和示例:)