【问题标题】:integrate multiple service response in spring cloud gateway在spring cloud gateway中集成多种服务响应
【发布时间】:2018-05-10 19:31:43
【问题描述】:

当我获得例如 /bar 的请求表单路径时,Spring Cloud Gateway 中是否可以调用多个微服务并集成它们的结果(例如 JSON)并作为 /bar 的响应发送? 我该怎么做? 谢谢

【问题讨论】:

标签: spring spring-cloud


【解决方案1】:

您可以使用 ProxyExchange 来帮助您组合多个响应。

Spring Cloud给出的一个例子:

@RestController
@SpringBootApplication
public class GatewaySampleApplication {

    @Value("${remote.home}")
    private URI home;

    @GetMapping("/test")
    public ResponseEntity<?> proxy(ProxyExchange<byte[]> proxy) throws Exception {
        return proxy.uri(home.toString() + "/image/png").get();
    }

}

在这种情况下,它仅用于返回 ResponseEntity,但您可以随意使用它。在您的情况下,您可以组合多个 ResponseEntities。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-01
    • 2021-05-24
    • 2021-10-23
    • 2020-08-14
    • 1970-01-01
    • 2018-06-09
    • 2020-07-19
    • 1970-01-01
    相关资源
    最近更新 更多