区分环境
This commit is contained in:
25
apps/mqs/etc/mqs.dev.yaml
Normal file
25
apps/mqs/etc/mqs.dev.yaml
Normal file
@@ -0,0 +1,25 @@
|
||||
Name: mq
|
||||
Host: 0.0.0.0
|
||||
Port: 12001
|
||||
|
||||
# kq 消费者组1 - 用于记录
|
||||
KqConsumerLog:
|
||||
Name: kqConsumerLog
|
||||
Brokers:
|
||||
- 127.0.0.1:9092
|
||||
Group: logGroup
|
||||
Topic: apirequest
|
||||
Offset: first
|
||||
Consumers: 2 # 为了避免资源争夺,分配2个消费者
|
||||
Processors: 2
|
||||
|
||||
# kq 消费者组2 - 用于扣款
|
||||
KqConsumerCharge:
|
||||
Name: kqConsumerCharge
|
||||
Brokers:
|
||||
- 127.0.0.1:9092
|
||||
Group: chargeGroup
|
||||
Topic: apirequest
|
||||
Offset: first
|
||||
Consumers: 2 # 同样分配2个消费者
|
||||
Processors: 2
|
||||
@@ -6,7 +6,7 @@ Port: 12001
|
||||
KqConsumerLog:
|
||||
Name: kqConsumerLog
|
||||
Brokers:
|
||||
- 127.0.0.1:9092
|
||||
- tyapi_kafka:9092
|
||||
Group: logGroup
|
||||
Topic: apirequest
|
||||
Offset: first
|
||||
@@ -17,7 +17,7 @@ KqConsumerLog:
|
||||
KqConsumerCharge:
|
||||
Name: kqConsumerCharge
|
||||
Brokers:
|
||||
- 127.0.0.1:9092
|
||||
- tyapi_kafka:9092
|
||||
Group: chargeGroup
|
||||
Topic: apirequest
|
||||
Offset: first
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"flag"
|
||||
"github.com/zeromicro/go-zero/core/service"
|
||||
"os"
|
||||
"tianyuan-api/apps/mqs/internal/config"
|
||||
"tianyuan-api/apps/mqs/internal/mqs"
|
||||
"tianyuan-api/apps/mqs/internal/svc"
|
||||
@@ -12,9 +13,23 @@ import (
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
var configFile = flag.String("f", "etc/mqs.yaml", "the config file")
|
||||
|
||||
func main() {
|
||||
// 读取环境变量 ENV,默认为 "prod"
|
||||
env := os.Getenv("ENV")
|
||||
if env == "" {
|
||||
env = "production"
|
||||
}
|
||||
|
||||
// 根据 ENV 加载不同的配置文件
|
||||
var defaultConfigFile string
|
||||
if env == "development" {
|
||||
defaultConfigFile = "etc/mqs.dev.yaml" // 开发环境配置
|
||||
} else {
|
||||
defaultConfigFile = "etc/mqs.yaml" // 生产环境配置
|
||||
}
|
||||
|
||||
// 允许通过命令行参数覆盖配置文件路径
|
||||
configFile := flag.String("f", defaultConfigFile, "the config file")
|
||||
flag.Parse()
|
||||
|
||||
var c config.Config
|
||||
|
||||
Reference in New Issue
Block a user