1.update the nacos uri selector to find the same group instance.

2.update version to 1.2.0.
3.update the readme doc.
This commit is contained in:
zhongjie
2020-11-17 10:36:48 +08:00
parent fffc88293c
commit 93fa5f9c46
4 changed files with 56 additions and 11 deletions

View File

@@ -66,6 +66,7 @@ A Managerment API Gateway in Java . Fizz Gateway 是一个基于 Java开发的
| v1.0.0 | v1.0.0 | v1.0.0 |
| v1.1.0 | v1.1.0 | v1.1.0 |
| v1.1.1 | v1.1.1 | v1.1.1 |
| v1.2.0 | v1.2.0 | v1.1.1 |
请根据社区版的版本下载对应的管理后台版本
@@ -93,13 +94,13 @@ A Managerment API Gateway in Java . Fizz Gateway 是一个基于 Java开发的
##### 管理后台服务端fizz-manager-professional
1. 首次安装执行`fizz-manager-professional-1.1.1-mysql.sql`数据库脚本
2.`application-prod.yml``boot.sh``fizz-manager-professional-1.1.1.jar`拷贝到`/data/webapps/fizz-manager-professional`目录下
1. 首次安装执行`fizz-manager-professional-1.2.0-mysql.sql`数据库脚本
2.`application-prod.yml``boot.sh``fizz-manager-professional-1.2.0.jar`拷贝到`/data/webapps/fizz-manager-professional`目录下
3. 修改`application-prod.yml`文件,将相关配置修改成部署环境的配置
4. 修改`boot.sh`文件,将`RUN_CMD`变量值修改成部署环境的JAVA实际路径
5. 执行 `chmod +x boot.sh` 命令给`boot.sh`增加执行权限
6. 执行 `./boot.sh start` 命令启动服务,支持 start/stop/restart/status命令
7. 服务启动后访问 http://IP:8000/fizz-manager 将IP替换成服务部署机器IP地址,使用超级管理员账户`admin`密码`Aa123!`登录
7. 服务启动后访问前端登录地址,使用超级管理员账户`admin`密码`Aa123!`登录
##### 管理后台前端fizz-admin-professional
@@ -126,11 +127,14 @@ server {
#### 二、安装fizz-gateway-community社区版
说明:如果使用apollo配置中心可把application.yml文件内容迁到配置中心apollo上应用名为fizz-gateway使用不使用apollo可去掉下面启动命令里的apollo参数。
说明:
1. 支持配置中心apollo、nacos支持注册中心eureka、nacos详细配置方法查看application.yml文件。
2. 如果使用apollo配置中心可把application.yml文件内容迁到配置中心apollo上应用名为fizz-gateway如果不使用apollo可去掉下面启动命令里的apollo参数。
安装方式一:脚本启动:
1. 下载fizz-gateway-community的最新代码修改application.yml配置文件里eureka、redis的配置使用maven命令`mvn clean package -DskipTests=true`构建并把构建好的fizz-gateway-community-1.1.1.jar和boot.sh放同一目录
1. 下载fizz-gateway-community的最新代码修改application.yml配置文件里配置中心、注册中心、redis的配置使用maven命令`mvn clean package -DskipTests=true`构建并把构建好的fizz-gateway-community-1.2.0.jar和boot.sh放同一目录
2. 修改boot.sh脚本的apollo连接JVM内存配置
3. 执行 `./boot.sh start` 命令启动服务,支持 start/stop/restart/status命令
@@ -138,13 +142,13 @@ server {
1. 本地clone仓库上的最新代码
2. 将项目fizz-gateway导入IDE
3. 导入完成后设置项目启动配置及修改application.yml配置文件里eureka、redis的配置在VM选项中加入`-Denv=dev -Dapollo.meta=http://localhost:66`(Apollo配置中心地址)
3. 导入完成后设置项目启动配置及修改application.yml配置文件里配置中心、注册中心、redis的配置在VM选项中加入`-Denv=dev -Dapollo.meta=http://localhost:66`(Apollo配置中心地址)
安装方式三jar启动:
1. 本地clone仓库上的最新代码修改application.yml配置文件里eureka、redis的配置
1. 本地clone仓库上的最新代码修改application.yml配置文件里配置中心、注册中心、redis的配置
2. 在项目根目录fizz-gateway-community下执行Maven命令`mvn clean package -DskipTests=true`打包
3. 进入target目录使用命令`java -jar -Denv=DEV -Dapollo.meta=http://localhost:66 fizz-gateway-community-1.1.1.jar`启动服务
3. 进入target目录使用命令`java -jar -Denv=DEV -Dapollo.meta=http://localhost:66 fizz-gateway-community-1.2.0.jar`启动服务
最后访问网关地址形式为http://127.0.0.1:8600/proxy/[服务名]/[API Path]

View File

@@ -10,7 +10,7 @@
</parent>
<groupId>we</groupId>
<artifactId>fizz-gateway-community</artifactId>
<version>1.1.1</version>
<version>1.2.0</version>
<name>fizz-gateway-community</name>
<repositories>

View File

@@ -6,7 +6,7 @@ cd `dirname $0`
#变量定义
APOLLO_META_SERVER=http://localhost:66
ENV=dev
APP_NAME=fizz-gateway-community-1.1.1.jar
APP_NAME=fizz-gateway-community-1.2.0.jar
APP_DEP_DIR=/data/webapps/fizz-gateway
APP_LOG_DIR=/data/logs/fizz-gateway
JAVA_CMD=/usr/local/java/bin/java

View File

@@ -1,5 +1,7 @@
package we.proxy;
import com.alibaba.boot.nacos.discovery.properties.NacosDiscoveryProperties;
import com.alibaba.boot.nacos.discovery.properties.Register;
import com.alibaba.nacos.api.annotation.NacosInjected;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingService;
@@ -8,6 +10,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.annotation.PostConstruct;
import java.util.Collections;
import java.util.List;
/**
* The Nacos implementation of {@code DiscoveryClientUriSelector}
@@ -19,8 +26,34 @@ import org.springframework.stereotype.Service;
public class NacosUriSelector extends AbstractDiscoveryClientUriSelector {
private static final Logger log = LoggerFactory.getLogger(NacosUriSelector.class);
public NacosUriSelector(NacosDiscoveryProperties discoveryProperties) {
this.discoveryProperties = discoveryProperties;
}
@NacosInjected
private NamingService naming;
private NacosDiscoveryProperties discoveryProperties;
private String groupName;
private List<String> clusterNameList;
private boolean useGroupName;
private boolean userClusterName;
@PostConstruct
public void init() {
Register register = discoveryProperties.getRegister();
if (register != null) {
this.groupName = register.getGroupName();
if (StringUtils.hasText(groupName)) {
this.useGroupName = true;
}
String clusterName = register.getClusterName();
if (StringUtils.hasText(clusterName)) {
this.userClusterName = true;
this.clusterNameList = Collections.singletonList(clusterName);
}
}
}
@Override
public String getNextUri(String service, String relativeUri) {
@@ -31,7 +64,15 @@ public class NacosUriSelector extends AbstractDiscoveryClientUriSelector {
private Instance selectOneHealthyInstance(String service) {
Instance instance = null;
try {
if (useGroupName && userClusterName) {
instance = naming.selectOneHealthyInstance(service, groupName, clusterNameList);
} else if (useGroupName) {
instance = naming.selectOneHealthyInstance(service, groupName);
} else if (userClusterName) {
instance = naming.selectOneHealthyInstance(service, clusterNameList);
} else {
instance = naming.selectOneHealthyInstance(service);
}
} catch (NacosException e) {
log.warn("Nacos selectOneHealthyInstance({}) exception", service, e);
}