This is an automated email from the ASF dual-hosted git repository.
alexstocks pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-go-samples.git
The following commit(s) were added to refs/heads/master by this push:
new 7e99b8a fix: fix seata sample, make it work properly (#108)
7e99b8a is described below
commit 7e99b8a71268d9b690aa25cd139002a78c4455f4
Author: phil <[email protected]>
AuthorDate: Sun May 16 18:06:40 2021 +0800
fix: fix seata sample, make it work properly (#108)
Co-authored-by: yuefengbo <[email protected]>
---
.run/seata/seata_client_app.run.xml | 16 ++++++++++++++++
.run/seata/seata_order-svc_app.run.xml | 16 ++++++++++++++++
.run/seata/seata_product-svc_app.run.xml | 16 ++++++++++++++++
seata/client/app/svc/svc.go | 18 +++++++++---------
seata/order-svc/app/order_svc.go | 9 +++++----
seata/product-svc/app/product_svc.go | 9 +++++----
6 files changed, 67 insertions(+), 17 deletions(-)
diff --git a/.run/seata/seata_client_app.run.xml
b/.run/seata/seata_client_app.run.xml
new file mode 100644
index 0000000..c34da8c
--- /dev/null
+++ b/.run/seata/seata_client_app.run.xml
@@ -0,0 +1,16 @@
+<component name="ProjectRunConfigurationManager">
+ <configuration default="false" name="seata/client/app"
type="GoApplicationRunConfiguration" factoryName="Go Application">
+ <module name="dubbo-go-samples" />
+ <working_directory value="$PROJECT_DIR$" />
+ <envs>
+ <env name="CONF_CONSUMER_FILE_PATH"
value="$PROJECT_DIR$/seata/client/profiles/dev/client.yml" />
+ <env name="APP_LOG_CONF_FILE"
value="$PROJECT_DIR$/seata/client/profiles/dev/log.yml" />
+ <env name="SEATA_CONF_FILE"
value="$PROJECT_DIR$/seata/client/profiles/dev/seata.yml" />
+ </envs>
+ <kind value="PACKAGE" />
+ <filePath value="$PROJECT_DIR$/seata/client/app/client.go" />
+ <package value="github.com/apache/dubbo-go-samples/seata/client/app" />
+ <directory value="$PROJECT_DIR$" />
+ <method v="2" />
+ </configuration>
+</component>
\ No newline at end of file
diff --git a/.run/seata/seata_order-svc_app.run.xml
b/.run/seata/seata_order-svc_app.run.xml
new file mode 100644
index 0000000..def3fd7
--- /dev/null
+++ b/.run/seata/seata_order-svc_app.run.xml
@@ -0,0 +1,16 @@
+<component name="ProjectRunConfigurationManager">
+ <configuration default="false" name="seata/order-svc/app"
type="GoApplicationRunConfiguration" factoryName="Go Application">
+ <module name="dubbo-go-samples" />
+ <working_directory value="$PROJECT_DIR$" />
+ <envs>
+ <env name="CONF_PROVIDER_FILE_PATH"
value="$PROJECT_DIR$/seata/order-svc/profiles/dev/server.yml" />
+ <env name="APP_LOG_CONF_FILE"
value="$PROJECT_DIR$/seata/order-svc/profiles/dev/log.yml" />
+ <env name="SEATA_CONF_FILE"
value="$PROJECT_DIR$/seata/order-svc/profiles/dev/seata.yml" />
+ </envs>
+ <kind value="PACKAGE" />
+ <filePath value="$PROJECT_DIR$/seata/order-svc/app/server.go" />
+ <package value="github.com/apache/dubbo-go-samples/seata/order-svc/app" />
+ <directory value="$PROJECT_DIR$" />
+ <method v="2" />
+ </configuration>
+</component>
\ No newline at end of file
diff --git a/.run/seata/seata_product-svc_app.run.xml
b/.run/seata/seata_product-svc_app.run.xml
new file mode 100644
index 0000000..7fcfc16
--- /dev/null
+++ b/.run/seata/seata_product-svc_app.run.xml
@@ -0,0 +1,16 @@
+<component name="ProjectRunConfigurationManager">
+ <configuration default="false" name="seata/product-svc/app"
type="GoApplicationRunConfiguration" factoryName="Go Application">
+ <module name="dubbo-go-samples" />
+ <working_directory value="$PROJECT_DIR$" />
+ <envs>
+ <env name="CONF_PROVIDER_FILE_PATH"
value="$PROJECT_DIR$/seata/product-svc/profiles/dev/server.yml" />
+ <env name="APP_LOG_CONF_FILE"
value="$PROJECT_DIR$/seata/product-svc/profiles/dev/log.yml" />
+ <env name="SEATA_CONF_FILE"
value="$PROJECT_DIR$/seata/product-svc/profiles/dev/seata.yml" />
+ </envs>
+ <kind value="PACKAGE" />
+ <filePath value="$PROJECT_DIR$/seata/product-svc/app/server.go" />
+ <package value="github.com/apache/dubbo-go-samples/seata/product-svc/app"
/>
+ <directory value="$PROJECT_DIR$" />
+ <method v="2" />
+ </configuration>
+</component>
\ No newline at end of file
diff --git a/seata/client/app/svc/svc.go b/seata/client/app/svc/svc.go
index 86cb849..5a53342 100644
--- a/seata/client/app/svc/svc.go
+++ b/seata/client/app/svc/svc.go
@@ -19,20 +19,20 @@ package svc
import (
"context"
- "github.com/apache/dubbo-go-samples/seata/filter"
- "github.com/apache/dubbo-go/config"
-
"errors"
)
import (
- "github.com/apache/dubbo-go-samples/seata/order-svc/app/dao"
- dao2 "github.com/apache/dubbo-go-samples/seata/product-svc/app/dao"
+ "github.com/apache/dubbo-go/common/constant"
+ "github.com/apache/dubbo-go/config"
+ context2 "github.com/transaction-wg/seata-golang/pkg/client/context"
+ "github.com/transaction-wg/seata-golang/pkg/client/tm"
)
import (
- context2 "github.com/transaction-wg/seata-golang/pkg/client/context"
- "github.com/transaction-wg/seata-golang/pkg/client/tm"
+ "github.com/apache/dubbo-go-samples/seata/filter"
+ "github.com/apache/dubbo-go-samples/seata/order-svc/app/dao"
+ dao2 "github.com/apache/dubbo-go-samples/seata/product-svc/app/dao"
)
type OrderSvc struct {
@@ -102,7 +102,7 @@ func (svc *Svc) CreateSo(ctx context.Context, rollback
bool) ([]uint64, error) {
var allocateInventoryResult = &dao2.AllocateInventoryResult{}
// 通过 attachment 传递 xid
- err1 := orderSvc.CreateSo(context.WithValue(ctx, "attachment",
map[string]string{
+ err1 := orderSvc.CreateSo(context.WithValue(ctx,
constant.AttachmentKey, map[string]interface{}{
filter.SEATA_XID: rootContext.GetXID(),
}), soMasters, createSoResult)
if err1 != nil {
@@ -110,7 +110,7 @@ func (svc *Svc) CreateSo(ctx context.Context, rollback
bool) ([]uint64, error) {
}
// 通过 attachment 传递 xid
- err2 := productSvc.AllocateInventory(context.WithValue(ctx,
"attachment", map[string]string{
+ err2 := productSvc.AllocateInventory(context.WithValue(ctx,
constant.AttachmentKey, map[string]interface{}{
filter.SEATA_XID: rootContext.GetXID(),
}), reqs, allocateInventoryResult)
if err2 != nil {
diff --git a/seata/order-svc/app/order_svc.go b/seata/order-svc/app/order_svc.go
index e76af65..1cbc4bc 100644
--- a/seata/order-svc/app/order_svc.go
+++ b/seata/order-svc/app/order_svc.go
@@ -22,12 +22,13 @@ import (
)
import (
- "github.com/apache/dubbo-go-samples/seata/filter"
- dao2 "github.com/apache/dubbo-go-samples/seata/order-svc/app/dao"
+ "github.com/apache/dubbo-go/common/constant"
+ context2 "github.com/transaction-wg/seata-golang/pkg/client/context"
)
import (
- context2 "github.com/transaction-wg/seata-golang/pkg/client/context"
+ "github.com/apache/dubbo-go-samples/seata/filter"
+ dao2 "github.com/apache/dubbo-go-samples/seata/order-svc/app/dao"
)
type OrderSvc struct {
@@ -35,7 +36,7 @@ type OrderSvc struct {
}
func (svc *OrderSvc) CreateSo(ctx context.Context, reqs []*dao2.SoMaster)
(*dao2.CreateSoResult, error) {
- attach := ctx.Value("attachment").(map[string]interface{})
+ attach := ctx.Value(constant.AttachmentKey).(map[string]interface{})
val := attach[filter.SEATA_XID]
xid := val.(string)
diff --git a/seata/product-svc/app/product_svc.go
b/seata/product-svc/app/product_svc.go
index 07f93ee..9d97211 100644
--- a/seata/product-svc/app/product_svc.go
+++ b/seata/product-svc/app/product_svc.go
@@ -22,12 +22,13 @@ import (
)
import (
- "github.com/apache/dubbo-go-samples/seata/filter"
- dao2 "github.com/apache/dubbo-go-samples/seata/product-svc/app/dao"
+ "github.com/apache/dubbo-go/common/constant"
+ context2 "github.com/transaction-wg/seata-golang/pkg/client/context"
)
import (
- context2 "github.com/transaction-wg/seata-golang/pkg/client/context"
+ "github.com/apache/dubbo-go-samples/seata/filter"
+ dao2 "github.com/apache/dubbo-go-samples/seata/product-svc/app/dao"
)
type ProductSvc struct {
@@ -35,7 +36,7 @@ type ProductSvc struct {
}
func (svc *ProductSvc) AllocateInventory(ctx context.Context, reqs
[]*dao2.AllocateInventoryReq) (*dao2.AllocateInventoryResult, error) {
- attach := ctx.Value("attachment").(map[string]interface{})
+ attach := ctx.Value(constant.AttachmentKey).(map[string]interface{})
val := attach[filter.SEATA_XID]
xid := val.(string)