You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
spring-cloud-tencent/spring-cloud-tencent-examples/polaris-gateway-example/README-zh.md

1.9 KiB

Spring Cloud Polaris Gateway example

样例简介

本样例将介绍如何在Spring Cloud项目中使用spring-cloud-tencent-polaris-gateway以使用其各项功能。

本样例包括gateway-zuul-servicegateway-scg-servicegateway-callee-servicegateway-zuul-servicegateway-scg-service调用gateway-callee-service

使用说明

修改配置

配置如下所示。其中,{ip}和{port}为Polaris后端服务的IP地址与端口号。

spring:
  application:
    name: ${application.name}
  cloud:
    polaris:
      address: ${ip}:${port}

启动样例

启动Polaris后端服务

参考Polaris Getting Started

启动应用

  • IDEA启动

分别启动spring-cloud-tencent-examples/polaris-gateway-example/gateway-zuul-serviceGatewayZuulServicespring-cloud-tencent-examples/polaris-gateway-example/gateway-scg-serviceGatewayScgServicespring-cloud-tencent-examples/polaris-gateway-example/gateway-callee-serviceGatewayCalleeService

  • Maven打包启动

spring-cloud-tencent-examples/polaris-gateway-example下执行

mvn clean package

然后在gateway-zuul-servicegateway-scg-servicegateway-callee-service下找到生成的jar包运行

java -jar ${app.jar}

启动应用,其中${app.jar}替换为对应的jar包名。

验证

Zuul调用

curl -L -X GET 'http://localhost:48082/GatewayCalleeService/gateway/example/callee/echo' -H 'SCT-CUSTOM-METADATA: {"b": 2}'

预期返回值

{"a":"1","b":2}

Spring-Cloud-Gateway调用

curl -L -X GET 'http://localhost:48083/GatewayCalleeService/gateway/example/callee/echo' -H 'SCT-CUSTOM-METADATA: {"b": 2}'

预期返回值

{"a":"1","b":2}