topfans/backend/services/userService/configs/README.md
2026-04-07 22:29:48 +08:00

100 lines
1.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Dubbo-go配置文件说明
## 配置文件位置
`configs/dubbo.yaml` - Dubbo-go服务配置
## 配置说明
### 注册中心配置
```yaml
registries:
nacos:
protocol: nacos
address: 127.0.0.1:8848 # Nacos地址
namespace: public
```
**说明**
- 使用Nacos作为服务注册中心
- 默认端口8848
- 可以根据实际情况修改地址
**如何启动Nacos**
```bash
# 下载Nacos
# https://github.com/alibaba/nacos/releases
# 启动Nacos单机模式
./startup.sh -m standalone
# 访问控制台
# http://127.0.0.1:8848/nacos
# 默认账号密码nacos/nacos
```
### 协议配置
```yaml
protocols:
triple:
name: tri
port: 20000 # Dubbo服务端口
serializer: "protobuf" # 使用protobuf序列化
```
**说明**
- 使用Triple协议基于gRPC完全兼容
- 使用protobuf序列化与现有proto定义兼容
- 默认端口20000可在main.go的flag中修改
### 服务配置
```yaml
provider:
services:
UserSocialService:
interface: "" # 服务接口名将在实现Provider时设置
protocol-ids: triple
registry-ids: nacos
serialization: protobuf
```
**说明**
- 服务名称UserSocialService
- 使用triple协议
- 注册到nacos
- 使用protobuf序列化
## 环境变量配置(可选)
可以通过环境变量覆盖配置:
```bash
export DUBBO_REGISTRY_ADDRESS=127.0.0.1:8848
export DUBBO_PROTOCOL_PORT=20000
```
## 配置文件加载
在`main.go`中加载配置:
```go
import (
_ "dubbo.apache.org/dubbo-go/v3/imports"
"dubbo.apache.org/dubbo-go/v3/config"
)
// 加载配置文件
config.Load(config.WithPath("configs/dubbo.yaml"))
```
## 注意事项
1. **Nacos必须启动**服务启动前需要确保Nacos注册中心已启动
2. **端口冲突**确保20000端口未被占用
3. **配置文件路径**:确保运行时能正确读取到配置文件
4. **序列化方式**使用protobuf与现有proto定义兼容