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.
1.9 KiB
1.9 KiB
Spring Cloud Polaris Gateway example
样例简介
本样例将介绍如何在Spring Cloud项目中使用spring-cloud-tencent-polaris-gateway
以使用其各项功能。
本样例包括gateway-zuul-service
、gateway-scg-service
和gateway-callee-service
。gateway-zuul-service
和gateway-scg-service
调用gateway-callee-service
。
使用说明
修改配置
配置如下所示。其中,{ip}和
{port}为Polaris后端服务的IP地址与端口号。
spring:
application:
name: ${application.name}
cloud:
polaris:
address: ${ip}:${port}
启动样例
启动Polaris后端服务
启动应用
- IDEA启动
分别启动spring-cloud-tencent-examples/polaris-gateway-example/gateway-zuul-service
的GatewayZuulService
、spring-cloud-tencent-examples/polaris-gateway-example/gateway-scg-service
的GatewayScgService
和spring-cloud-tencent-examples/polaris-gateway-example/gateway-callee-service
的GatewayCalleeService
- Maven打包启动
在spring-cloud-tencent-examples/polaris-gateway-example
下执行
mvn clean package
然后在gateway-zuul-service
、gateway-scg-service
和gateway-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}