2017-01-04 1 views
1

Je suis nouveau à l'intégration de printemps et je ne pouvais pas trouver un poste similaire ici. En ce moment j'ai un messageHandler qui appelle URI spécifique et écrit sur le canal.Printemps Intégration plusieurs messageHandlers

@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; 
    } 

et 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(); 
} 

Maintenant, je dois étendre cette fonction afin que l'on URL supplémentaire sera appelée. Pour autant que je sache, MessageHandler peut toujours appeler une seule URL et gérer la fonction dans IntegrationFlow seulement un MessageHandler.

Répondre

0

Utilisez un canal de publication de souscription et abonnez-vous deux sous-flux; voir le DSL reference.

BTW, @Scope("prototype") ne s'applique pas aux grains d'intégration de ressort.