2017-02-24 35 views
1

我消耗來自兔隊列中的消息與被配置像這樣一個bean:使用報頭建立在HTTP出站通道適配器URL

IntegrationFlows.from(Amqp.inboundGateway(listenerContainer()).errorChannel(FailedFlow.CHANNEL_NAME)) 
      .transform(Transformers.fromJson()) 
      .channel(TestFlow.CHANNEL_NAME) 
      .get(); 

該消息經過一些路由器和頭濃縮商在結束了出站流量配置有像這樣一個bean:

IntegrationFlows.from(CHANNEL_NAME) 
      .transform(Transformers.toJson()) 
      .handle(Http.outboundChannelAdapter("http://localhost:8080/api/test") 
          .httpMethod(HttpMethod.POST) 
          .requestFactory(getRequestFactory())) 
      .get(); 

同時測試,但實際使用中,我需要把請求發送到使用存儲在已被前面添加一個標題基本URL不同的服務器能正常工作。

IntegrationFlows.from(CHANNEL_NAME) 
      .transform(Transformers.toJson()) 
      .handle(e -> Http.outboundChannelAdapter(String.format("%s/test", 
        e.getHeaders().get(IntegrationConstants.NOTIFY_BASE_URL_HEADER_NAME))) 
      .httpMethod(HttpMethod.POST) 
      .requestFactory(getRequestFactory())) 
      .get(); 

看來,在測試的配置我傳遞一個MessageHandlerSpec到手柄方法和實際的配置我傳遞一個的MessageHandler到手柄的方法。我不確定有什麼區別,我所知道的是在傳遞MessageHandler時不會調用端點。

如何在保持直接使用MessageHandlerSpec的同時訪問標題?

回答

1
.handle(IntegrationFlows.from(CHANNEL_NAME) 
        .transform(Transformers.toJson()) 
        .handle(Http.outboundChannelAdapter("{baseUrl}/test") 
          .httpMethod(HttpMethod.POST) 
          .requestFactory(getRequestFactory()) 
          .uriVariable("baseUrl", e -> e.getHeaders().get(IntegrationConstants.NOTIFY_BASE_URL_HEADER_NAME))) 
        .get()) 

:-D

相關問題