提交 33c5c876 编写于 作者: X xiongchun

网关模块封装 & 网关范例

上级 dacac4b0
......@@ -25,7 +25,7 @@
- **第二步:模块的本地配置文件模版**
```properties
spring.application.name=pangu-examples-dubbo-service
spring.application.name=pangu-examples-config-remote-nacos
spring.profiles.active=${spring.profiles.active:dev}
nacos.config.bootstrap.enable=true
nacos.config.bootstrap.log-enable=true
......@@ -39,7 +39,7 @@
- **第三步:在Nacos配置中心新建配置**
1. 在配置中心新建命名空间,命名空间ID与本地配置文件`application.properties`中的参数`nacos.config.namespace`值一致。(pangu-dev)
2.`pangu-dev`命名空间下,新建配置。DataId与本地配置文件`application.properties`中的参数`nacos.config.data-id`值一致。(pangu-showcases-config)配置如下参数信息。
2.`pangu-dev`命名空间下,新建配置。DataId与本地配置文件`application.properties`中的参数`nacos.config.data-id`值一致。(pangu-examples-config-remote-nacos)配置如下参数信息。
```properties
# 演示参数配置
demo.app.id=XC001001
......
#### :mushroom: 本范例演示功能
1. 如何初始化创建一个基本的盘古空应用
2. 应用日志输出级别的动态热切换演示
3. 如何启动盘古应用(启动参数配置)
1. 如何开发一个网关模块,实现泛华调用后端Dubbo应用。
#### :four_leaf_clover: 如何创建&启动一个盘古空应用
- **第一步:[pom.xml](https://gitee.com/pulanos/pangu-showcases/blob/master/pangu-showcases-empty/pom.xml)**
``` xml
> 盘古网关基于Apache Shenyu 网关系统开发。
> - 支持各种语言(http 协议),支持 Dubbo、 Spring Cloud、 gRPC、 Motan、 Sofa、 Tars 等协议。
> - 灵活的流量筛选,能满足各种流量控制。流量配置动态化,性能极高。
> - 内置丰富的插件支持,鉴权,限流,熔断,防火墙等等。
> - 支持集群部署,支持 A/B Test,蓝绿发布。
#### :four_leaf_clover: 如何开发一个网关模块,实现泛华调用后端Dubbo应用
- **第一步:安装pom依赖**
```xml
<parent>
<groupId>com.gitee.pulanos.pangu</groupId>
<artifactId>pangu-framework-parent</artifactId>
<version>5.0.1</version>
<version>latest.version.xxx</version>
<relativePath/>
</parent>
```
- **第二步:参数配置**
- 本地参数配置([application.properties](https://gitee.com/pulanos/pangu-showcases/blob/master/pangu-showcases-empty/src/main/resources/application.properties))
```
spring.application.name=pangu-showcases-empty
spring.profiles.active=${active}
```xml
<dependencies>
<dependency>
<groupId>com.gitee.pulanos.pangu</groupId>
<artifactId>pangu-framework-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.gitee.pulanos.pangu</groupId>
<artifactId>pangu-framework-gateway-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.gitee.pulanos.pangu</groupId>
<artifactId>pangu-framework-dubbo-spring-boot-starter</artifactId>
</dependency>
</dependencies>
```
- **第二步:模块的本地配置文件模版**
```properties
spring.application.name=pangu-examples-gateway
spring.profiles.active=${spring.profiles.active:dev}
nacos.config.bootstrap.enable=true
nacos.config.bootstrap.log-enable=true
nacos.config.auto-refresh=true
#同名的远程配置将覆盖本地配置
nacos.config.remote-first=true
#对应Nacos配置中心的命名空间ID
nacos.config.namespace=pangu-${active}
nacos.config.server-addr=${nacos.url}
nacos.config.type=properties
nacos.config.data-id=${spring.application.name}.properties
```
- 远程参数配置(Nacos配置中心)
```
server.port=8080
logging.level.root=INFO
logging.level.com.gitee.pulanos.pangu=INFO
logging.level.com.alibaba.nacos.client.config.impl.ClientWorker=WARN
```
> 关于Nacos的安装和基本使用请查看盘古开发相关文档。
nacos.config.namespace=${nacos.namespace:pangu-dev}
nacos.config.server-addr=${nacos.server-addr:127.0.0.1:8848}
nacos.config.type=yaml
nacos.config.data-id=${spring.application.name}.yaml
```
- **第三步:[启动类](https://gitee.com/pulanos/pangu-showcases/blob/master/pangu-showcases-empty/src/main/java/com/gitee/pulanos/pangu/showcases/EmptyApplication.java)**
``` java
@SpringBootApplication
@ComponentScan({"com.gitee.pulanos.pangu"})
public class EmptyApplication {
public static void main(String[] args) {
PanGuApplicationBuilder.init(EmptyApplication.class).run(args);
}
}
```
> :fa-bullhorn: 启动参数设置 :`-Dactive=dev -Dnacos.url=127.0.0.1:8848 -Dnacos.username=xxxx -Dnacos.password=****`
(根据实际情况设置启动参数中Nacos配置中心的连接和认证信息)
#### :rose: 应用日志输出级别的动态热切换演示
登录Nacos配置中心,修改如下log输出级别,查看控制台正在循环输出日志的变化情况。以验证日志级别的动态热切换功能。
```
logging.level.root=INFO
logging.level.com.gitee.pulanos.pangu=INFO
logging.level.com.alibaba.nacos.client.config.impl.ClientWorker=WARN
```
- **第三步:在Nacos配置中心新建配置**
1. 在配置中心新建命名空间,命名空间ID与本地配置文件`application.properties`中的参数`nacos.config.namespace`值一致。(pangu-dev)
2.`pangu-dev`命名空间下,新建配置。DataId与本地配置文件`application.properties`中的参数`nacos.config.data-id`值一致。(pangu-examples-config-remote-nacos)配置如下参数信息。
```yaml
```
\ No newline at end of file
server:
port: 9090
spring:
main:
allow-bean-definition-overriding: true
management:
health:
defaults:
enabled: false
shenyu:
cross:
enabled: true
allowedHeaders:
allowedMethods: "*"
allowedOrigin: "*"
allowedExpose: "*"
maxAge: "18000"
allowCredentials: true
switchConfig:
local: true
file:
enabled: true
maxSize : 10
sync:
websocket:
urls: ws://139.155.46.145:9999/websocket
dubbo:
parameter: multi
exclude:
enabled: false
paths:
- /favicon.ico
extPlugin:
path:
enabled: true
threads: 1
scheduleTime: 300
scheduleDelay: 30
scheduler:
enabled: false
type: fixed
threads: 16
upstreamCheck:
enabled: false
timeout: 3000
healthyThreshold: 1
unhealthyThreshold: 1
interval: 5000
printEnabled: true
printInterval: 60000
logging:
level:
root: info
org.springframework.boot: info
org.apache.ibatis: info
org.apache.shenyu.bonuspoint: info
org.apache.shenyu.lottery: info
org.apache.shenyu: info
......@@ -19,7 +19,6 @@ package com.gitee.pulanos.pangu.framework.starter.autoconfigure;
import cn.hutool.core.util.StrUtil;
import com.alibaba.nacos.api.config.annotation.NacosConfigListener;
import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.alibaba.nacos.spring.util.ConfigParseUtils;
import com.gitee.pulanos.pangu.framework.common.Constants;
import lombok.extern.slf4j.Slf4j;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册