我是 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;
}
和集成流
@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。