Merge pull request #732 from iku50/feat/ecosystem-seata
feat(filter): move new seata samples into transcation directory
diff --git a/go.sum b/go.sum
index 64aa085..c746fc4 100644
--- a/go.sum
+++ b/go.sum
@@ -600,8 +600,6 @@
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
dubbo.apache.org/dubbo-go/v3 v3.0.2-0.20220508105316-b27ec53b7bab/go.mod h1:Ytn9MtmsFYkpa1bzW/3loUFBgm7eJ3M3+XWRurhbBZc=
dubbo.apache.org/dubbo-go/v3 v3.0.2/go.mod h1:bODgByAf72kzG/5YIfZIODXx81pY3gaAdIQ8B4mN/Yk=
-dubbo.apache.org/dubbo-go/v3 v3.1.1-0.20240202021041-198504bb0029 h1:+5r/DyxObRS5gUkyyojGBl/QHs8zIkmX45F0hTjciL4=
-dubbo.apache.org/dubbo-go/v3 v3.1.1-0.20240202021041-198504bb0029/go.mod h1:Aq4YRQHYH5rF6NpeYzPfjTdwhVTOBd5BhdXXstl7EZE=
dubbo.apache.org/dubbo-go/v3 v3.2.0-rc1 h1:31t/KezZ7R9TYpnsQkqSa15chW3UxWEvn41erKmsvrc=
dubbo.apache.org/dubbo-go/v3 v3.2.0-rc1/go.mod h1:4otARIJhwkOBWdRMlOpWLCJ45LR2tu9GhtEkMU5kXyg=
gioui.org v0.0.0-20210308172011-57750fc8a0a6/go.mod h1:RSH6KIUZ0p2xy5zHDxgAM4zumjgTw83q2ge/PI+yyw8=
diff --git a/transcation/seata-go/README.md b/transcation/seata-go/README.md
new file mode 100644
index 0000000..6aac072
--- /dev/null
+++ b/transcation/seata-go/README.md
@@ -0,0 +1,12 @@
+# Seata-go tcc example
+
+## How to run?
+
+1. Start the seata-server with the docker file.
+
+ ```shell
+ cd dockercompose
+ docker-compose -f docker-compose.yml up -d seata-server
+ ```
+
+2. Just execute the main function under tcc/client/cmd and tcc/server/cmd directory.
diff --git a/transcation/seata-go/README_zh.md b/transcation/seata-go/README_zh.md
new file mode 100644
index 0000000..e18581e
--- /dev/null
+++ b/transcation/seata-go/README_zh.md
@@ -0,0 +1,12 @@
+# Seata-go tcc 例子
+
+## 如何运行?
+
+1. 先执行以下命令,启动 seata-server。
+
+ ```shell
+ cd dockercompose
+ docker-compose -f docker-compose.yml up -d seata-server
+ ```
+
+2. 再执行 tcc/client/cmd 和 tcc/server/cmd 目录下的 main()方法。
diff --git a/transcation/seata-go/conf/seatago.yml b/transcation/seata-go/conf/seatago.yml
new file mode 100644
index 0000000..58607f3
--- /dev/null
+++ b/transcation/seata-go/conf/seatago.yml
@@ -0,0 +1,158 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# time 时间单位对应的是 time.Duration(1)
+seata:
+ enabled: true
+ # application id
+ application-id: applicationName
+ # service group
+ tx-service-group: default_tx_group
+ access-key: aliyunAccessKey
+ secret-key: aliyunSecretKey
+ enable-auto-data-source-proxy: true
+ data-source-proxy-mode: AT
+ client:
+ rm:
+ # Maximum cache length of asynchronous queue
+ async-commit-buffer-limit: 10000
+ # The maximum number of retries when report reports the status
+ report-retry-count: 5
+ # The interval for regularly checking the metadata of the db(AT)
+ table-meta-check-enable: false
+ # Whether to report the status if the transaction is successfully executed(AT)
+ report-success-enable: false
+ # Whether to allow regular check of db metadata(AT)
+ saga-branch-register-enable: false
+ saga-json-parser: fastjson
+ saga-retry-persist-mode-update: false
+ saga-compensate-persist-mode-update: false
+ #Ordered.HIGHEST_PRECEDENCE + 1000 #
+ tcc-action-interceptor-order: -2147482648
+ # Parse SQL parser selection
+ sql-parser-type: druid
+ lock:
+ retry-interval: 30
+ retry-times: 10
+ retry-policy-branch-rollback-on-conflict: true
+ tm:
+ commit-retry-count: 5
+ rollback-retry-count: 5
+ default-global-transaction-timeout: 60s
+ degrade-check: false
+ degrade-check-period: 2000
+ degrade-check-allow-times: 10s
+ interceptor-order: -2147482648
+ undo:
+ # Judge whether the before image and after image are the same,If it is the same, undo will not be recorded
+ data-validation: true
+ # Serialization method
+ log-serialization: jackson
+ # undo log table name
+ log-table: undo_log
+ # Only store modified fields
+ only-care-update-columns: true
+ compress:
+ # Compression type. Allowed Options: None, Gzip, Zip, Sevenz, Bzip2, Lz4, Zstd, Deflate
+ type: None
+ # Compression threshold Unit: k
+ threshold: 64k
+ load-balance:
+ type: RandomLoadBalance
+ virtual-nodes: 10
+ service:
+ vgroup-mapping:
+ # Prefix for Print Log
+ default_tx_group: default
+ grouplist:
+ default: 127.0.0.1:8091
+ enable-degrade: false
+ # close the transaction
+ disable-global-transaction: false
+ transport:
+ shutdown:
+ wait: 3s
+ # Netty related configurations
+ # type
+ type: TCP
+ server: NIO
+ heartbeat: true
+ # Encoding and decoding mode
+ serialization: seata
+ # Message compression mode
+ compressor: none
+ # Allow batch sending of requests (TM)
+ enable-tm-client-batch-send-request: false
+ # Allow batch sending of requests (RM)
+ enable-rm-client-batch-send-request: true
+ # RM send request timeout
+ rpc-rm-request-timeout: 30s
+ # TM send request timeout
+ rpc-tm-request-timeout: 30s
+ # Configuration Center
+ config:
+ type: file
+ file:
+ name: config.conf
+ nacos:
+ namespace: ""
+ server-addr: 127.0.0.1:8848
+ group: SEATA_GROUP
+ username: ""
+ password: ""
+ ##if use MSE Nacos with auth, mutex with username/password attribute
+ #access-key: ""
+ #secret-key: ""
+ data-id: seata.properties
+ # Registration Center
+ registry:
+ type: file
+ file:
+ name: registry.conf
+ nacos:
+ application: seata-server
+ server-addr: 127.0.0.1:8848
+ group: "SEATA_GROUP"
+ namespace: ""
+ username: ""
+ password: ""
+ ##if use MSE Nacos with auth, mutex with username/password attribute #
+ #access-key: "" #
+ #secret-key: "" #
+ log:
+ exception-rate: 100
+ tcc:
+ fence:
+ # Anti suspension table name
+ log-table-name: tcc_fence_log_test
+ clean-period: 60s
+ # getty configuration
+ getty:
+ reconnect-interval: 0
+ # temporary not supported connection-num
+ connection-num: 1
+ session:
+ compress-encoding: false
+ tcp-no-delay: true
+ tcp-keep-alive: true
+ keep-alive-period: 120s
+ tcp-r-buf-size: 262144
+ tcp-w-buf-size: 65536
+ tcp-read-timeout: 1s
+ tcp-write-timeout: 5s
+ wait-timeout: 1s
+ max-msg-len: 16498688
+ session-name: client_test
+ cron-period: 1s
diff --git a/transcation/seata-go/dockercompose/docker-compose.yml b/transcation/seata-go/dockercompose/docker-compose.yml
new file mode 100644
index 0000000..995e754
--- /dev/null
+++ b/transcation/seata-go/dockercompose/docker-compose.yml
@@ -0,0 +1,27 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+version: "3"
+services:
+ seata-server:
+ image: seataio/seata-server:2.0.0
+ ports:
+ - "8091:8091"
+ - "7091:7091"
+ environment:
+ - SEATA_PORT=8091
+ - STORE_MODE=file
diff --git a/transcation/seata-go/tcc/client/cmd/client.go b/transcation/seata-go/tcc/client/cmd/client.go
new file mode 100644
index 0000000..48eae48
--- /dev/null
+++ b/transcation/seata-go/tcc/client/cmd/client.go
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package main
+
+import (
+ "context"
+
+ "dubbo.apache.org/dubbo-go/v3"
+ "dubbo.apache.org/dubbo-go/v3/client"
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
+ _ "dubbo.apache.org/dubbo-go/v3/imports"
+
+ "github.com/dubbogo/gost/log/logger"
+
+ _ "github.com/seata/seata-go/pkg/imports"
+ "github.com/seata/seata-go/pkg/integration"
+ "github.com/seata/seata-go/pkg/tm"
+)
+
+// need to setup environment variable "DUBBO_GO_CONFIG_PATH" to "seata-go/tcc/client/conf/dubbogo.yml"
+// and run "seata-go/tcc/server/cmd/server.go" before run
+func main() {
+ integration.UseDubbo()
+ ins, err := dubbo.NewInstance(
+ dubbo.WithName("dubbo_seata_client"),
+ )
+ if err != nil {
+ panic(err)
+ }
+ cli, err := ins.NewClient(
+ client.WithClientURL("127.0.0.1:20000"),
+ client.WithClientProtocolDubbo(),
+ )
+ if err != nil {
+ panic(err)
+ }
+ conn, err := cli.Dial("UserProvider", client.WithSerialization(constant.Hessian2Serialization))
+ if err != nil {
+ panic(err)
+ }
+ test(conn)
+}
+
+func test(conn *client.Connection) {
+ ctx := tm.Begin(context.Background(), "TestTCCServiceBusiness")
+ business(ctx, conn)
+ <-make(chan struct{})
+}
+
+func business(ctx context.Context, conn *client.Connection) (re error) {
+ var resp bool
+ if re := conn.CallUnary(ctx, []interface{}{1}, &resp, "Prepare"); re != nil {
+ logger.Infof("response prepare: %v", re)
+ } else {
+ logger.Infof("get resp %#v", resp)
+ }
+ return
+}
diff --git a/transcation/seata-go/tcc/server/cmd/server.go b/transcation/seata-go/tcc/server/cmd/server.go
new file mode 100644
index 0000000..2d4fd90
--- /dev/null
+++ b/transcation/seata-go/tcc/server/cmd/server.go
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package main
+
+import (
+ "dubbo.apache.org/dubbo-go/v3"
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
+ _ "dubbo.apache.org/dubbo-go/v3/imports"
+ "dubbo.apache.org/dubbo-go/v3/protocol"
+ "dubbo.apache.org/dubbo-go/v3/server"
+
+ "github.com/dubbogo/gost/log/logger"
+
+ _ "github.com/seata/seata-go/pkg/imports"
+ "github.com/seata/seata-go/pkg/integration"
+ "github.com/seata/seata-go/pkg/rm/tcc"
+
+ "github.com/apache/dubbo-go-samples/transcation/seata-go/tcc/service"
+)
+
+func main() {
+ integration.UseDubbo()
+ userProviderProxy, err := tcc.NewTCCServiceProxy(&service.UserProvider{})
+ if err != nil {
+ logger.Errorf("get userProviderProxy tcc service proxy error, %v", err.Error())
+ return
+ }
+ ins, err := dubbo.NewInstance(
+ dubbo.WithName("dubbo_seata_server"),
+ )
+ if err != nil {
+ panic(err)
+ }
+ srv, err := ins.NewServer(
+ server.WithServerProtocol(
+ protocol.WithDubbo(),
+ protocol.WithPort(20000),
+ ),
+ )
+ if err != nil {
+ panic(err)
+ }
+ if err := srv.Register(userProviderProxy, nil, server.WithInterface("UserProvider"), server.WithSerialization(constant.Hessian2Serialization)); err != nil {
+ panic(err)
+ }
+ if err := srv.Serve(); err != nil {
+ panic(err)
+ }
+}
diff --git a/transcation/seata-go/tcc/service/user_provider.go b/transcation/seata-go/tcc/service/user_provider.go
new file mode 100644
index 0000000..9961dfc
--- /dev/null
+++ b/transcation/seata-go/tcc/service/user_provider.go
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package service
+
+import (
+ "context"
+
+ "github.com/dubbogo/gost/log/logger"
+ "github.com/seata/seata-go/pkg/tm"
+)
+
+type UserProvider struct {
+}
+
+func (t *UserProvider) Prepare(ctx context.Context, params ...interface{}) (bool, error) {
+ logger.Infof("Prepare result: %v, xid %v", params, tm.GetXID(ctx))
+ return true, nil
+}
+
+func (t *UserProvider) Commit(ctx context.Context, businessActionContext *tm.BusinessActionContext) (bool, error) {
+ logger.Infof("Commit result: %v, xid %s", businessActionContext, tm.GetXID(ctx))
+ return true, nil
+}
+
+func (t *UserProvider) Rollback(ctx context.Context, businessActionContext *tm.BusinessActionContext) (bool, error) {
+ logger.Infof("Rollback result: %v, xid %s", businessActionContext, tm.GetXID(ctx))
+ return true, nil
+}
+
+func (t *UserProvider) GetActionName() string {
+ logger.Infof("GetActionName result")
+ return "TwoPhaseDemoService"
+}