shadowwinds commented on issue #22356:
URL:
https://github.com/apache/shardingsphere/issues/22356#issuecomment-2478119868
> Rewrite the SeataTransactionHolder class to make it public, add an
interceptor and manually call SeataTransactionHolder.set(), it can work
normally, but I don't know if it is correct.
>
> ```java
> public final class SeataTransactionHolder {
>
> private SeataTransactionHolder() {
>
> }
>
> private static final ThreadLocal<GlobalTransaction> CONTEXT = new
ThreadLocal<>();
>
> /**
> * Set seata global transaction.
> *
> * @param transaction global transaction context
> */
> public static void set(final GlobalTransaction transaction) {
> CONTEXT.set(transaction);
> }
>
> /**
> * Get seata global transaction.
> *
> * @return global transaction
> */
> public static GlobalTransaction get() {
> return CONTEXT.get();
> }
>
> /**
> * Clear global transaction.
> */
> public static void clear() {
> CONTEXT.remove();
> }
> }
> ```
>
> ```java
> @Configuration
> public class SeataFeignInterceptorConfiguration implements
WebMvcConfigurer {
>
> @Override
> public void addInterceptors(InterceptorRegistry registry) {
> registry.addInterceptor(new
SeataFeignInterceptor()).addPathPatterns("/**");
> }
>
> public static class SeataFeignInterceptor implements
HandlerInterceptor {
>
> @Override
> public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
> String xid = RootContext.getXID();
> if (xid == null) {
> xid = request.getHeader(RootContext.KEY_XID);
> }
>
> if (!StringUtils.isBlank(xid) && SeataTransactionHolder.get()
== null) {
> RootContext.bind(xid);
>
SeataTransactionHolder.set(GlobalTransactionContext.getCurrentOrCreate());
> }
>
> return true;
> }
> }
> }
> ```
For those using Seata and Sharding Sphere before 5.5.1, you may need to
modify SeataATShardingSphereTransactionManager
https://github.com/apache/shardingsphere/pull/32095/files#diff-e8dafec201902f04425b22562c566322b0dcc4e8680a3ff1b4695484703cba6d
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]