Spring Integration 几个消息处理程序



我是春季集成的新手,在这里找不到任何类似的帖子。现在我有一个消息处理程序,它调用特定的 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;
    }

和集成流

@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 中的函数只能调用一个消息处理程序。

使用发布订阅通道并为其订阅两个子流;请参阅 DSL 参考。

顺便说一句,@Scope("prototype")不适用于弹簧集成豆。

相关内容

  • 没有找到相关文章

最新更新