Spring集成了几个messageHandlers

时间:2017-01-04 09:59:24

标签: spring-integration message-handlers

我是Spring Integration的新手,我在这里找不到任何类似的帖子。 现在我有一个messageHandler调用特定的URI并写入通道。

@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函数。

1 个答案:

答案 0 :(得分:0)

使用发布订阅频道并订阅两个子流;请参阅DSL reference

BTW,@Scope("prototype")不适用于spring integration beans。