From 3036086b34f9a4d4fd34f32a45c13b625164be5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?WangLiang/=E7=8E=8B=E8=89=AF?= <841369634@qq.com> Date: Wed, 21 Dec 2022 18:41:19 +0800 Subject: [PATCH 1/2] optimize: alibaba-seata: Transfer XID using `feign.RequestInterceptor` (#1946) (#2993) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * optimize: alibaba-seata: Transfer XID using `feign.RequestInterceptor` * 移除多余的代码 * imports顺序调整。 * Feign.Builder的默认retryer修改为NEVER_RETRY。 * fix style * fix style * Update SeataFeignBuilderBeanPostProcessor.java * add static --- .../feign/SeataContextBeanPostProcessor.java | 61 -------------- .../SeataFeignBlockingLoadBalancerClient.java | 47 ----------- .../cloud/seata/feign/SeataFeignBuilder.java | 35 -------- ...> SeataFeignBuilderBeanPostProcessor.java} | 30 ++++--- .../cloud/seata/feign/SeataFeignClient.java | 81 ------------------- .../SeataFeignClientAutoConfiguration.java | 45 ++--------- .../cloud/seata/feign/SeataFeignContext.java | 69 ---------------- .../seata/feign/SeataFeignObjectWrapper.java | 55 ------------- ...java => SeataFeignRequestInterceptor.java} | 30 ++++--- 9 files changed, 37 insertions(+), 416 deletions(-) delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataContextBeanPostProcessor.java delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignBlockingLoadBalancerClient.java delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignBuilder.java rename spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/{SeataBeanPostProcessor.java => SeataFeignBuilderBeanPostProcessor.java} (61%) delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignClient.java delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignContext.java delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignObjectWrapper.java rename spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/{SeataSentinelFeignBuilder.java => SeataFeignRequestInterceptor.java} (55%) diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataContextBeanPostProcessor.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataContextBeanPostProcessor.java deleted file mode 100644 index 37b0de3a71..0000000000 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataContextBeanPostProcessor.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2013-2023 the original author or authors. - * - * Licensed 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 - * - * https://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 com.alibaba.cloud.seata.feign; - -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.BeanFactory; -import org.springframework.beans.factory.config.BeanPostProcessor; -import org.springframework.cloud.openfeign.FeignClientFactory; - -/** - * @author xiaojing - */ -public class SeataContextBeanPostProcessor implements BeanPostProcessor { - - private final BeanFactory beanFactory; - - private SeataFeignObjectWrapper seataFeignObjectWrapper; - - SeataContextBeanPostProcessor(BeanFactory beanFactory) { - this.beanFactory = beanFactory; - } - - @Override - public Object postProcessBeforeInitialization(Object bean, String beanName) - throws BeansException { - if (bean instanceof FeignClientFactory && !(bean instanceof SeataFeignContext)) { - return new SeataFeignContext(getSeataFeignObjectWrapper(), - (FeignClientFactory) bean); - } - return bean; - } - - @Override - public Object postProcessAfterInitialization(Object bean, String beanName) - throws BeansException { - return bean; - } - - private SeataFeignObjectWrapper getSeataFeignObjectWrapper() { - if (this.seataFeignObjectWrapper == null) { - this.seataFeignObjectWrapper = this.beanFactory - .getBean(SeataFeignObjectWrapper.class); - } - return this.seataFeignObjectWrapper; - } - -} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignBlockingLoadBalancerClient.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignBlockingLoadBalancerClient.java deleted file mode 100644 index 89be6211a4..0000000000 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignBlockingLoadBalancerClient.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2013-2023 the original author or authors. - * - * Licensed 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 - * - * https://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 com.alibaba.cloud.seata.feign; - -import java.io.IOException; - -import feign.Client; -import feign.Request; -import feign.Response; - -import org.springframework.cloud.loadbalancer.blocking.client.BlockingLoadBalancerClient; -import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory; -import org.springframework.cloud.openfeign.loadbalancer.FeignBlockingLoadBalancerClient; - -/** - * @author yuhuangbin - */ -public class SeataFeignBlockingLoadBalancerClient - extends FeignBlockingLoadBalancerClient { - - public SeataFeignBlockingLoadBalancerClient(Client delegate, - BlockingLoadBalancerClient loadBalancerClient, - LoadBalancerClientFactory loadBalancerClientFactory, - SeataFeignObjectWrapper seataFeignObjectWrapper) { - super((Client) seataFeignObjectWrapper.wrap(delegate), loadBalancerClient, loadBalancerClientFactory); - } - - @Override - public Response execute(Request request, Request.Options options) throws IOException { - return super.execute(request, options); - } - -} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignBuilder.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignBuilder.java deleted file mode 100644 index 750bb024e8..0000000000 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignBuilder.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2013-2023 the original author or authors. - * - * Licensed 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 - * - * https://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 com.alibaba.cloud.seata.feign; - -import feign.Feign; - -import org.springframework.beans.factory.BeanFactory; - -/** - * @author xiaojing - */ -final class SeataFeignBuilder { - - private SeataFeignBuilder() { - } - - static Feign.Builder builder(BeanFactory beanFactory) { - return Feign.builder().client(new SeataFeignClient(beanFactory)); - } - -} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataBeanPostProcessor.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignBuilderBeanPostProcessor.java similarity index 61% rename from spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataBeanPostProcessor.java rename to spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignBuilderBeanPostProcessor.java index fbb540536c..8c903fd193 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataBeanPostProcessor.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignBuilderBeanPostProcessor.java @@ -16,30 +16,28 @@ package com.alibaba.cloud.seata.feign; +import feign.Feign; +import feign.Retryer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; /** - * @author xiaojing + * @author wang.liang + * @since 2.2.5 */ -public class SeataBeanPostProcessor implements BeanPostProcessor { - - private final SeataFeignObjectWrapper seataFeignObjectWrapper; +public class SeataFeignBuilderBeanPostProcessor implements BeanPostProcessor { - SeataBeanPostProcessor(SeataFeignObjectWrapper seataFeignObjectWrapper) { - this.seataFeignObjectWrapper = seataFeignObjectWrapper; - } + private static final Logger LOGGER = LoggerFactory.getLogger(SeataFeignBuilderBeanPostProcessor.class); @Override - public Object postProcessBeforeInitialization(Object bean, String beanName) - throws BeansException { - return this.seataFeignObjectWrapper.wrap(bean); - } - - @Override - public Object postProcessAfterInitialization(Object bean, String beanName) - throws BeansException { + public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { + if (bean instanceof Feign.Builder) { + ((Feign.Builder) bean).retryer(Retryer.NEVER_RETRY); + LOGGER.info("change the retryer of the bean '{}' to 'Retryer.NEVER_RETRY'", beanName); + } return bean; } - } diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignClient.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignClient.java deleted file mode 100644 index e0cd1da422..0000000000 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignClient.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2013-2023 the original author or authors. - * - * Licensed 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 - * - * https://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 com.alibaba.cloud.seata.feign; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import com.alibaba.cloud.commons.lang.StringUtils; -import feign.Client; -import feign.Request; -import feign.Response; -import io.seata.core.context.RootContext; - -import org.springframework.beans.factory.BeanFactory; - -/** - * @author xiaojing - */ -public class SeataFeignClient implements Client { - - private final Client delegate; - - private final BeanFactory beanFactory; - - private static final int MAP_SIZE = 16; - - SeataFeignClient(BeanFactory beanFactory) { - this.beanFactory = beanFactory; - this.delegate = new Client.Default(null, null); - } - - SeataFeignClient(BeanFactory beanFactory, Client delegate) { - this.delegate = delegate; - this.beanFactory = beanFactory; - } - - @Override - public Response execute(Request request, Request.Options options) throws IOException { - - Request modifiedRequest = getModifyRequest(request); - return this.delegate.execute(modifiedRequest, options); - } - - private Request getModifyRequest(Request request) { - - String xid = RootContext.getXID(); - - if (StringUtils.isEmpty(xid)) { - return request; - } - - Map> headers = new HashMap<>(MAP_SIZE); - headers.putAll(request.headers()); - - List seataXid = new ArrayList<>(); - seataXid.add(xid); - headers.put(RootContext.KEY_XID, seataXid); - - return Request.create(request.httpMethod(), request.url(), headers, request.body(), - request.charset(), null); - } - -} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignClientAutoConfiguration.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignClientAutoConfiguration.java index 2e3de55b3a..4928d8301a 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignClientAutoConfiguration.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignClientAutoConfiguration.java @@ -17,62 +17,27 @@ package com.alibaba.cloud.seata.feign; import feign.Client; -import feign.Feign; -import org.springframework.beans.factory.BeanFactory; -import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.cloud.openfeign.FeignAutoConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Scope; /** * @author xiaojing + * @author wang.liang */ - @Configuration(proxyBeanMethods = false) @ConditionalOnClass(Client.class) -@AutoConfigureBefore(FeignAutoConfiguration.class) public class SeataFeignClientAutoConfiguration { @Bean - @Scope("prototype") - @ConditionalOnClass(name = "com.alibaba.csp.sentinel.SphU") - @ConditionalOnProperty(name = "feign.sentinel.enabled", havingValue = "true") - Feign.Builder feignSentinelBuilder(BeanFactory beanFactory) { - return SeataSentinelFeignBuilder.builder(beanFactory); + public static SeataFeignBuilderBeanPostProcessor seataFeignBuilderBeanPostProcessor() { + return new SeataFeignBuilderBeanPostProcessor(); } @Bean - @ConditionalOnMissingBean - @Scope("prototype") - Feign.Builder feignBuilder(BeanFactory beanFactory) { - return SeataFeignBuilder.builder(beanFactory); - } - - @Configuration(proxyBeanMethods = false) - protected static class FeignBeanPostProcessorConfiguration { - - @Bean - static SeataBeanPostProcessor seataBeanPostProcessor( - SeataFeignObjectWrapper seataFeignObjectWrapper) { - return new SeataBeanPostProcessor(seataFeignObjectWrapper); - } - - @Bean - static SeataContextBeanPostProcessor seataContextBeanPostProcessor( - BeanFactory beanFactory) { - return new SeataContextBeanPostProcessor(beanFactory); - } - - @Bean - SeataFeignObjectWrapper seataFeignObjectWrapper(BeanFactory beanFactory) { - return new SeataFeignObjectWrapper(beanFactory); - } - + public SeataFeignRequestInterceptor seataFeignRequestInterceptor() { + return new SeataFeignRequestInterceptor(); } } diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignContext.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignContext.java deleted file mode 100644 index d5076c96f8..0000000000 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignContext.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2013-2023 the original author or authors. - * - * Licensed 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 - * - * https://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 com.alibaba.cloud.seata.feign; - -import java.util.HashMap; -import java.util.Map; - -import feign.Client; - -import org.springframework.cloud.openfeign.FeignClientFactory; - -/** - * @author xiaojing - */ -public class SeataFeignContext extends FeignClientFactory { - - private final SeataFeignObjectWrapper seataFeignObjectWrapper; - - private final FeignClientFactory delegate; - - SeataFeignContext(SeataFeignObjectWrapper seataFeignObjectWrapper, - FeignClientFactory delegate) { - this.seataFeignObjectWrapper = seataFeignObjectWrapper; - this.delegate = delegate; - } - - @Override - public T getInstance(String name, Class type) { - T object = this.delegate.getInstance(name, type); - if (object instanceof Client) { - return object; - } - return (T) this.seataFeignObjectWrapper.wrap(object); - } - - @Override - public Map getInstances(String name, Class type) { - Map instances = this.delegate.getInstances(name, type); - if (instances == null) { - return null; - } - Map convertedInstances = new HashMap<>(); - for (Map.Entry entry : instances.entrySet()) { - if (entry.getValue() instanceof Client) { - convertedInstances.put(entry.getKey(), entry.getValue()); - } - else { - convertedInstances.put(entry.getKey(), - (T) this.seataFeignObjectWrapper.wrap(entry.getValue())); - } - } - return convertedInstances; - } - -} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignObjectWrapper.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignObjectWrapper.java deleted file mode 100644 index c73a366027..0000000000 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignObjectWrapper.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2013-2023 the original author or authors. - * - * Licensed 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 - * - * https://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 com.alibaba.cloud.seata.feign; - -import feign.Client; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.springframework.beans.factory.BeanFactory; -import org.springframework.cloud.loadbalancer.blocking.client.BlockingLoadBalancerClient; -import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory; -import org.springframework.cloud.openfeign.loadbalancer.FeignBlockingLoadBalancerClient; - -/** - * @author xiaojing - */ -public class SeataFeignObjectWrapper { - - private static final Logger LOG = LoggerFactory - .getLogger(SeataFeignObjectWrapper.class); - - private final BeanFactory beanFactory; - - - SeataFeignObjectWrapper(BeanFactory beanFactory) { - this.beanFactory = beanFactory; - } - - Object wrap(Object bean) { - if (bean instanceof Client client && !(bean instanceof SeataFeignClient)) { - if (bean instanceof FeignBlockingLoadBalancerClient feignBlockingLoadBalancerClient) { - return new SeataFeignBlockingLoadBalancerClient(feignBlockingLoadBalancerClient.getDelegate(), - beanFactory.getBean(BlockingLoadBalancerClient.class), - beanFactory.getBean(LoadBalancerClientFactory.class), - this); - } - return new SeataFeignClient(this.beanFactory, client); - } - return bean; - } -} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataSentinelFeignBuilder.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignRequestInterceptor.java similarity index 55% rename from spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataSentinelFeignBuilder.java rename to spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignRequestInterceptor.java index 229549371d..b226bf0a5c 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataSentinelFeignBuilder.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignRequestInterceptor.java @@ -16,23 +16,29 @@ package com.alibaba.cloud.seata.feign; -import com.alibaba.cloud.sentinel.feign.SentinelFeign; -import feign.Feign; -import feign.Retryer; +import java.util.ArrayList; +import java.util.List; -import org.springframework.beans.factory.BeanFactory; +import feign.RequestInterceptor; +import feign.RequestTemplate; +import io.seata.core.context.RootContext; + +import org.springframework.util.StringUtils; /** - * @author xiaojing + * @author wang.liang */ -final class SeataSentinelFeignBuilder { +public class SeataFeignRequestInterceptor implements RequestInterceptor { - private SeataSentinelFeignBuilder() { - } + @Override + public void apply(RequestTemplate template) { + String xid = RootContext.getXID(); + if (StringUtils.isEmpty(xid)) { + return; + } - static Feign.Builder builder(BeanFactory beanFactory) { - return SentinelFeign.builder().retryer(Retryer.NEVER_RETRY) - .client(new SeataFeignClient(beanFactory)); + List seataXid = new ArrayList<>(); + seataXid.add(xid); + template.header(RootContext.KEY_XID, xid); } - } From a7bee567513e41acd5d68b4611c3cd8cd6b3804f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=89=AF?= <841369634@qq.com> Date: Thu, 23 Feb 2023 10:35:33 +0800 Subject: [PATCH 2/2] fix Deprecated --- .../alibaba/cloud/seata/feign/SeataFeignRequestInterceptor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignRequestInterceptor.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignRequestInterceptor.java index b226bf0a5c..50baa54743 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignRequestInterceptor.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignRequestInterceptor.java @@ -33,7 +33,7 @@ public class SeataFeignRequestInterceptor implements RequestInterceptor { @Override public void apply(RequestTemplate template) { String xid = RootContext.getXID(); - if (StringUtils.isEmpty(xid)) { + if (!StringUtils.hasLength(xid)) { return; }