1

嗨我試圖使用Spring集成實現以下流程。 公開REST服務,處理有效內容,將更改後的有效內容寫入JMS並回復到REST服務。春季集成:REST到JMS集成給出超時錯誤

@Bean 
public IntegrationFlow httpInputFlow() { 
    return IntegrationFlows 
      .from(Http.inboundGateway(「/company」) 
        .requestMapping(r -> r 
          .methods(HttpMethod.POST)) 
        .requestPayloadType(com.poc.model.Company.class)) 
      .transform(jsonToObjectTransformer()) 
      .channel(requestChannel()) 
      .get(); 
} 

@Bean 
@Transformer(inputChannel=「requestChannel」, outputChannel=「responseChannel」) 
ObjectToJsonTransformer jsonToObjectTransformer() { 
    return new ObjectToJsonTransformer(); 
} 
@Bean 
public DirectChannel requestChannel() { 
    return MessageChannels.direct().get(); 
} 
@Bean 
public DirectChannel responseChannel() { 
    return MessageChannels.direct().get(); 
} 
@Bean 
IntegrationFlow outboundFlow() throws Exception { 
    return IntegrationFlows.from(responseChannel()) .handle(Jms.outboundAdapter(connectionFactory()).destination(「samplequeue」)) 
      .get(); 
} 

請求有效載荷正在到達隊列。但是,REST服務超時沒有回覆。我需要將轉換後的有效負載放入隊列中,並將其發送給其餘服務的響應。我找不到任何可用的例子。

任何幫助表示讚賞。

回答

1

responseChannel必須是publishSubscribe並且您應該有一個bridge subscrbiber讓它將回復發送回HTTP入站網關。單向組件中的Jms.outboundAdapter()並不會產生任何回覆。這就是你的流程停止的方式,不會迴應到入口點。

你的用例可被寫像:

@Bean 
public IntegrationFlow httpInputFlow() { 
    return IntegrationFlows 
      .from(Http.inboundGateway("/company") 
        .requestMapping(r -> r 
          .methods(HttpMethod.POST)) 
        .reqestPayloadType(com.poc.model.Company.class)) 
      .transform(jsonToObjectTransformer()) 
      .publishSubscribeChannel(subscribers -> 
        subscribers.subscribe(f -> f 
         .handle(Jms.outboundAdapter(connectionFactory()).destination("samplequeue")))) 
      .bridge(null) 
      .get(); 
} 

publishSubscribeChannel()提供所需的信道。 subscribers.subscribe()加上Jms.outboundAdapter()作爲第一個用戶。 .bridge()作爲publishSubscribeChannel()的最後一個(本例中是第二位)用戶。

BridgeHandler將其回覆發送給replyChannel標題的想法,該標題由Http.inboundGateway()填充。

+0

謝謝Artem,會試試這個。 – jack

+0

你可以建議如何通過.bridge()橋處理程序? Bridge方法期望Consumer >作爲參數。樣本是在xml中,而不是在java dsl中。 – jack

+0

必須是'.brdige(null)'。在將Java DSL移植到5.0中的Spring Integration Core後,我們添加了不帶參數的'.bridge()'。 –