Skip to content

Commit

Permalink
upgrade(nacos 2.5.0): --v0.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
lltx committed Jan 31, 2025
1 parent c9b9183 commit e22cfbf
Show file tree
Hide file tree
Showing 8 changed files with 306 additions and 628 deletions.
69 changes: 42 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,63 +1,78 @@
Nacos 从 2.2.0 版本开始,可通过 SPI 机制注入多数据源实现插件,并在引入对应数据源实现后,便可在 Nacos 启动时通过读取 application.properties 配置文件中 spring.datasource.platform 配置项选择加载对应多数据源插件.
# Nacos PostgreSQL 数据源插件

![Nacos 插件化实现
](https://minio.pigx.top/oss/202212/1671179590.jpg)

> Nacos 官方默认实现 MySQL、Derby ,其他类型数据库接入需要参考下文自己扩展。
![](https://minio.pigx.top/oss/202212/1671180565.png)
[![Maven Central](https://img.shields.io/maven-central/v/com.pig4cloud.plugin/nacos-datasource-plugin-pg.svg?style=flat-square)](https://maven-badges.herokuapp.com/maven-central/com.pig4cloud.plugin/nacos-datasource-plugin-pg/)

## 自定义 PostgreSQL 插件
Nacos 从 2.2.0 版本开始,可通过 SPI 机制注入多数据源实现插件。引入对应数据源实现后,可在 Nacos 启动时通过读取 `application.properties` 配置文件中 `spring.datasource.platform` 配置项选择加载对应多数据源插件。

### 1. 添加 postgresql 插件
> 注意:Nacos 官方默认实现 MySQL、Derby,其他类型数据库接入需要参考文档自行扩展。
> 依赖已上传 maven 中央仓库,请勿使用阿里云代理
## 版本对应关系

| NACOS 版本 | 插件版本 |
| Nacos 版本 | 插件版本 |
|---------------|-------|
| 2.2.0 - 2.3.0 | 0.0.2 |
| 2.3.1 - 2.3.2 | 0.0.3 |
| 2.4.0 - 2.4.1 | 0.0.4 |
| 2.4.0 - 2.4.3 | 0.0.4 |
| 2.5.0 - | 0.0.5 |

## 使用方法

### 1. 添加依赖

> 注意:依赖已上传 Maven 中央仓库,请勿使用阿里云代理
```xml
<dependency>
<groupId>com.pig4cloud.plugin</groupId>
<artifactId>nacos-datasource-plugin-pg</artifactId>
<version>${nacos.plugin.version}</version>
<groupId>com.pig4cloud.plugin</groupId>
<artifactId>nacos-datasource-plugin-postgresql</artifactId>
<version>${nacos.plugin.version}</version>
</dependency>

<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
```

### 2. 导入 nacos postgresql 数据库脚本
### 2. 初始化数据库

执行 SQL 脚本初始化数据库表结构:./sql/nacos-pg.sql

./sql/nacos-pg.sql
### 3. 配置数据源

### 3. 配置 nacos 数据源链接信息
在 Nacos 的配置文件中添加以下配置:

```yaml
db:
num: 1
url:
0: jdbc:postgresql://172.27.0.5:5432/pigxx_config
user:
0: postgres
password:
0: 123456
0: jdbc:postgresql://127.0.0.1:5432/postgres
user: postgres
password: postgres
pool:
config:
driver-class-name: org.postgresql.Driver
```
### 4. 指定 nacos 数据源平台
### 4. 指定数据源平台
在 Nacos 的配置文件中设置数据源平台为 PostgreSQL:
```yaml
spring:
datasource:
platform: postgresql
```
![](https://minio.pigx.vip/oss/202212/1671184577.png)
## 贡献指南
欢迎提交 Issue 或 Pull Request 来帮助改进这个项目。
## 许可证
本项目采用 [Apache 2.0 许可证](LICENSE)。
![Nacos 插件化实现
](https://minio.pigx.top/oss/202212/1671179590.jpg)
![](https://minio.pigx.top/oss/202212/1671180565.png)
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.pig4cloud.plugin</groupId>
<artifactId>nacos-datasource-plugin-pg</artifactId>
<version>0.0.4</version>
<artifactId>nacos-datasource-plugin-postgresql</artifactId>
<version>0.0.5</version>
<name>nacos-datasource-plugin-pg</name>
<description>nacos-datasource-plugin-pg</description>
<url>https://pig4cloud.com</url>
Expand All @@ -23,7 +23,7 @@
</licenses>

<properties>
<nacos.version>2.4.1</nacos.version>
<nacos.version>2.5.0</nacos.version>
<spring.checkstyle.plugin>0.0.32</spring.checkstyle.plugin>
<maven.compiler.version>3.8.1</maven.compiler.version>
<maven.compiler.source>1.8</maven.compiler.source>
Expand Down
Loading

0 comments on commit e22cfbf

Please sign in to comment.