mirror of https://github.com/dtm-labs/dtm.git
11 changed files with 171 additions and 85 deletions
@ -1,38 +1,21 @@ |
|||||
package dtmsvr |
package dtmsvr |
||||
|
|
||||
import ( |
import ( |
||||
"bytes" |
|
||||
"io/ioutil" |
|
||||
"time" |
|
||||
|
|
||||
"github.com/gin-gonic/gin" |
|
||||
"github.com/sirupsen/logrus" |
"github.com/sirupsen/logrus" |
||||
|
"github.com/yedf/dtm/common" |
||||
) |
) |
||||
|
|
||||
func Main() { |
func Main() { |
||||
logrus.Printf("start dtmsvr") |
StartConsumePreparedMsg(1) |
||||
gin.SetMode(gin.ReleaseMode) |
StartConsumeCommitedMsg(1) |
||||
app := gin.Default() |
logrus.Printf("dtmsvr listen at: 8080") |
||||
app.Use(func(c *gin.Context) { |
go StartSvr() |
||||
body := "" |
} |
||||
if c.Request.Method == "POST" { |
|
||||
rb, err := c.GetRawData() |
|
||||
if err != nil { |
|
||||
logrus.Printf("GetRawData error: %s", err.Error()) |
|
||||
} else { |
|
||||
body = string(rb) |
|
||||
c.Request.Body = ioutil.NopCloser(bytes.NewBuffer(rb)) |
|
||||
} |
|
||||
} |
|
||||
began := time.Now() |
|
||||
logrus.Printf("begin %s %s query: %s body: %s", c.Request.Method, c.FullPath(), c.Request.URL.RawQuery, body) |
|
||||
c.Next() |
|
||||
logrus.Printf("used %d ms %s %s query: %s", time.Since(began).Milliseconds(), c.Request.Method, c.FullPath(), c.Request.URL.RawQuery) |
|
||||
|
|
||||
}) |
func StartSvr() { |
||||
|
logrus.Printf("start dtmsvr") |
||||
|
app := common.GetGinApp() |
||||
AddRoute(app) |
AddRoute(app) |
||||
// StartConsumePreparedMsg(1)
|
|
||||
StartConsumeCommitedMsg(1) |
|
||||
logrus.Printf("dtmsvr listen at: 8080") |
logrus.Printf("dtmsvr listen at: 8080") |
||||
go app.Run() |
app.Run() |
||||
} |
} |
||||
|
|||||
@ -1,25 +1,27 @@ |
|||||
package examples |
package examples |
||||
|
|
||||
import ( |
import ( |
||||
"github.com/gin-gonic/gin" |
|
||||
"github.com/sirupsen/logrus" |
"github.com/sirupsen/logrus" |
||||
|
"github.com/yedf/dtm/common" |
||||
) |
) |
||||
|
|
||||
func Main() { |
func Main() { |
||||
|
go StartSvr() |
||||
|
trans(&TransReq{ |
||||
|
Amount: 30, |
||||
|
TransInFailed: false, |
||||
|
TransOutFailed: true, |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
func StartSvr() { |
||||
logrus.Printf("examples starting") |
logrus.Printf("examples starting") |
||||
gin.SetMode(gin.ReleaseMode) |
app := common.GetGinApp() |
||||
app := gin.Default() |
|
||||
app.POST(BusiApi+"/TransIn", TransIn) |
app.POST(BusiApi+"/TransIn", TransIn) |
||||
app.POST(BusiApi+"/TransInCompensate", TransInCompensate) |
app.POST(BusiApi+"/TransInCompensate", TransInCompensate) |
||||
app.POST(BusiApi+"/TransOut", TransOut) |
app.POST(BusiApi+"/TransOut", TransOut) |
||||
app.POST(BusiApi+"/TransOutCompensate", TransOutCompensate) |
app.POST(BusiApi+"/TransOutCompensate", TransOutCompensate) |
||||
app.POST(BusiApi+"/TransQuery", TransQuery) |
app.POST(BusiApi+"/TransQuery", TransQuery) |
||||
|
|
||||
go app.Run(":8081") |
|
||||
logrus.Printf("examples istening at %d", BusiPort) |
logrus.Printf("examples istening at %d", BusiPort) |
||||
trans(&TransReq{ |
app.Run(":8081") |
||||
Amount: 30, |
|
||||
TransInFailed: false, |
|
||||
TransOutFailed: true, |
|
||||
}) |
|
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue