2017-01-04 7 views
1

저는 Spring Integration을 처음 접했고 비슷한 게시물을 찾을 수 없었습니다. 지금은 특정 URI를 호출하고 채널에 쓰는 하나의 messageHandler가 있습니다.Spring 통합 여러 messageHandler

@Bean 
    @Scope("prototype") 
    public MessageHandler httpGateway() { 
     if (checkURLs()) { 
      LOG.error("REST URLS are not configured"); 
      return null; 
     } 
     CredentialsProvider credsProvider = createCredentials(); 
     CloseableHttpClient httpclient = createHttpClient(credsProvider); 
     HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory(httpclient); 
     HttpRequestExecutingMessageHandler httpHandler = createHttpRequestHandler(httpRequestFactory, requestURL); 
     return httpHandler; 
    } 

private HttpRequestExecutingMessageHandler createHttpRequestHandler(HttpComponentsClientHttpRequestFactory httpRequestFactory, String request) { 
     HttpRequestExecutingMessageHandler httpHandler = null; 
     try { 
      httpHandler = new HttpRequestExecutingMessageHandler(new URI(request)); 
     } catch (URISyntaxException e) { 
      LOG.error(e.toString(), e); 
     } 
     httpHandler.setExpectedResponseType(String.class); 
     httpHandler.setRequestFactory(httpRequestFactory); 
     httpHandler.setHttpMethod(HttpMethod.GET); 
     return httpHandler; 
    } 

및 IntegrationFlows

@Bean 
public IntegrationFlow esbFlow(MessageHandler httpGateway) { 
    if (checkURLs()) { 
     LOG.error("REST URLS are not configured create flow without fetching"); 
     return null; 
    } 
    return IntegrationFlows 
      .from(integerMessageSource(), c -> c.poller(Pollers.cron(pollerCron))) 
      .channel(TRIGGER_CHANNEL) 
      .handle(httpGateway) 
      .filter(p -> p instanceof String, f -> f.discardChannel(ESB_JSON_ERROR_CHANNEL)) 
      .channel(ESB_JSON_PARSING_CHANNEL) 
      .get(); 
} 

자, 내가 하나 개의 추가 URL 호출 할 수 있도록 확장이 기능에 있습니다. 내가 아는 한, MessageHandler는 하나의 URL만을 호출 할 수 있으며 IntegrationFlow에서는 하나의 MessageHandler에서만 함수를 처리 할 수 ​​있습니다.

답변

0

게시 구독 채널을 사용하고 이에 대한 두 개의 서브 플로우를 구독하십시오. DSL reference을 참조하십시오.

BTW, @Scope("prototype")은 스프링 통합 beans에는 적용 할 수 없습니다.