首页 > 解决方案 > Spring 集成异步 Http 出站调用

问题描述

我有一个要求,我必须在循环中使用不同的有效负载值对 http 端点进行 Http 出站调用,调用函数不必等待从出站调用收到的响应,所以基本上出站调用将异步发生一个循环。

有没有办法我们可以使用 Http.outboundGateway 来实现这一点

标签: spring-integrationspring-integration-http

解决方案


您只需要有一个ExecutorChannel作为该 HTTP 出站网关端点的输入。就像是:

.channel(MessageChannels.executor(someTaskExecutor))
.handle(Http.outboundGateway(...))

如果您从某个循环中执行此操作,那么您还应该有一个id用于该通道的注入和用于从您的代码发送。如果您不喜欢在代码中处理 API,您也可以考虑@MessagingGateway在该通道之上使用外观。MessageChannel

在文档中查看更多信息:

https://docs.spring.io/spring-integration/docs/current/reference/html/messaging-endpoints.html#gateway

https://docs.spring.io/spring-integration/docs/current/reference/html/core.html#executor-channel


推荐阅读