compose mysql changed
This commit is contained in:
parent
a83036c87d
commit
ab90c40094
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,5 +1,5 @@
|
|||||||
*/**/*.yml
|
*/**/*.yml
|
||||||
*.yml
|
conf.yml*
|
||||||
*.out
|
*.out
|
||||||
*/**/main
|
*/**/main
|
||||||
main
|
main
|
||||||
@ -2,6 +2,14 @@
|
|||||||
跨语言--语言无关,基于http协议
|
跨语言--语言无关,基于http协议
|
||||||
支持xa、tcc、saga
|
支持xa、tcc、saga
|
||||||
## 快速开始
|
## 快速开始
|
||||||
|
dtm依赖于mysql
|
||||||
|
使用已有的mysql:
|
||||||
|
参考conf.yml.sample将mysql信息填写到conf.yml
|
||||||
|
或者通过docker安装mysql
|
||||||
|
docker-compose up -f docker-compose.mysql.yml
|
||||||
|
启动并运行saga示例
|
||||||
|
go run app/main.go
|
||||||
|
|
||||||
场景描述:
|
场景描述:
|
||||||
假设您实现了一个转账功能,分为两个微服务:转入、转出
|
假设您实现了一个转账功能,分为两个微服务:转入、转出
|
||||||
转出:服务地址为 http://example.com/api/busi_saga/transOut?gid=xxx POST 参数为 {"uid": 2, "amount":30}
|
转出:服务地址为 http://example.com/api/busi_saga/transOut?gid=xxx POST 参数为 {"uid": 2, "amount":30}
|
||||||
|
|||||||
@ -13,8 +13,8 @@ type testConfig struct {
|
|||||||
var config = testConfig{}
|
var config = testConfig{}
|
||||||
|
|
||||||
var myinit int = func() int {
|
var myinit int = func() int {
|
||||||
InitApp(GetProjectPath(), &config)
|
InitApp(GetProjectDir(), &config)
|
||||||
config.Mysql["database"] = "dtm"
|
config.Mysql["database"] = ""
|
||||||
return 0
|
return 0
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|||||||
@ -202,6 +202,10 @@ func InitApp(dir string, config interface{}) {
|
|||||||
configLoaded[dir] = true
|
configLoaded[dir] = true
|
||||||
viper.SetConfigFile(dir + "/conf.yml")
|
viper.SetConfigFile(dir + "/conf.yml")
|
||||||
err := viper.ReadInConfig()
|
err := viper.ReadInConfig()
|
||||||
|
if err != nil {
|
||||||
|
viper.SetConfigFile(dir + "/conf.sample.yml")
|
||||||
|
err = viper.ReadInConfig()
|
||||||
|
}
|
||||||
E2P(err)
|
E2P(err)
|
||||||
}
|
}
|
||||||
err := viper.Unmarshal(config)
|
err := viper.Unmarshal(config)
|
||||||
|
|||||||
@ -96,6 +96,6 @@ func TestResty(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCaller(t *testing.T) {
|
func TestCaller(t *testing.T) {
|
||||||
p := GetProjectPath()
|
p := GetProjectDir()
|
||||||
assert.Equal(t, true, strings.HasSuffix(filepath.Dir(p), "common"))
|
assert.Equal(t, true, strings.HasSuffix(filepath.Dir(p), "common"))
|
||||||
}
|
}
|
||||||
|
|||||||
8
compose.mysql.yml
Normal file
8
compose.mysql.yml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
version: '3.3'
|
||||||
|
services:
|
||||||
|
mysql:
|
||||||
|
image: 'mysql:5.7'
|
||||||
|
environment:
|
||||||
|
MYSQL_ROOT_PASSWORD: my-secret-pw
|
||||||
|
ports:
|
||||||
|
- '3306:3306'
|
||||||
@ -1,8 +1,7 @@
|
|||||||
Mysql:
|
Mysql:
|
||||||
host: 'mysql'
|
host: 'localhost'
|
||||||
user: 'root'
|
user: 'root'
|
||||||
password: 'my-secret-pw'
|
password: 'my-secret-pw'
|
||||||
database: 'dtm'
|
|
||||||
port: '3306'
|
port: '3306'
|
||||||
|
|
||||||
PreparedExpire: 90 # 单位秒,处于prepared中的任务,过了这个时间,查询结果还是PENDING的话,则会被cancel
|
PreparedExpire: 90 # 单位秒,处于prepared中的任务,过了这个时间,查询结果还是PENDING的话,则会被cancel
|
||||||
@ -1,15 +0,0 @@
|
|||||||
version: '3.3'
|
|
||||||
services:
|
|
||||||
api:
|
|
||||||
build: .
|
|
||||||
ports:
|
|
||||||
- '80:4005'
|
|
||||||
volumes:
|
|
||||||
- .:/app/dtm
|
|
||||||
# command: ['sh', '-c', 'go build app/main.go && go test -v ./dtmsvr']
|
|
||||||
mysql:
|
|
||||||
image: 'mysql:5.7'
|
|
||||||
environment:
|
|
||||||
MYSQL_ROOT_PASSWORD: my-secret-pw
|
|
||||||
ports:
|
|
||||||
- '3306:3306'
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
Mysql:
|
|
||||||
host: 'mysql'
|
|
||||||
user: 'root'
|
|
||||||
password: 'my-secret-pw'
|
|
||||||
database: 'dtm'
|
|
||||||
port: '3306'
|
|
||||||
PreparedExpire: 90 # 单位秒,处于prepared中的任务,过了这个时间,查询结果还是PENDING的话,则会被cancel
|
|
||||||
TransCronInterval: 20 # 单位秒 当事务等待这个时间之后,还没有变化,则进行一轮处理,包括prepared中的任务和commited的任务
|
|
||||||
@ -10,3 +10,5 @@ var config = &dtmsvrConfig{
|
|||||||
PreparedExpire: 60,
|
PreparedExpire: 60,
|
||||||
JobCronInterval: 20,
|
JobCronInterval: 20,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var dbName = "dtm"
|
||||||
|
|||||||
@ -14,7 +14,7 @@ import (
|
|||||||
|
|
||||||
var myinit int = func() int {
|
var myinit int = func() int {
|
||||||
common.InitApp(common.GetProjectDir(), &config)
|
common.InitApp(common.GetProjectDir(), &config)
|
||||||
config.Mysql["database"] = "dtm"
|
config.Mysql["database"] = dbName
|
||||||
return 0
|
return 0
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -26,12 +26,13 @@ func TestViper(t *testing.T) {
|
|||||||
func TestDtmSvr(t *testing.T) {
|
func TestDtmSvr(t *testing.T) {
|
||||||
TransProcessedTestChan = make(chan string, 1)
|
TransProcessedTestChan = make(chan string, 1)
|
||||||
PopulateMysql()
|
PopulateMysql()
|
||||||
|
examples.PopulateMysql()
|
||||||
// 启动组件
|
// 启动组件
|
||||||
go StartSvr()
|
go StartSvr()
|
||||||
go examples.SagaStartSvr()
|
go examples.SagaStartSvr()
|
||||||
go examples.XaStartSvr()
|
go examples.XaStartSvr()
|
||||||
go examples.TccStartSvr()
|
go examples.TccStartSvr()
|
||||||
time.Sleep(time.Duration(100 * 1000 * 1000))
|
time.Sleep(time.Duration(200 * 1000 * 1000))
|
||||||
|
|
||||||
// 清理数据
|
// 清理数据
|
||||||
e2p(dbGet().Exec("truncate trans_global").Error)
|
e2p(dbGet().Exec("truncate trans_global").Error)
|
||||||
|
|||||||
@ -17,7 +17,7 @@ func Main() {
|
|||||||
func StartSvr() {
|
func StartSvr() {
|
||||||
logrus.Printf("start dtmsvr")
|
logrus.Printf("start dtmsvr")
|
||||||
common.InitApp(common.GetProjectDir(), &config)
|
common.InitApp(common.GetProjectDir(), &config)
|
||||||
config.Mysql["database"] = "dtm"
|
config.Mysql["database"] = dbName
|
||||||
app := common.GetGinApp()
|
app := common.GetGinApp()
|
||||||
AddRoute(app)
|
AddRoute(app)
|
||||||
logrus.Printf("dtmsvr listen at: %d", dtmsvrPort)
|
logrus.Printf("dtmsvr listen at: %d", dtmsvrPort)
|
||||||
@ -26,6 +26,6 @@ func StartSvr() {
|
|||||||
|
|
||||||
func PopulateMysql() {
|
func PopulateMysql() {
|
||||||
common.InitApp(common.GetProjectDir(), &config)
|
common.InitApp(common.GetProjectDir(), &config)
|
||||||
config.Mysql["database"] = "dtm"
|
config.Mysql["database"] = dbName
|
||||||
examples.RunSqlScript(config.Mysql, common.GetCurrentDir()+"/dtmsvr.sql")
|
examples.RunSqlScript(config.Mysql, common.GetCurrentDir()+"/dtmsvr.sql")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,3 +5,5 @@ type exampleConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var Config = exampleConfig{}
|
var Config = exampleConfig{}
|
||||||
|
|
||||||
|
var dbName = "dtm_busi"
|
||||||
|
|||||||
@ -31,6 +31,6 @@ func RunSqlScript(mysql map[string]string, script string) {
|
|||||||
|
|
||||||
func PopulateMysql() {
|
func PopulateMysql() {
|
||||||
common.InitApp(common.GetProjectDir(), &Config)
|
common.InitApp(common.GetProjectDir(), &Config)
|
||||||
Config.Mysql["database"] = "dtm_busi"
|
Config.Mysql["database"] = dbName
|
||||||
RunSqlScript(Config.Mysql, common.GetCurrentDir()+"/examples.sql")
|
RunSqlScript(Config.Mysql, common.GetCurrentDir()+"/examples.sql")
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user