sofastack / sofa-rpc

SOFARPC is a high-performance, high-extensibility, production-level Java RPC framework.
https://www.sofastack.tech/sofa-rpc/docs/Home
Apache License 2.0
3.81k stars 1.17k forks source link

RPC-020060001: 没有获得服务[com.pxy.rpc.SysIpListRpcService:1.0]的调用地址,请检查服务是否已经推送 #993

Closed dwj1979 closed 3 years ago

dwj1979 commented 3 years ago

我创建一个sofa工程提供rpc接口,然后在另一个工程中调用rpc接口,提示如下错误: com.alipay.sofa.rpc.core.exception.SofaRouteException: RPC-020060001: 没有获得服务[com.pxy.rpc.SysIpListRpcService:1.0]的调用地址,请检查服务是否已经推送 at com.alipay.sofa.rpc.client.AbstractCluster.noAvailableProviderException(AbstractCluster.java:490) ~[sofa-rpc-all-5.7.3.jar:5.7.3] at com.alipay.sofa.rpc.client.AbstractCluster.select(AbstractCluster.java:419) ~[sofa-rpc-all-5.7.3.jar:5.7.3] at com.alipay.sofa.rpc.client.FailoverCluster.doInvoke(FailoverCluster.java:65) ~[sofa-rpc-all-5.7.3.jar:5.7.3] at com.alipay.sofa.rpc.client.AbstractCluster.invoke(AbstractCluster.java:297) ~[sofa-rpc-all-5.7.3.jar:5.7.3] at com.alipay.sofa.rpc.client.ClientProxyInvoker.invoke(ClientProxyInvoker.java:83) ~[sofa-rpc-all-5.7.3.jar:5.7.3] at com.pxy.rpc.SysIpListRpcService_proxy_5.blackListIp(SysIpListRpcService_proxy_5.java) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Unknown Source) ~[na:na] at com.alipay.sofa.runtime.service.binding.JvmBindingAdapter$JvmServiceInvoker.doInvoke(JvmBindingAdapter.java:243) ~[runtime-sofa-boot-3.4.4.jar:3.4.4] at com.alipay.sofa.runtime.spi.service.ServiceProxy.invoke(ServiceProxy.java:40) ~[runtime-sofa-boot-3.4.4.jar:3.4.4] at com.alipay.sofa.runtime.service.binding.JvmBindingAdapter$JvmServiceInvoker.invoke(JvmBindingAdapter.java:157) ~[runtime-sofa-boot-3.4.4.jar:3.4.4] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.14.RELEASE.jar:5.1.14.RELEASE] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) ~[spring-aop-5.1.14.RELEASE.jar:5.1.14.RELEASE] at com.sun.proxy.$Proxy121.blackListIp(Unknown Source) ~[na:na] at com.pxy.interceptor.BlacklistIntercepter.checkIpInBlackList(BlacklistIntercepter.java:40) ~[classes/:na] at com.pxy.interceptor.BlacklistIntercepter.preHandle(BlacklistIntercepter.java:29) ~[classes/:na] at org.springframework.web.servlet.HandlerExecutionChain.applyPreHandle(HandlerExecutionChain.java:137) ~[spring-webmvc-5.1.14.RELEASE.jar:5.1.14.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1035) ~[spring-webmvc-5.1.14.RELEASE.jar:5.1.14.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) ~[spring-webmvc-5.1.14.RELEASE.jar:5.1.14.RELEASE] at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.1.14.RELEASE.jar:5.1.14.RELEASE] at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) ~[spring-webmvc-5.1.14.RELEASE.jar:5.1.14.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:660) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.1.14.RELEASE.jar:5.1.14.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.31.jar:9.0.31] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.springframework.web.filter.CorsFilter.doFilterInternal(CorsFilter.java:97) ~[spring-web-5.1.14.RELEASE.jar:5.1.14.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.1.14.RELEASE.jar:5.1.14.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.springframework.boot.actuate.web.trace.servlet.HttpTraceFilter.doFilterInternal(HttpTraceFilter.java:88) ~[spring-boot-actuator-2.1.13.RELEASE.jar:2.1.13.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.1.14.RELEASE.jar:5.1.14.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:114) ~[spring-boot-actuator-2.1.13.RELEASE.jar:2.1.13.RELEASE] at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:104) ~[spring-boot-actuator-2.1.13.RELEASE.jar:2.1.13.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.1.14.RELEASE.jar:5.1.14.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-5.1.14.RELEASE.jar:5.1.14.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.1.14.RELEASE.jar:5.1.14.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:367) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1639) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) ~[na:na] at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) ~[na:na] at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at java.base/java.lang.Thread.run(Unknown Source) ~[na:na]

在调用方的工程启动类上使用如下注解,引入RPC接口,xml文件放在工程的resources目录下 @ImportResource({"classpath:core-service-rpc.xml"})

xml定义如下:

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sofa="http://sofastack.io/schema/sofaboot" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://sofastack.io/schema/sofaboot http://sofastack.io/schema/sofaboot.xsd" default-autowire="byName">

我注册中心使用的是zookeeper,两个工程关于注册中心的配置如下: com: alipay: sofa: rpc: registry-address: zookeeper://192.168.0.192:2181 工程启动后,注册中心也连接成功,日志如下: 2020-11-02 17:23:31.434 INFO 644 --- [ main] o.a.c.f.imps.CuratorFrameworkImpl : Starting 2020-11-02 17:23:31.436 INFO 644 --- [ main] org.apache.zookeeper.ZooKeeper : Initiating client connection, connectString=192.168.0.192:2181 sessionTimeout=60000 watcher=org.apache.curator.ConnectionState@5abb7a8f 2020-11-02 17:23:31.439 INFO 644 --- [ main] org.apache.zookeeper.ClientCnxnSocket : jute.maxbuffer value is 4194304 Bytes 2020-11-02 17:23:31.447 INFO 644 --- [168.0.192:2181)] org.apache.zookeeper.ClientCnxn : Opening socket connection to server 192.168.0.192/192.168.0.192:2181. Will not attempt to authenticate using SASL (unknown error) 2020-11-02 17:23:31.447 INFO 644 --- [168.0.192:2181)] org.apache.zookeeper.ClientCnxn : Socket connection established, initiating session, client: /192.168.0.57:30430, server: 192.168.0.192/192.168.0.192:2181 2020-11-02 17:23:31.451 INFO 644 --- [ main] o.a.c.f.imps.CuratorFrameworkImpl : Default schema 2020-11-02 17:23:31.452 INFO 644 --- [168.0.192:2181)] org.apache.zookeeper.ClientCnxn : Session establishment complete on server 192.168.0.192/192.168.0.192:2181, sessionid = 0x100000175a20037, negotiated timeout = 40000 2020-11-02 17:23:31.458 INFO 644 --- [ain-EventThread] o.a.c.f.state.ConnectionStateManager : State change: CONNECTED 2020-11-02 17:23:31.465 INFO 644 --- [ain-EventThread] o.a.c.framework.imps.EnsembleTracker : New config event received: {} 2020-11-02 17:23:31.466 INFO 644 --- [ain-EventThread] o.a.c.framework.imps.EnsembleTracker : New config event received: {} 通过zookeeper客户端查看,该接口也注册成功了。 zookeeper中该接口的providers下信息如下: bolt://192.168.207.1:12200?version=1.0&accepts=100000&appName=SOFABootExample&weight=100&language=java&pid=6428&interface=com.pxy.rpc.SysIpListRpcService&timeout=3000&serialization=hessian2&protocol=bolt&delay=-1&dynamic=true&startTime=1604308311332&id=rpc-cfg-8&uniqueId=sysIpListServiceRpcImpl&rpcVer=50703 zookeeper中该接口的consumers下信息如下: bolt://192.168.0.57?version=1.0&uniqueId=&pid=4436&timeout=-1&id=sysIpListRpcService&generic=false&interface=com.pxy.rpc.SysIpListRpcService&appName=admin&serialization=hessian2&startTime=1604309751752&pid=4436&language=java&rpcVer=50703 在rpc接口提供方的工程内调用rpc接口是可以的,在其他工程调用接口就出上面的错误
dwj1979 commented 3 years ago

提供方和调用方在同一个开发环境下,为什么提供方注册的接口地址是 bolt://192.168.207.1:12200?..... 这个IP并不是我机器的IP,而调用方的IP地址是正确的,是我的本机IP

dwj1979 commented 3 years ago

我在配置文件中设置了如下配置项: com.alipay.sofa.enabled.ip.range=192.168.0:192.168.0 ,可以让rpc接口提供方在zookeeper注册的接口地址变为我本机物理网卡地址了 bolt://192.168.0.57:12200?.....

但是【RPC-020060001: 没有获得服务[com.pxy.rpc.SysIpListRpcService:1.0]的调用地址,请检查服务是否已经推送】错误依旧

dwj1979 commented 3 years ago

RPC接口定义如下:

@Service @SofaService(uniqueId = "sysIpListServiceRpcImpl", bindings = { @SofaServiceBinding(bindingType = "bolt")} , interfaceType = SysIpListRpcService.class) public class SysIpListServiceRpcImpl implements SysIpListRpcService {

}

hu-chia commented 3 years ago

调用方是否也设置了uniqueId?

ujjboy commented 3 years ago

从 ZK 注册信息里看应该是服务端有 uniqueId,客户端没有 uniqueId。