polaris-java-agent icon indicating copy to clipboard operation
polaris-java-agent copied to clipboard

dubbo2 问题记录

Open zifeiyu0531 opened this issue 2 years ago • 0 comments

1. jsonrpc4j

问题记录

dubbo插件的PolarisRegistry.java构造器执行:

for (String supportedExtension : supportedExtensions) {
    protocols.put(supportedExtension, extensionLoader.getExtension(supportedExtension));
}

当遍历到http时,创建HttpProtocol报错:

Exception in thread "main" java.lang.IllegalStateException: Extension instance (name: http, class: interface org.apache.dubbo.rpc.Protocol) couldn't be instantiated: null
	at org.apache.dubbo.common.extension.ExtensionLoader.createExtension(ExtensionLoader.java:691)
	at org.apache.dubbo.common.extension.ExtensionLoader.getExtension(ExtensionLoader.java:445)
	at org.apache.dubbo.common.extension.ExtensionLoader.getExtension(ExtensionLoader.java:429)
	at cn.polarismesh.agent.plugin.dubbo2.polaris.PolarisRegistry.<init>(PolarisRegistry.java:49)
	at cn.polarismesh.agent.plugin.dubbo2.polaris.PolarisRegistryFactory.getRegistry(PolarisRegistryFactory.java:22)
......
Caused by: java.lang.NoClassDefFoundError: com/googlecode/jsonrpc4j/HttpException
	at org.apache.dubbo.rpc.protocol.http.HttpProtocol.<init>(HttpProtocol.java:60)
	... 38 more
Caused by: java.lang.ClassNotFoundException: com.googlecode.jsonrpc4j.HttpException
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
	... 39 more

解决方案

在dubbo项目中,手动添加jsonrpc4j依赖

<dependency>
    <groupId>com.github.briandilley.jsonrpc4j</groupId>
    <artifactId>jsonrpc4j</artifactId>
    <version>1.2.0</version>
</dependency>

问题归因

怀疑jsonrpc4j包冲突

2. doList

问题记录

dubbo consumer端启动后,当PolarisDirectorylist(Invocation invocation)方法执行:

List<Invoker<T>> originalInvokers = this.originalRegistryDirectory.doList(invocation);

报错

[07/03/22 16:13:45:740 CST] 线程 - 1  INFO polaris.PolarisDirectory: [POLARIS] getAvailableInstances count:2, service org.apache.dubbo.demo.DemoService, labels {application=demo-consumer, method=sayHello, release=2.7.15, qos.port=33333, pid=79608, id=org.apache.dubbo.config.RegistryConfig, qos.enable=true, qos.accept.foreign.ip=false, dubbo.tag=tag1}
[07/03/22 16:13:45:740 CST] 线程 - 1 ERROR polaris.PolarisDirectory: [POLARIS] can not find invoker in InvokerMap, address is: 192.168.180.1:xxxxx

解决方案

移除provider端的tag属性

<dubbo:service tag="tag2" serialization="protobuf" interface="org.apache.dubbo.demo.DemoService" ref="demoServiceImpl"/>
<dubbo:service serialization="protobuf" interface="org.apache.dubbo.demo.DemoService" ref="demoServiceImpl"/>

问题归因

this.originalRegistryDirectory.doList(invocation)执行时要走dubbo的路由,当执行到tag路由时会因为路由不匹配导致找不到对应的invoker,疑似无法兼容dubbo原本的tag路由,因此需要用户抛弃dubbo原本的路由,使用polaris提供的路由功能

注:
在使用polaris路由时,provider端定义`parameter`的`key`值不能为`tag`,否则会自动当成`dubbo.tag`,一样报错
如:
<dubbo:service serialization="protobuf" interface="org.apache.dubbo.demo.DemoService" ref="demoServiceImpl">
    <dubbo:parameter key="tag" value="xxx"/><!--出错-->
    <!--这里的key不能为`tag`-->
</dubbo:service>

zifeiyu0531 avatar Mar 07 '22 06:03 zifeiyu0531