You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@seata.apache.org by ji...@apache.org on 2024/07/02 02:10:57 UTC

(incubator-seata) branch 2.x updated: optimize: add support for configuring exposeProxy in GlobalTransactionScanner (#6566)

This is an automated email from the ASF dual-hosted git repository.

jianbin pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/incubator-seata.git


The following commit(s) were added to refs/heads/2.x by this push:
     new f21d0c43b1 optimize: add support for configuring exposeProxy in GlobalTransactionScanner (#6566)
f21d0c43b1 is described below

commit f21d0c43b115ea8a5a7c2776989c325da3afc862
Author: Brian Wang <wh...@163.com>
AuthorDate: Tue Jul 2 10:10:53 2024 +0800

    optimize: add support for configuring exposeProxy in GlobalTransactionScanner (#6566)
---
 changes/en-us/2.x.md                               |  5 ++--
 changes/zh-cn/2.x.md                               |  6 +++--
 .../annotation/GlobalTransactionScanner.java       | 27 +++++++++++++++++++++-
 script/client/spring/application.properties        |  1 +
 script/client/spring/application.yml               |  1 +
 .../autoconfigure/properties/SeataProperties.java  | 14 +++++++++++
 .../boot/autoconfigure/SeataAutoConfiguration.java |  3 ++-
 .../annotation/GlobalTransactionScanner.java       | 21 ++++++++++++++---
 8 files changed, 69 insertions(+), 9 deletions(-)

diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md
index 7b6b41522b..9ac1a7f5c2 100644
--- a/changes/en-us/2.x.md
+++ b/changes/en-us/2.x.md
@@ -18,10 +18,10 @@ Add changes here for all PR submitted to the 2.x branch.
 - [[#6209](https://github.com/apache/incubator-seata/pull/6209)] Eliminate RpcMessage and Encoder/Decoder dependencies
 - [[#6634](https://github.com/apache/incubator-seata/pull/6634)] select channel handles based on protocol versions
 - [[#6523](https://github.com/apache/incubator-seata/pull/6523)] upgrade alibaba/druid version to 1.2.20
-
+- [[#6566](https://github.com/apache/incubator-seata/pull/6566)] Add support for configuring exposeProxy in GlobalTransactionScanner
+- [[#6534](https://github.com/apache/incubator-seata/pull/6534)] optimize: send async response
 
 ### refactor:
-- [[#6534](https://github.com/apache/incubator-seata/pull/6534)] optimize: send async response
 
 ### security:
 
@@ -40,5 +40,6 @@ Thanks to these contributors for their code commits. Please report an unintended
 - [Bughue](https://github.com/Bughue)
 - [funky-eyes](https://github.com/funky-eyes)
 - [tanyaofei](https://github.com/tanyaofei)
+- [wanghongzhou](https://github.com/wanghongzhou)
 
 Also, we receive many valuable issues, questions and advices from our community. Thanks for you all.
diff --git a/changes/zh-cn/2.x.md b/changes/zh-cn/2.x.md
index 686908c99c..c856e78517 100644
--- a/changes/zh-cn/2.x.md
+++ b/changes/zh-cn/2.x.md
@@ -18,10 +18,11 @@
 - [[#6209](https://github.com/apache/incubator-seata/pull/6209)] 解开 RpcMessage 和 Encoder/Decoder 的互相依赖
 - [[#6634](https://github.com/apache/incubator-seata/pull/6634)] 根据协议版本指定channel handle
 - [[#6523](https://github.com/apache/incubator-seata/pull/6523)] 升级 alibaba/druid 的版本到1.2.20
-
+- [[#6566](https://github.com/apache/incubator-seata/pull/6566)] 支持GlobalTransactionScanner类中exposeProxy属性的配置
+- [[#6534](https://github.com/apache/incubator-seata/pull/6534)] 优化: 发送异步响应
 
 ### refactor:
-- [[#6534](https://github.com/apache/incubator-seata/pull/6534)] 优化: 发送异步响应
+
 
 ### security:
 
@@ -39,6 +40,7 @@
 - [Bughue](https://github.com/Bughue)
 - [funky-eyes](https://github.com/funky-eyes)
 - [tanyaofei](https://github.com/tanyaofei)
+- [wanghongzhou](https://github.com/wanghongzhou)
 
 
 同时,我们收到了社区反馈的很多有价值的issue和建议,非常感谢大家。
diff --git a/compatible/src/main/java/io/seata/spring/annotation/GlobalTransactionScanner.java b/compatible/src/main/java/io/seata/spring/annotation/GlobalTransactionScanner.java
index 5d8108b645..171af91aad 100644
--- a/compatible/src/main/java/io/seata/spring/annotation/GlobalTransactionScanner.java
+++ b/compatible/src/main/java/io/seata/spring/annotation/GlobalTransactionScanner.java
@@ -85,6 +85,18 @@ public class GlobalTransactionScanner extends org.apache.seata.spring.annotation
         super(applicationId, txServiceGroup, failureHandlerHook);
     }
 
+    /**
+     * Instantiates a new Global transaction scanner.
+     *
+     * @param applicationId      the application id
+     * @param txServiceGroup     the tx service group
+     * @param exposeProxy        the exposeProxy
+     * @param failureHandlerHook the failure handler hook
+     */
+    public GlobalTransactionScanner(String applicationId, String txServiceGroup, boolean exposeProxy, FailureHandler failureHandlerHook) {
+        super(applicationId, txServiceGroup, exposeProxy, failureHandlerHook);
+    }
+
     /**
      * Instantiates a new Global transaction scanner.
      *
@@ -94,7 +106,20 @@ public class GlobalTransactionScanner extends org.apache.seata.spring.annotation
      * @param failureHandlerHook the failure handler hook
      */
     public GlobalTransactionScanner(String applicationId, String txServiceGroup, int mode, FailureHandler failureHandlerHook) {
-        super(applicationId, txServiceGroup, mode, failureHandlerHook);
+        super(applicationId, txServiceGroup, mode, false, failureHandlerHook);
+    }
+
+    /**
+     * Instantiates a new Global transaction scanner.
+     *
+     * @param applicationId      the application id
+     * @param txServiceGroup     the tx service group
+     * @param mode               the mode
+     * @param exposeProxy        the exposeProxy
+     * @param failureHandlerHook the failure handler hook
+     */
+    public GlobalTransactionScanner(String applicationId, String txServiceGroup, int mode, boolean exposeProxy, FailureHandler failureHandlerHook) {
+        super(applicationId, txServiceGroup, mode, exposeProxy, failureHandlerHook);
     }
 
     protected void initClient() {
diff --git a/script/client/spring/application.properties b/script/client/spring/application.properties
index eddf85d617..f74bcbb53b 100755
--- a/script/client/spring/application.properties
+++ b/script/client/spring/application.properties
@@ -26,6 +26,7 @@ seata.secret-key=aliyunSecretKey
 seata.enable-auto-data-source-proxy=true
 seata.data-source-proxy-mode=AT
 seata.use-jdk-proxy=false
+seata.expose-proxy=false
 seata.client.rm.async-commit-buffer-limit=10000
 seata.client.rm.report-retry-count=5
 seata.client.rm.table-meta-check-enable=false
diff --git a/script/client/spring/application.yml b/script/client/spring/application.yml
index 6034f5a653..951002d5f8 100755
--- a/script/client/spring/application.yml
+++ b/script/client/spring/application.yml
@@ -24,6 +24,7 @@ seata:
   enable-auto-data-source-proxy: true
   data-source-proxy-mode: AT
   use-jdk-proxy: false
+  expose-proxy: false
   scan-packages: firstPackage,secondPackage
   excludes-for-scanning: firstBeanNameForExclude,secondBeanNameForExclude
   excludes-for-auto-proxying: firstClassNameForExclude,secondClassNameForExclude
diff --git a/seata-spring-autoconfigure/seata-spring-autoconfigure-client/src/main/java/org/apache/seata/spring/boot/autoconfigure/properties/SeataProperties.java b/seata-spring-autoconfigure/seata-spring-autoconfigure-client/src/main/java/org/apache/seata/spring/boot/autoconfigure/properties/SeataProperties.java
index 70775df3ba..a71ae89283 100644
--- a/seata-spring-autoconfigure/seata-spring-autoconfigure-client/src/main/java/org/apache/seata/spring/boot/autoconfigure/properties/SeataProperties.java
+++ b/seata-spring-autoconfigure/seata-spring-autoconfigure-client/src/main/java/org/apache/seata/spring/boot/autoconfigure/properties/SeataProperties.java
@@ -51,6 +51,12 @@ public class SeataProperties {
      * Whether use JDK proxy instead of CGLIB proxy
      */
     private boolean useJdkProxy = false;
+    /**
+     * Whether to expose the proxy object through AopContext.
+     * Setting this to true allows AopContext.currentProxy() to be used to obtain the current proxy,
+     * which can be useful for invoking methods annotated with @GlobalTransactional within the same class.
+     */
+    private boolean exposeProxy = false;
     /**
      * The scan packages. If empty, will scan all beans.
      */
@@ -136,6 +142,14 @@ public class SeataProperties {
         return this;
     }
 
+    public boolean isExposeProxy() {
+        return exposeProxy;
+    }
+
+    public void setExposeProxy(boolean exposeProxy) {
+        this.exposeProxy = exposeProxy;
+    }
+
     public String[] getExcludesForAutoProxying() {
         return excludesForAutoProxying;
     }
diff --git a/seata-spring-boot-starter/src/main/java/org/apache/seata/spring/boot/autoconfigure/SeataAutoConfiguration.java b/seata-spring-boot-starter/src/main/java/org/apache/seata/spring/boot/autoconfigure/SeataAutoConfiguration.java
index 9c05742694..005087e42b 100644
--- a/seata-spring-boot-starter/src/main/java/org/apache/seata/spring/boot/autoconfigure/SeataAutoConfiguration.java
+++ b/seata-spring-boot-starter/src/main/java/org/apache/seata/spring/boot/autoconfigure/SeataAutoConfiguration.java
@@ -80,6 +80,7 @@ public class SeataAutoConfiguration {
         GlobalTransactionScanner.setAccessKey(seataProperties.getAccessKey());
         GlobalTransactionScanner.setSecretKey(seataProperties.getSecretKey());
         // create global transaction scanner
-        return new GlobalTransactionScanner(seataProperties.getApplicationId(), seataProperties.getTxServiceGroup(), failureHandler);
+        return new GlobalTransactionScanner(seataProperties.getApplicationId(), seataProperties.getTxServiceGroup(),
+                seataProperties.isExposeProxy(), failureHandler);
     }
 }
diff --git a/spring/src/main/java/org/apache/seata/spring/annotation/GlobalTransactionScanner.java b/spring/src/main/java/org/apache/seata/spring/annotation/GlobalTransactionScanner.java
index 4ccee7dcd9..2170e59958 100644
--- a/spring/src/main/java/org/apache/seata/spring/annotation/GlobalTransactionScanner.java
+++ b/spring/src/main/java/org/apache/seata/spring/annotation/GlobalTransactionScanner.java
@@ -160,7 +160,7 @@ public class GlobalTransactionScanner extends AbstractAutoProxyCreator
      * @param mode           the mode
      */
     public GlobalTransactionScanner(String applicationId, String txServiceGroup, int mode) {
-        this(applicationId, txServiceGroup, mode, null);
+        this(applicationId, txServiceGroup, mode, false, null);
     }
 
     /**
@@ -171,7 +171,20 @@ public class GlobalTransactionScanner extends AbstractAutoProxyCreator
      * @param failureHandlerHook the failure handler hook
      */
     public GlobalTransactionScanner(String applicationId, String txServiceGroup, FailureHandler failureHandlerHook) {
-        this(applicationId, txServiceGroup, DEFAULT_MODE, failureHandlerHook);
+        this(applicationId, txServiceGroup, DEFAULT_MODE, false, failureHandlerHook);
+    }
+
+    /**
+     * Instantiates a new Global transaction scanner.
+     *
+     * @param applicationId      the application id
+     * @param txServiceGroup     the tx service group
+     * @param exposeProxy        the exposeProxy
+     * @param failureHandlerHook the failure handler hook
+     */
+    public GlobalTransactionScanner(String applicationId, String txServiceGroup, boolean exposeProxy,
+                                    FailureHandler failureHandlerHook) {
+        this(applicationId, txServiceGroup, DEFAULT_MODE, exposeProxy, failureHandlerHook);
     }
 
     /**
@@ -180,12 +193,14 @@ public class GlobalTransactionScanner extends AbstractAutoProxyCreator
      * @param applicationId      the application id
      * @param txServiceGroup     the tx service group
      * @param mode               the mode
+     * @param exposeProxy        the exposeProxy
      * @param failureHandlerHook the failure handler hook
      */
-    public GlobalTransactionScanner(String applicationId, String txServiceGroup, int mode,
+    public GlobalTransactionScanner(String applicationId, String txServiceGroup, int mode, boolean exposeProxy,
                                     FailureHandler failureHandlerHook) {
         setOrder(ORDER_NUM);
         setProxyTargetClass(true);
+        setExposeProxy(exposeProxy);
         this.applicationId = applicationId;
         this.txServiceGroup = txServiceGroup;
         this.failureHandlerHook = failureHandlerHook;


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org