1、环境说明:
seata 1.2.0
spring boot 2.3.0.M3
spring cloud Hoxton.SR3
eureka作为注册中心
spring cloud alibaba seata 2.2.1.RELEASE (master源码install)
集成后,调用接口提示bug:Load balancer does not have available server for client 。
与issue类似:https://github.com/alibaba/spring-cloud-alibaba/issues/1347
2、解决方式:
https://github.com/alibaba/spring-cloud-alibaba.git 下载源码
2.1、创建工程:xxx-cloud-base-seata 引入依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
<version>1.2.0</version>
<exclusions>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
2.2、复制spring cloud alibaba starter seata 下的两个文件: com.alibaba.cloud.seata.web.SeataHandlerInterceptor com.alibaba.cloud.seata.web.SeataHandlerInterceptorConfiguration
到工程xxx-cloud-base-seata包名com.xxx.cloud.base.seata.web下。
2.3、工程xxx-cloud-base-seata添加如下类:com.xxx.cloud.base.seata.config
import feign.RequestInterceptor;
import feign.RequestTemplate;
import io.seata.core.context.RootContext;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
@Component
public class RequestHeaderInterceptor implements RequestInterceptor {
@Override
public void apply(RequestTemplate template) {
String xid = RootContext.getXID();
if (StringUtils.isNotBlank(xid)) {
template.header(RootContext.KEY_XID, xid);
}
}
}
2.4、在相应的业务工程中引入如上工程:xxx-cloud-base-seata。取消依赖spring-cloud-starter-alibaba-seata(2.2.1.RELEASE版本)或者spring-cloud-alibaba-seata(2.2.0.RELEASE版本)
3、后记:
以上只是目前测试可正常使用的一个处理方法,具体使用情况还在继续测试。