|
|
@@ -11,23 +11,67 @@ import (
|
|
11
|
11
|
|
|
12
|
12
|
// Config 应用配置
|
|
13
|
13
|
type Config struct {
|
|
14
|
|
- Database DBConfig `yaml:"database"`
|
|
15
|
|
- Redis RedisConfig `yaml:"redis"`
|
|
16
|
|
- Doris DorisConfig `yaml:"doris"`
|
|
17
|
|
- Auth Auth `yaml:"auth"`
|
|
18
|
|
- Service Service `yaml:"service"`
|
|
19
|
|
- HTTP HTTPConfig `yaml:"http"` // 新增 HTTP 配置
|
|
|
14
|
+ Database DBConfig `yaml:"database"`
|
|
|
15
|
+ Redis RedisConfig `yaml:"redis"`
|
|
|
16
|
+ Doris DorisConfig `yaml:"doris"`
|
|
|
17
|
+ RabbitMQ RabbitMQConfig `yaml:"rabbitmq"` // 新增 RabbitMQ 配置
|
|
|
18
|
+ Auth Auth `yaml:"auth"`
|
|
|
19
|
+ Service Service `yaml:"service"`
|
|
|
20
|
+ HTTP HTTPConfig `yaml:"http"`
|
|
|
21
|
+}
|
|
|
22
|
+
|
|
|
23
|
+// RabbitMQConfig RabbitMQ配置
|
|
|
24
|
+type RabbitMQConfig struct {
|
|
|
25
|
+ // 连接配置
|
|
|
26
|
+ Host string `yaml:"host"`
|
|
|
27
|
+ Port int `yaml:"port"`
|
|
|
28
|
+ Username string `yaml:"username"`
|
|
|
29
|
+ Password string `yaml:"password"`
|
|
|
30
|
+ Vhost string `yaml:"vhost"`
|
|
|
31
|
+
|
|
|
32
|
+ // TLS配置
|
|
|
33
|
+ UseTLS bool `yaml:"use_tls"`
|
|
|
34
|
+ CACert string `yaml:"ca_cert"`
|
|
|
35
|
+ CertFile string `yaml:"cert_file"`
|
|
|
36
|
+ KeyFile string `yaml:"key_file"`
|
|
|
37
|
+
|
|
|
38
|
+ // 连接池和超时配置
|
|
|
39
|
+ MaxOpenChannels int `yaml:"max_open_channels"` // 最大通道数
|
|
|
40
|
+ ReconnectDelay int `yaml:"reconnect_delay"` // 重连延迟(毫秒)
|
|
|
41
|
+ MaxReconnectAttempts int `yaml:"max_reconnect_attempts"` // 最大重试次数
|
|
|
42
|
+
|
|
|
43
|
+ // 心跳和超时
|
|
|
44
|
+ Heartbeat int `yaml:"heartbeat"` // 心跳间隔(秒)
|
|
|
45
|
+ ChannelSize int `yaml:"channel_size"` // 通道缓冲区大小
|
|
|
46
|
+
|
|
|
47
|
+ // 队列和交换机默认配置
|
|
|
48
|
+ DefaultExchange string `yaml:"default_exchange"`
|
|
|
49
|
+ DefaultQueue string `yaml:"default_queue"`
|
|
|
50
|
+
|
|
|
51
|
+ // 消息确认模式
|
|
|
52
|
+ AutoAck bool `yaml:"auto_ack"`
|
|
|
53
|
+ Mandatory bool `yaml:"mandatory"`
|
|
|
54
|
+ Immediate bool `yaml:"immediate"`
|
|
|
55
|
+
|
|
|
56
|
+ // QoS配置
|
|
|
57
|
+ PrefetchCount int `yaml:"prefetch_count"` // 预取数量
|
|
|
58
|
+ PrefetchSize int `yaml:"prefetch_size"` // 预取大小(字节)
|
|
|
59
|
+ Global bool `yaml:"global"` // 是否是全局QoS
|
|
|
60
|
+
|
|
|
61
|
+ // 发布确认
|
|
|
62
|
+ PublisherConfirms bool `yaml:"publisher_confirms"` // 是否启用发布者确认
|
|
|
63
|
+ ConfirmTimeout int `yaml:"confirm_timeout"` // 确认超时(秒)
|
|
20
|
64
|
}
|
|
21
|
65
|
|
|
22
|
66
|
// HTTPConfig HTTP客户端配置
|
|
23
|
67
|
type HTTPConfig struct {
|
|
24
|
|
- Timeout int `yaml:"timeout"` // 请求超时时间(秒)
|
|
25
|
|
- MaxIdleConns int `yaml:"max_idle_conns"` // 最大空闲连接数
|
|
26
|
|
- MaxIdleConnsPerHost int `yaml:"max_idle_conns_per_host"` // 每个主机的最大空闲连接数
|
|
27
|
|
- IdleConnTimeout int `yaml:"idle_conn_timeout"` // 空闲连接超时时间(秒)
|
|
28
|
|
- MaxConnsPerHost int `yaml:"max_conns_per_host"` // 每个主机的最大连接数
|
|
29
|
|
- DisableCompression bool `yaml:"disable_compression"` // 是否禁用压缩
|
|
30
|
|
- DisableKeepAlives bool `yaml:"disable_keep_alives"` // 是否禁用长连接
|
|
|
68
|
+ Timeout int `yaml:"timeout"`
|
|
|
69
|
+ MaxIdleConns int `yaml:"max_idle_conns"`
|
|
|
70
|
+ MaxIdleConnsPerHost int `yaml:"max_idle_conns_per_host"`
|
|
|
71
|
+ IdleConnTimeout int `yaml:"idle_conn_timeout"`
|
|
|
72
|
+ MaxConnsPerHost int `yaml:"max_conns_per_host"`
|
|
|
73
|
+ DisableCompression bool `yaml:"disable_compression"`
|
|
|
74
|
+ DisableKeepAlives bool `yaml:"disable_keep_alives"`
|
|
31
|
75
|
}
|
|
32
|
76
|
|
|
33
|
77
|
// DBConfig 数据库配置
|
|
|
@@ -40,45 +84,36 @@ type DBConfig struct {
|
|
40
|
84
|
Database string `yaml:"database"`
|
|
41
|
85
|
MaxOpenConns int `yaml:"max_open_conns"`
|
|
42
|
86
|
MaxIdleConns int `yaml:"max_idle_conns"`
|
|
43
|
|
- ConnMaxLifetime int `yaml:"conn_max_lifetime"` // 单位:秒
|
|
|
87
|
+ ConnMaxLifetime int `yaml:"conn_max_lifetime"`
|
|
44
|
88
|
}
|
|
45
|
89
|
|
|
46
|
90
|
// RedisConfig Redis配置
|
|
47
|
91
|
type RedisConfig struct {
|
|
48
|
|
- Host string `yaml:"host"`
|
|
49
|
|
- Port int `yaml:"port"`
|
|
50
|
|
- Password string `yaml:"password"`
|
|
51
|
|
- DB int `yaml:"db"`
|
|
52
|
|
- PoolSize int `yaml:"pool_size"`
|
|
53
|
|
- // 连接超时和读写超时(秒)
|
|
54
|
|
- DialTimeout int `yaml:"dial_timeout"`
|
|
55
|
|
- ReadTimeout int `yaml:"read_timeout"`
|
|
56
|
|
- WriteTimeout int `yaml:"write_timeout"`
|
|
57
|
|
- // 连接池配置
|
|
58
|
|
- IdleTimeout int `yaml:"idle_timeout"` // 空闲连接超时(秒)
|
|
59
|
|
- MaxConnAge int `yaml:"max_conn_age"` // 连接最大存活时间(秒)
|
|
|
92
|
+ Host string `yaml:"host"`
|
|
|
93
|
+ Port int `yaml:"port"`
|
|
|
94
|
+ Password string `yaml:"password"`
|
|
|
95
|
+ DB int `yaml:"db"`
|
|
|
96
|
+ PoolSize int `yaml:"pool_size"`
|
|
|
97
|
+ DialTimeout int `yaml:"dial_timeout"`
|
|
|
98
|
+ ReadTimeout int `yaml:"read_timeout"`
|
|
|
99
|
+ WriteTimeout int `yaml:"write_timeout"`
|
|
|
100
|
+ IdleTimeout int `yaml:"idle_timeout"`
|
|
|
101
|
+ MaxConnAge int `yaml:"max_conn_age"`
|
|
60
|
102
|
}
|
|
61
|
103
|
|
|
62
|
104
|
// DorisConfig Doris配置
|
|
63
|
105
|
type DorisConfig struct {
|
|
64
|
|
- // FE节点配置
|
|
65
|
|
- FEHost string `yaml:"fe_host"`
|
|
66
|
|
- FEPort int `yaml:"fe_port"`
|
|
67
|
|
- FEUsername string `yaml:"fe_username"`
|
|
68
|
|
- FEPassword string `yaml:"fe_password"`
|
|
69
|
|
-
|
|
70
|
|
- // MySQL协议配置
|
|
71
|
|
- MySQLHost string `yaml:"mysql_host"`
|
|
72
|
|
- MySQLPort int `yaml:"mysql_port"`
|
|
73
|
|
-
|
|
74
|
|
- // 连接池配置
|
|
75
|
|
- MaxOpenConns int `yaml:"max_open_conns"`
|
|
76
|
|
- MaxIdleConns int `yaml:"max_idle_conns"`
|
|
77
|
|
- ConnMaxLifetime int `yaml:"conn_max_lifetime"` // 单位:秒
|
|
78
|
|
-
|
|
79
|
|
- // Stream Load配置
|
|
80
|
|
- StreamLoadTimeout int `yaml:"stream_load_timeout"` // 秒
|
|
81
|
|
- BatchSize int `yaml:"batch_size"` // 批量大小
|
|
|
106
|
+ FEHost string `yaml:"fe_host"`
|
|
|
107
|
+ FEPort int `yaml:"fe_port"`
|
|
|
108
|
+ FEUsername string `yaml:"fe_username"`
|
|
|
109
|
+ FEPassword string `yaml:"fe_password"`
|
|
|
110
|
+ MySQLHost string `yaml:"mysql_host"`
|
|
|
111
|
+ MySQLPort int `yaml:"mysql_port"`
|
|
|
112
|
+ MaxOpenConns int `yaml:"max_open_conns"`
|
|
|
113
|
+ MaxIdleConns int `yaml:"max_idle_conns"`
|
|
|
114
|
+ ConnMaxLifetime int `yaml:"conn_max_lifetime"`
|
|
|
115
|
+ StreamLoadTimeout int `yaml:"stream_load_timeout"`
|
|
|
116
|
+ BatchSize int `yaml:"batch_size"`
|
|
82
|
117
|
}
|
|
83
|
118
|
|
|
84
|
119
|
// Auth 认证配置
|
|
|
@@ -101,13 +136,16 @@ type IConfig interface {
|
|
101
|
136
|
GetDatabase() DBConfig
|
|
102
|
137
|
GetRedis() RedisConfig
|
|
103
|
138
|
GetDoris() DorisConfig
|
|
|
139
|
+ GetRabbitMQ() RabbitMQConfig // 新增获取RabbitMQ配置方法
|
|
104
|
140
|
GetAuth() Auth
|
|
105
|
141
|
GetService() Service
|
|
106
|
|
- GetHTTP() HTTPConfig // 新增获取HTTP配置方法
|
|
|
142
|
+ GetHTTP() HTTPConfig
|
|
107
|
143
|
IsDatabaseConfigured() bool
|
|
108
|
144
|
IsRedisConfigured() bool
|
|
109
|
145
|
IsDorisConfigured() bool
|
|
110
|
|
- IsHTTPConfigured() bool // 新增检查HTTP配置方法
|
|
|
146
|
+ IsRabbitMQConfigured() bool // 新增检查RabbitMQ配置方法
|
|
|
147
|
+ IsHTTPConfigured() bool
|
|
|
148
|
+ IsAuthConfigured() bool
|
|
111
|
149
|
}
|
|
112
|
150
|
|
|
113
|
151
|
// 实现接口的具体类型
|
|
|
@@ -127,6 +165,10 @@ func (cw *configWrapper) GetDoris() DorisConfig {
|
|
127
|
165
|
return cw.config.Doris
|
|
128
|
166
|
}
|
|
129
|
167
|
|
|
|
168
|
+func (cw *configWrapper) GetRabbitMQ() RabbitMQConfig {
|
|
|
169
|
+ return cw.config.RabbitMQ
|
|
|
170
|
+}
|
|
|
171
|
+
|
|
130
|
172
|
func (cw *configWrapper) GetAuth() Auth {
|
|
131
|
173
|
return cw.config.Auth
|
|
132
|
174
|
}
|
|
|
@@ -155,10 +197,15 @@ func (cw *configWrapper) IsRedisConfigured() bool {
|
|
155
|
197
|
|
|
156
|
198
|
func (cw *configWrapper) IsDorisConfigured() bool {
|
|
157
|
199
|
doris := cw.config.Doris
|
|
158
|
|
- // 检查FE配置(HTTP API方式)
|
|
159
|
200
|
return doris.FEHost != "" && doris.FEPort > 0
|
|
160
|
201
|
}
|
|
161
|
202
|
|
|
|
203
|
+func (cw *configWrapper) IsRabbitMQConfigured() bool {
|
|
|
204
|
+ rabbit := cw.config.RabbitMQ
|
|
|
205
|
+ // 基础连接配置检查
|
|
|
206
|
+ return rabbit.Host != "" && rabbit.Port > 0
|
|
|
207
|
+}
|
|
|
208
|
+
|
|
162
|
209
|
func (cw *configWrapper) IsHTTPConfigured() bool {
|
|
163
|
210
|
httpCfg := cw.config.HTTP
|
|
164
|
211
|
return httpCfg.Timeout > 0
|
|
|
@@ -180,7 +227,6 @@ func GetConfig() IConfig {
|
|
180
|
227
|
config, err := loadConfig()
|
|
181
|
228
|
if err != nil {
|
|
182
|
229
|
initErr = err
|
|
183
|
|
- // 创建一个空的配置实例,避免nil指针
|
|
184
|
230
|
instance = &configWrapper{config: &Config{}}
|
|
185
|
231
|
return
|
|
186
|
232
|
}
|
|
|
@@ -196,7 +242,6 @@ func GetInitError() error {
|
|
196
|
242
|
|
|
197
|
243
|
// loadConfig 加载配置文件
|
|
198
|
244
|
func loadConfig() (*Config, error) {
|
|
199
|
|
-
|
|
200
|
245
|
configFile, err := findConfigFile()
|
|
201
|
246
|
if err != nil {
|
|
202
|
247
|
return nil, err
|
|
|
@@ -222,7 +267,7 @@ func loadConfig() (*Config, error) {
|
|
222
|
267
|
ReadTimeout: 3,
|
|
223
|
268
|
WriteTimeout: 3,
|
|
224
|
269
|
IdleTimeout: 300,
|
|
225
|
|
- MaxConnAge: 0, // 0表示不限制
|
|
|
270
|
+ MaxConnAge: 0,
|
|
226
|
271
|
},
|
|
227
|
272
|
Doris: DorisConfig{
|
|
228
|
273
|
FEPort: 8030,
|
|
|
@@ -238,11 +283,34 @@ func loadConfig() (*Config, error) {
|
|
238
|
283
|
MaxIdleConns: 100,
|
|
239
|
284
|
MaxIdleConnsPerHost: 10,
|
|
240
|
285
|
IdleConnTimeout: 90,
|
|
241
|
|
- MaxConnsPerHost: 0, // 0表示不限制
|
|
|
286
|
+ MaxConnsPerHost: 0,
|
|
242
|
287
|
DisableCompression: false,
|
|
243
|
288
|
DisableKeepAlives: false,
|
|
244
|
289
|
},
|
|
|
290
|
+ RabbitMQ: RabbitMQConfig{
|
|
|
291
|
+ Port: 5672,
|
|
|
292
|
+ Username: "guest",
|
|
|
293
|
+ Password: "guest",
|
|
|
294
|
+ Vhost: "/",
|
|
|
295
|
+ UseTLS: false,
|
|
|
296
|
+ MaxOpenChannels: 10,
|
|
|
297
|
+ ReconnectDelay: 5000, // 5秒
|
|
|
298
|
+ MaxReconnectAttempts: 10, // 最多重试10次
|
|
|
299
|
+ Heartbeat: 30, // 30秒心跳
|
|
|
300
|
+ ChannelSize: 100,
|
|
|
301
|
+ DefaultExchange: "amq.direct",
|
|
|
302
|
+ DefaultQueue: "",
|
|
|
303
|
+ AutoAck: false, // 默认手动确认
|
|
|
304
|
+ Mandatory: false,
|
|
|
305
|
+ Immediate: false,
|
|
|
306
|
+ PrefetchCount: 1, // 一次预取1条消息
|
|
|
307
|
+ PrefetchSize: 0,
|
|
|
308
|
+ Global: false,
|
|
|
309
|
+ PublisherConfirms: false, // 默认不启用发布确认
|
|
|
310
|
+ ConfirmTimeout: 30, // 5秒确认超时
|
|
|
311
|
+ },
|
|
245
|
312
|
}
|
|
|
313
|
+
|
|
246
|
314
|
// 读取配置文件
|
|
247
|
315
|
data, err := os.ReadFile(configFile)
|
|
248
|
316
|
if err != nil {
|