今天项目集成Seata时遇到一个奇怪的异常,在此记录一下。
Linux环境安装Seata,使用Nacos作为配置中心、注册中心;
Linux已开放端口:8848、7091、8091
在我Windows环境下可以看到Nacos运行正常,Seata运行也正常:
application.properties:
#========== seata config =============
#seata.enable=true
seata.data-source-proxy-mode=AT
seata.tx-service-group=default_tx_group
#seata.service.vgroup-mapping.default_tx_group=default
#seata.service.grouplist.default=192.168.1.105:8091
#seata.client.undo.log-serialization=kryo
seata.registry.type=nacos
seata.registry.nacos.application=seata-server
seata.registry.nacos.server-addr=192.168.37.130:8848
seata.registry.nacos.group=SEATA_GROUP
seata.registry.nacos.username=nacos
seata.registry.nacos.password=nacos
seata.config.type=nacos
seata.config.nacos.server-addr=192.168.37.130:8848
seata.config.nacos.group=SEATA_GROUP
seata.config.nacos.username=nacos
seata.config.nacos.password=nacos
其中,事务分组default_tx_group的集群配置检查没问题
service.vgroupMapping.default_tx_group=default
service.default.grouplist=192.168.37.130:8091
也检查了Seata相关配置也没发现问题,但是项目运行时抛异常:
com.alibaba.nacos.api.exception.NacosException: Request nacos server failed:
at com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy.requestToServer(NamingGrpcClientProxy.java:288) ~[nacos-client-2.1.0.jar:na]
at com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy.doSubscribe(NamingGrpcClientProxy.java:229) ~[nacos-client-2.1.0.jar:na]
at com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy.subscribe(NamingGrpcClientProxy.java:214) ~[nacos-client-2.1.0.jar:na]
at com.alibaba.nacos.client.naming.remote.NamingClientProxyDelegate.subscribe(NamingClientProxyDelegate.java:147) ~[nacos-client-2.1.0.jar:na]
at com.alibaba.nacos.client.naming.NacosNamingService.getAllInstances(NacosNamingService.java:229) ~[nacos-client-2.1.0.jar:na]
at com.alibaba.nacos.client.naming.NacosNamingService.getAllInstances(NacosNamingService.java:212) ~[nacos-client-2.1.0.jar:na]
at io.seata.discovery.registry.nacos.NacosRegistryServiceImpl.lookup(NacosRegistryServiceImpl.java:129) ~[seata-all-1.4.2.jar:1.4.2]
at io.seata.core.rpc.netty.NettyClientChannelManager.getAvailServerList(NettyClientChannelManager.java:232) ~[seata-all-1.4.2.jar:1.4.2]
at io.seata.core.rpc.netty.NettyClientChannelManager.reconnect(NettyClientChannelManager.java:166) ~[seata-all-1.4.2.jar:1.4.2]
at io.seata.core.rpc.netty.RmNettyRemotingClient.registerResource(RmNettyRemotingClient.java:194) [seata-all-1.4.2.jar:1.4.2]
at io.seata.rm.AbstractResourceManager.registerResource(AbstractResourceManager.java:121) [seata-all-1.4.2.jar:1.4.2]
at io.seata.rm.datasource.DataSourceManager.registerResource(DataSourceManager.java:90) [seata-all-1.4.2.jar:1.4.2]
at io.seata.rm.DefaultResourceManager.registerResource(DefaultResourceManager.java:114) [seata-all-1.4.2.jar:1.4.2]
at io.seata.rm.datasource.DataSourceProxy.init(DataSourceProxy.java:110) [seata-all-1.4.2.jar:1.4.2]
at io.seata.rm.datasource.DataSourceProxy.<init>(DataSourceProxy.java:96) [seata-all-1.4.2.jar:1.4.2]
at io.seata.rm.datasource.DataSourceProxy.<init>(DataSourceProxy.java:81) [seata-all-1.4.2.jar:1.4.2]
at io.seata.spring.annotation.datasource.DataSourceProxyHolder.createDsProxyByMode(DataSourceProxyHolder.java:97) [seata-all-1.4.2.jar:1.4.2]
at io.seata.spring.annotation.datasource.DataSourceProxyHolder.putDataSource(DataSourceProxyHolder.java:88) [seata-all-1.4.2.jar:1.4.2]
at io.seata.spring.annotation.datasource.SeataDataSourceBeanPostProcessor.postProcessAfterInitialization(SeataDataSourceBeanPostProcessor.java:58) [seata-all-1.4.2.jar:1.4.2]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:455) [spring-beans-5.3.13.jar:5.3.13]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1808) [spring-beans-5.3.13.jar:5.3.13]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) [spring-beans-5.3.13.jar:5.3.13]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) [spring-beans-5.3.13.jar:5.3.13]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) [spring-beans-5.3.13.jar:5.3.13]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.13.jar:5.3.13]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) [spring-beans-5.3.13.jar:5.3.13]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) [spring-beans-5.3.13.jar:5.3.13]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944) ~[spring-beans-5.3.13.jar:5.3.13]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.13.jar:5.3.13]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.13.jar:5.3.13]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730) ~[spring-boot-2.6.1.jar:2.6.1]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) ~[spring-boot-2.6.1.jar:2.6.1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:302) ~[spring-boot-2.6.1.jar:2.6.1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[spring-boot-2.6.1.jar:2.6.1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1290) ~[spring-boot-2.6.1.jar:2.6.1]
at com.lee.demo.dubbo.demo.UserServiceProviderApplication.main(UserServiceProviderApplication.java:17) ~[classes/:na]
Caused by: com.alibaba.nacos.api.exception.NacosException: Client not connected, current status:STARTING
at com.alibaba.nacos.common.remote.client.RpcClient.request(RpcClient.java:651) ~[nacos-client-2.1.0.jar:na]
at com.alibaba.nacos.common.remote.client.RpcClient.request(RpcClient.java:631) ~[nacos-client-2.1.0.jar:na]
at com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy.requestToServer(NamingGrpcClientProxy.java:278) ~[nacos-client-2.1.0.jar:na]
... 35 common frames omitted
后来经过查找百度发现了问题所在,因为Nacos2.0新增了gRPC的通信方式,需要在Linux环境开启再多开放两个端口(与主端口偏移量1000,1001)也就是:
9848:8848+1000
9849:8848+1001
然后我在Linux上开放了这两个端口:
然后再运行项目就没有报错了。