前言
其实像这种找不到方法的,无外乎就是两种原因
- 服务提供方未注册,通常是提交了代码但未重新部署
- 服务消费方的jar版本与服务提供方的不一致,通常是服务消费方引用了旧版本的jar,找不到新的方法,这种可能是人为忘记更新jar,也可能是版本冲突导致引用了低版本的jar
现场
Failed to invoke the method queryOrder3 in the service com.example.order.service.IOrderService.
Tried 1 times of the providers [192.168.9.9:20991] (1/1) from the registry 192.168.9.193:2181 on the consumer 192.168.9.190 using the dubbo version 2.5.3.
Last error is: Failed to invoke remote method: queryOrder3, provider: dubbo://192.168.9.9:20991/com.example.order.service.IOrderService?accesslog=true&anyhost=true&application=ods_backend_consumer&check=false&default.check=true&default.retries=0&default.timeout=15000&dubbo=2.5.3&interface=com.example.order.service.IOrderService&logger=log4j&methods=queryOrder1,queryOrder2&pid=11212&revision=3.2.10-SNAPSHOT&side=consumer×tamp=1603184881391&version=1.0, cause: com.alibaba.dubbo.rpc.RpcException: Failed to invoke remote proxy method queryOrder3 to registry://192.168.9.193:2181/com.alibaba.dubbo.registry.RegistryService?application=ods_provider&backup=192.168.9.193:2182,192.168.9.193:2183&dubbo=2.5.3&export=dubbo%3A%2F%2F172.20.0.49%3A20991%2Fcom.example.order.service.IOrderService%3Faccesslog%3Dtrue%26anyhost%3Dtrue%26application%3Dods_provider%26default.retries%3D0%26default.timeout%3D15000%26dubbo%3D2.5.3%26interface%3Dcom.example.order.service.IOrderService%26logger%3Dlog4j%26methods%3queryOrder1%2CqueryOrder2%26pid%3D1%26revision%3DSNAPSHOT%26side%3Dprovider%26threadpool%3Dfixed%26timestamp%3D1603076554376%26version%3D1.0&logger=log4j&pid=1®istry=zookeeper×tamp=1603076554361, cause: Not found method "queryOrder3" in class com.example.order.service.IOrderService.
at com.alibaba.dubbo.rpc.proxy.AbstractProxyInvoker.invoke(AbstractProxyInvoker.java:76)
...
at java.lang.Thread.run(Thread.java:745)
Caused by: com.alibaba.dubbo.common.bytecode.NoSuchMethodException: Not found method "queryOrder3" in class com.example.order.service.IOrderService.
at com.alibaba.dubbo.common.bytecode.Wrapper16.invokeMethod(Wrapper16.java)
at com.alibaba.dubbo.rpc.proxy.javassist.JavassistProxyFactory$1.doInvoke(JavassistProxyFactory.java:46)
at com.alibaba.dubbo.rpc.proxy.AbstractProxyInvoker.invoke(AbstractProxyInvoker.java:72)
... 27 more
关注的信息点:
- 第 1 行,调用IOrderService的queryOrdre3发生了异常
- 第 3 行,服务提供者的地址是 192.168.9.9:20991
- 第 7 行,具体错误原因是找不到queryOrder3这个方法
排查思路
按照前言的错误类型逐一排查
排查服务提供方是否正常注册
- 连接服务,使用telnet调试dubbo,在终端内输入 telnet localhost 20880,不过这里的ip和端口要改成自己的
> telnet 192.168.9.9 20991
Trying 192.168.9.9...
Connected to 192.168.9.9.
Escape character is '^]'.
dubbo>
- 查看服务列表 ls
dubbo>ls
com.example.service.IOrderService
com.example.service.IUserService
com.example.service.IGoodsService
- 查看服务中的接口
dubbo>ls IOrderService
queryOrder1
queryOrder2
tips:如果方法重载,比如queryOrder1重载了,那么也会显示多个queryOrder1
这里能看到queryOrder3没有在列表手上,说明queryOrder3未注册,应该检服务提供方的代码是否已经正确部署,比如代码没有合并到特性分支、构建时选错分支等
排查双方的jar包版本是否一致
可以使用 IDEA 的 maven helper 插件,用来排查jar版本