Skip to content

Commit f21d0c4

Browse files
authored
optimize: add support for configuring exposeProxy in GlobalTransactionScanner (#6566)
1 parent b2ff764 commit f21d0c4

File tree

8 files changed

+69
-9
lines changed

8 files changed

+69
-9
lines changed

changes/en-us/2.x.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ Add changes here for all PR submitted to the 2.x branch.
1818
- [[#6209](https://github.com/apache/incubator-seata/pull/6209)] Eliminate RpcMessage and Encoder/Decoder dependencies
1919
- [[#6634](https://github.com/apache/incubator-seata/pull/6634)] select channel handles based on protocol versions
2020
- [[#6523](https://github.com/apache/incubator-seata/pull/6523)] upgrade alibaba/druid version to 1.2.20
21-
21+
- [[#6566](https://github.com/apache/incubator-seata/pull/6566)] Add support for configuring exposeProxy in GlobalTransactionScanner
22+
- [[#6534](https://github.com/apache/incubator-seata/pull/6534)] optimize: send async response
2223

2324
### refactor:
24-
- [[#6534](https://github.com/apache/incubator-seata/pull/6534)] optimize: send async response
2525

2626
### security:
2727

@@ -40,5 +40,6 @@ Thanks to these contributors for their code commits. Please report an unintended
4040
- [Bughue](https://github.com/Bughue)
4141
- [funky-eyes](https://github.com/funky-eyes)
4242
- [tanyaofei](https://github.com/tanyaofei)
43+
- [wanghongzhou](https://github.com/wanghongzhou)
4344

4445
Also, we receive many valuable issues, questions and advices from our community. Thanks for you all.

changes/zh-cn/2.x.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
- [[#6209](https://github.com/apache/incubator-seata/pull/6209)] 解开 RpcMessage 和 Encoder/Decoder 的互相依赖
1919
- [[#6634](https://github.com/apache/incubator-seata/pull/6634)] 根据协议版本指定channel handle
2020
- [[#6523](https://github.com/apache/incubator-seata/pull/6523)] 升级 alibaba/druid 的版本到1.2.20
21-
21+
- [[#6566](https://github.com/apache/incubator-seata/pull/6566)] 支持GlobalTransactionScanner类中exposeProxy属性的配置
22+
- [[#6534](https://github.com/apache/incubator-seata/pull/6534)] 优化: 发送异步响应
2223

2324
### refactor:
24-
- [[#6534](https://github.com/apache/incubator-seata/pull/6534)] 优化: 发送异步响应
25+
2526

2627
### security:
2728

@@ -39,6 +40,7 @@
3940
- [Bughue](https://github.com/Bughue)
4041
- [funky-eyes](https://github.com/funky-eyes)
4142
- [tanyaofei](https://github.com/tanyaofei)
43+
- [wanghongzhou](https://github.com/wanghongzhou)
4244

4345

4446
同时,我们收到了社区反馈的很多有价值的issue和建议,非常感谢大家。

compatible/src/main/java/io/seata/spring/annotation/GlobalTransactionScanner.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ public GlobalTransactionScanner(String applicationId, String txServiceGroup, Fai
8585
super(applicationId, txServiceGroup, failureHandlerHook);
8686
}
8787

88+
/**
89+
* Instantiates a new Global transaction scanner.
90+
*
91+
* @param applicationId the application id
92+
* @param txServiceGroup the tx service group
93+
* @param exposeProxy the exposeProxy
94+
* @param failureHandlerHook the failure handler hook
95+
*/
96+
public GlobalTransactionScanner(String applicationId, String txServiceGroup, boolean exposeProxy, FailureHandler failureHandlerHook) {
97+
super(applicationId, txServiceGroup, exposeProxy, failureHandlerHook);
98+
}
99+
88100
/**
89101
* Instantiates a new Global transaction scanner.
90102
*
@@ -94,7 +106,20 @@ public GlobalTransactionScanner(String applicationId, String txServiceGroup, Fai
94106
* @param failureHandlerHook the failure handler hook
95107
*/
96108
public GlobalTransactionScanner(String applicationId, String txServiceGroup, int mode, FailureHandler failureHandlerHook) {
97-
super(applicationId, txServiceGroup, mode, failureHandlerHook);
109+
super(applicationId, txServiceGroup, mode, false, failureHandlerHook);
110+
}
111+
112+
/**
113+
* Instantiates a new Global transaction scanner.
114+
*
115+
* @param applicationId the application id
116+
* @param txServiceGroup the tx service group
117+
* @param mode the mode
118+
* @param exposeProxy the exposeProxy
119+
* @param failureHandlerHook the failure handler hook
120+
*/
121+
public GlobalTransactionScanner(String applicationId, String txServiceGroup, int mode, boolean exposeProxy, FailureHandler failureHandlerHook) {
122+
super(applicationId, txServiceGroup, mode, exposeProxy, failureHandlerHook);
98123
}
99124

100125
protected void initClient() {

script/client/spring/application.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ seata.secret-key=aliyunSecretKey
2626
seata.enable-auto-data-source-proxy=true
2727
seata.data-source-proxy-mode=AT
2828
seata.use-jdk-proxy=false
29+
seata.expose-proxy=false
2930
seata.client.rm.async-commit-buffer-limit=10000
3031
seata.client.rm.report-retry-count=5
3132
seata.client.rm.table-meta-check-enable=false

script/client/spring/application.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ seata:
2424
enable-auto-data-source-proxy: true
2525
data-source-proxy-mode: AT
2626
use-jdk-proxy: false
27+
expose-proxy: false
2728
scan-packages: firstPackage,secondPackage
2829
excludes-for-scanning: firstBeanNameForExclude,secondBeanNameForExclude
2930
excludes-for-auto-proxying: firstClassNameForExclude,secondClassNameForExclude

seata-spring-autoconfigure/seata-spring-autoconfigure-client/src/main/java/org/apache/seata/spring/boot/autoconfigure/properties/SeataProperties.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ public class SeataProperties {
5151
* Whether use JDK proxy instead of CGLIB proxy
5252
*/
5353
private boolean useJdkProxy = false;
54+
/**
55+
* Whether to expose the proxy object through AopContext.
56+
* Setting this to true allows AopContext.currentProxy() to be used to obtain the current proxy,
57+
* which can be useful for invoking methods annotated with @GlobalTransactional within the same class.
58+
*/
59+
private boolean exposeProxy = false;
5460
/**
5561
* The scan packages. If empty, will scan all beans.
5662
*/
@@ -136,6 +142,14 @@ public SeataProperties setUseJdkProxy(boolean useJdkProxy) {
136142
return this;
137143
}
138144

145+
public boolean isExposeProxy() {
146+
return exposeProxy;
147+
}
148+
149+
public void setExposeProxy(boolean exposeProxy) {
150+
this.exposeProxy = exposeProxy;
151+
}
152+
139153
public String[] getExcludesForAutoProxying() {
140154
return excludesForAutoProxying;
141155
}

seata-spring-boot-starter/src/main/java/org/apache/seata/spring/boot/autoconfigure/SeataAutoConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public static GlobalTransactionScanner globalTransactionScanner(SeataProperties
8080
GlobalTransactionScanner.setAccessKey(seataProperties.getAccessKey());
8181
GlobalTransactionScanner.setSecretKey(seataProperties.getSecretKey());
8282
// create global transaction scanner
83-
return new GlobalTransactionScanner(seataProperties.getApplicationId(), seataProperties.getTxServiceGroup(), failureHandler);
83+
return new GlobalTransactionScanner(seataProperties.getApplicationId(), seataProperties.getTxServiceGroup(),
84+
seataProperties.isExposeProxy(), failureHandler);
8485
}
8586
}

spring/src/main/java/org/apache/seata/spring/annotation/GlobalTransactionScanner.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public GlobalTransactionScanner(String applicationId, String txServiceGroup) {
160160
* @param mode the mode
161161
*/
162162
public GlobalTransactionScanner(String applicationId, String txServiceGroup, int mode) {
163-
this(applicationId, txServiceGroup, mode, null);
163+
this(applicationId, txServiceGroup, mode, false, null);
164164
}
165165

166166
/**
@@ -171,7 +171,20 @@ public GlobalTransactionScanner(String applicationId, String txServiceGroup, int
171171
* @param failureHandlerHook the failure handler hook
172172
*/
173173
public GlobalTransactionScanner(String applicationId, String txServiceGroup, FailureHandler failureHandlerHook) {
174-
this(applicationId, txServiceGroup, DEFAULT_MODE, failureHandlerHook);
174+
this(applicationId, txServiceGroup, DEFAULT_MODE, false, failureHandlerHook);
175+
}
176+
177+
/**
178+
* Instantiates a new Global transaction scanner.
179+
*
180+
* @param applicationId the application id
181+
* @param txServiceGroup the tx service group
182+
* @param exposeProxy the exposeProxy
183+
* @param failureHandlerHook the failure handler hook
184+
*/
185+
public GlobalTransactionScanner(String applicationId, String txServiceGroup, boolean exposeProxy,
186+
FailureHandler failureHandlerHook) {
187+
this(applicationId, txServiceGroup, DEFAULT_MODE, exposeProxy, failureHandlerHook);
175188
}
176189

177190
/**
@@ -180,12 +193,14 @@ public GlobalTransactionScanner(String applicationId, String txServiceGroup, Fai
180193
* @param applicationId the application id
181194
* @param txServiceGroup the tx service group
182195
* @param mode the mode
196+
* @param exposeProxy the exposeProxy
183197
* @param failureHandlerHook the failure handler hook
184198
*/
185-
public GlobalTransactionScanner(String applicationId, String txServiceGroup, int mode,
199+
public GlobalTransactionScanner(String applicationId, String txServiceGroup, int mode, boolean exposeProxy,
186200
FailureHandler failureHandlerHook) {
187201
setOrder(ORDER_NUM);
188202
setProxyTargetClass(true);
203+
setExposeProxy(exposeProxy);
189204
this.applicationId = applicationId;
190205
this.txServiceGroup = txServiceGroup;
191206
this.failureHandlerHook = failureHandlerHook;

0 commit comments

Comments
 (0)