parent
4bc76f497d
commit
fa9ffa88c2
@ -1,30 +1,31 @@ |
|||||||
* [首页](/?t=1561970396914) |
* [首页](/?t=1561975674071) |
||||||
* 开发文档 |
* 开发文档 |
||||||
* [快速体验](files/10010_快速体验.md?t=1561970396914) |
* [快速体验](files/10010_快速体验.md?t=1561975674073) |
||||||
* [项目接入到SOP](files/10011_项目接入到SOP.md?t=1561970396931) |
* [项目接入到SOP](files/10011_项目接入到SOP.md?t=1561975674089) |
||||||
* [新增接口](files/10020_新增接口.md?t=1561970396931) |
* [新增接口](files/10020_新增接口.md?t=1561975674089) |
||||||
* [业务参数校验](files/10030_业务参数校验.md?t=1561970396931) |
* [业务参数校验](files/10030_业务参数校验.md?t=1561975674090) |
||||||
* [错误处理](files/10040_错误处理.md?t=1561970396931) |
* [错误处理](files/10040_错误处理.md?t=1561975674090) |
||||||
* [编写文档](files/10041_编写文档.md?t=1561970396931) |
* [编写文档](files/10041_编写文档.md?t=1561975674090) |
||||||
* [接口交互详解](files/10050_接口交互详解.md?t=1561970396931) |
* [接口交互详解](files/10050_接口交互详解.md?t=1561975674090) |
||||||
* [easyopen支持](files/10070_easyopen支持.md?t=1561970396932) |
* [easyopen支持](files/10070_easyopen支持.md?t=1561975674090) |
||||||
* [使用签名校验工具](files/10080_使用签名校验工具.md?t=1561970396932) |
* [使用签名校验工具](files/10080_使用签名校验工具.md?t=1561975674090) |
||||||
* [ISV管理](files/10085_ISV管理.md?t=1561970396932) |
* [ISV管理](files/10085_ISV管理.md?t=1561975674090) |
||||||
* [自定义路由](files/10086_自定义路由.md?t=1561970396932) |
* [自定义路由](files/10086_自定义路由.md?t=1561975674090) |
||||||
* [路由授权](files/10090_路由授权.md?t=1561970396932) |
* [路由授权](files/10090_路由授权.md?t=1561975674090) |
||||||
* [接口限流](files/10092_接口限流.md?t=1561970396932) |
* [接口限流](files/10092_接口限流.md?t=1561975674090) |
||||||
* [监控日志](files/10093_监控日志.md?t=1561970396932) |
* [监控日志](files/10093_监控日志.md?t=1561975674091) |
||||||
* [SDK开发](files/10095_SDK开发.md?t=1561970396932) |
* [SDK开发](files/10095_SDK开发.md?t=1561975674091) |
||||||
* [使用SpringCloudGateway](files/10096_使用SpringCloudGateway.md?t=1561970396932) |
* [使用SpringCloudGateway](files/10096_使用SpringCloudGateway.md?t=1561975674091) |
||||||
* [应用授权](files/10097_应用授权.md?t=1561970396932) |
* [应用授权](files/10097_应用授权.md?t=1561975674091) |
||||||
* [更改数据节点名称](files/10099_更改数据节点名称.md?t=1561970396932) |
* [更改数据节点名称](files/10099_更改数据节点名称.md?t=1561975674091) |
||||||
* [对接前端](files/10100_对接前端.md?t=1561970396933) |
* [对接前端](files/10100_对接前端.md?t=1561975674091) |
||||||
* [自定义过滤器](files/10102_自定义过滤器.md?t=1561970396933) |
* [自定义过滤器](files/10102_自定义过滤器.md?t=1561975674091) |
||||||
* [文件上传](files/10104_文件上传.md?t=1561970396933) |
* [文件上传](files/10104_文件上传.md?t=1561975674091) |
||||||
* [nacos注册中心](files/10106_nacos注册中心.md?t=1561970396933) |
* [nacos注册中心](files/10106_nacos注册中心.md?t=1561975674091) |
||||||
|
* [扩展其它注册中心](files/10107_扩展其它注册中心.md?t=1561975674091) |
||||||
* 原理分析 |
* 原理分析 |
||||||
* [原理分析之@ApiMapping](files/90010_原理分析之@ApiMapping.md?t=1561970396933) |
* [原理分析之@ApiMapping](files/90010_原理分析之@ApiMapping.md?t=1561975674092) |
||||||
* [原理分析之路由存储](files/90011_原理分析之路由存储.md?t=1561970396933) |
* [原理分析之路由存储](files/90011_原理分析之路由存储.md?t=1561975674092) |
||||||
* [原理分析之如何路由](files/90012_原理分析之如何路由.md?t=1561970396933) |
* [原理分析之如何路由](files/90012_原理分析之如何路由.md?t=1561975674092) |
||||||
* [原理分析之文档归纳](files/90013_原理分析之文档归纳.md?t=1561970396933) |
* [原理分析之文档归纳](files/90013_原理分析之文档归纳.md?t=1561975674092) |
||||||
* [常见问题](files/90100_常见问题.md?t=1561970396933) |
* [常见问题](files/90100_常见问题.md?t=1561975674092) |
||||||
|
@ -0,0 +1,112 @@ |
|||||||
|
# 扩展其它注册中心 |
||||||
|
|
||||||
|
**注: nacos注册中心已经实现,本篇以nacos为例介绍如何扩展,如果要改成consul,可按照此方式进行修改** |
||||||
|
|
||||||
|
SOP默认使用eureka注册中心,如果要换成nacos注册中心,步骤如下: |
||||||
|
|
||||||
|
- 实现`com.gitee.sop.registryapi.service.RegistryService`接口 |
||||||
|
|
||||||
|
1.找到`SOP/sop-common/sop-registry-api`工程,在service.impl包下新建一个类,实现RegistryService接口 |
||||||
|
|
||||||
|
```java |
||||||
|
public class RegistryServiceNacos implements RegistryService { |
||||||
|
|
||||||
|
@Override |
||||||
|
public List<ServiceInfo> listAllService(int pageNo, int pageSize) throws Exception { |
||||||
|
// TODO: 返回服务实例 |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void onlineInstance(ServiceInstance serviceInstance) throws Exception { |
||||||
|
// TODO: 实例上线 |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void offlineInstance(ServiceInstance serviceInstance) throws Exception { |
||||||
|
// TODO: 实例下线 |
||||||
|
} |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
2.在`com.gitee.sop.registryapi.config.BaseRegistryConfig`中新增 |
||||||
|
|
||||||
|
```java |
||||||
|
/** |
||||||
|
* 当配置了registry.name=nacos生效 |
||||||
|
* |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@Bean |
||||||
|
@ConditionalOnProperty(prefix = "registry", name = "name", havingValue = "nacos") |
||||||
|
RegistryService registryServiceNacos() { |
||||||
|
return new RegistryServiceNacos(); |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
其中`@ConditionalOnProperty(prefix = "registry", name = "name", havingValue = "nacos")` |
||||||
|
表示`application.properties`配置了`registry.name=nacos`参数才能生效,registry.name=nacos下文会讲到。 |
||||||
|
|
||||||
|
|
||||||
|
- 微服务端修改 |
||||||
|
|
||||||
|
1.修改微服务应用pom.xml,注释eureka服务发现依赖,添加nacos服务发现依赖 |
||||||
|
|
||||||
|
```xml |
||||||
|
<!-- 注册中心【只能用一个,不用的注释掉】 --> |
||||||
|
<!-- 使用eureka注册中心 |
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.cloud</groupId> |
||||||
|
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> |
||||||
|
</dependency> |
||||||
|
--> |
||||||
|
|
||||||
|
<!-- 使用nacos注册中心 |
||||||
|
版本 0.2.x.RELEASE 对应的是 Spring Boot 2.x 版本,版本 0.1.x.RELEASE 对应的是 Spring Boot 1.x 版本。 |
||||||
|
https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-alibaba-nacos-discovery |
||||||
|
--> |
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.cloud</groupId> |
||||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> |
||||||
|
<version>0.2.2.RELEASE</version> |
||||||
|
</dependency> |
||||||
|
<!-- 注册中心end --> |
||||||
|
``` |
||||||
|
|
||||||
|
2.yml文件新增nacos配置,并注释掉eureka相关配置 |
||||||
|
|
||||||
|
```yaml |
||||||
|
spring: |
||||||
|
cloud: |
||||||
|
# nacos注册中心,和eureka只能用一个 |
||||||
|
nacos: |
||||||
|
discovery: |
||||||
|
server-addr: 127.0.0.1:8848 |
||||||
|
``` |
||||||
|
|
||||||
|
- 网关修改 |
||||||
|
|
||||||
|
找到`sop-gateway`工程,步骤同上 |
||||||
|
|
||||||
|
- SOP-admin修改 |
||||||
|
|
||||||
|
|
||||||
|
修改yml文件,新增nacos服务器地址,`registry.name`填nacos |
||||||
|
|
||||||
|
```yaml |
||||||
|
# 注册中心地址,根据实际情况改,这里只是参数,并不会去注册 |
||||||
|
registry: |
||||||
|
# 使用eureka,填:eureka,使用nacos填:nacos |
||||||
|
name: nacos |
||||||
|
eureka-server-addr: http://localhost:1111/eureka/ |
||||||
|
nacos-server-addr: 127.0.0.1:8848 |
||||||
|
``` |
||||||
|
|
||||||
|
- website-server修改 |
||||||
|
|
||||||
|
步骤同`SOP-admin修改` |
||||||
|
|
||||||
|
- 参考资料 |
||||||
|
|
||||||
|
1.[nacos介绍及安装](https://nacos.io/zh-cn/docs/quick-start.html) |
||||||
|
|
||||||
|
2.[nacos spring cloud注册发现](https://nacos.io/zh-cn/docs/quick-start-spring-cloud.html) |
Loading…
Reference in new issue