开发者社区 > 云原生 > 正文

dubbo3.0.5如何使用stubevent?

我在@DubboReference注解中看到有一项stubevent配置, 并尝试设置为true, @DubboReference(onconnect = "onConnect", stubevent = true, stub = "DemoServiceLocal") 我的本地存根类如下:

package org.apache.dubbo.demo.consumer;

import org.apache.dubbo.demo.DemoService;

public class DemoServiceLocal implements DemoService {

private DemoService demoService;
public DemoServiceLocal(DemoService demoService){
    this.demoService = demoService;
}
@Override
public String sayHello(String name) {
    return demoService.sayHello(name);
}

public void onConnect(){
    System.out.println("DemoServiceLocal.onConnect()");
}

}

按照Provider端的onconnect, ondisconnect事件通知理解, 在Consumer端的存根也支持onconnect, ondisconnect事件 但是Consumer端抛出如下异常:

13:00:59.150 [main] ERROR org.apache.dubbo.rpc.proxy.wrapper.StubProxyFactoryWrapper - [DUBBO] export a stub service error., dubbo version: 3.0.5, current host: 192.168.40.120 java.lang.NullPointerException: null at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:936) at org.apache.dubbo.rpc.support.GroupServiceKeyCache.getServiceKey(GroupServiceKeyCache.java:37) at org.apache.dubbo.rpc.support.ProtocolUtils.serviceKey(ProtocolUtils.java:51) at org.apache.dubbo.rpc.protocol.AbstractProtocol.serviceKey(AbstractProtocol.java:75) at org.apache.dubbo.rpc.protocol.AbstractProtocol.serviceKey(AbstractProtocol.java:71) at org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol.export(DubboProtocol.java:296) at org.apache.dubbo.rpc.protocol.ProtocolListenerWrapper.export(ProtocolListenerWrapper.java:66) at org.apache.dubbo.qos.protocol.QosProtocolWrapper.export(QosProtocolWrapper.java:76) at org.apache.dubbo.rpc.cluster.filter.ProtocolFilterWrapper.export(ProtocolFilterWrapper.java:61) at org.apache.dubbo.rpc.protocol.ProtocolSerializationWrapper.export(ProtocolSerializationWrapper.java:47) at org.apache.dubbo.rpc.Protocol$Adaptive.export(Protocol$Adaptive.java) at org.apache.dubbo.rpc.proxy.wrapper.StubProxyFactoryWrapper.export(StubProxyFactoryWrapper.java:123) at org.apache.dubbo.rpc.proxy.wrapper.StubProxyFactoryWrapper.getProxy(StubProxyFactoryWrapper.java:93) at org.apache.dubbo.rpc.ProxyFactory$Adaptive.getProxy(ProxyFactory$Adaptive.java) at org.apache.dubbo.config.ReferenceConfig.createProxy(ReferenceConfig.java:400) at org.apache.dubbo.config.ReferenceConfig.init(ReferenceConfig.java:275) at org.apache.dubbo.config.ReferenceConfig.get(ReferenceConfig.java:216) at org.apache.dubbo.config.utils.SimpleReferenceCache.get(SimpleReferenceCache.java:110) at org.apache.dubbo.config.deploy.DefaultModuleDeployer.lambda$referServices$6(DefaultModuleDeployer.java:384) at java.util.concurrent.ConcurrentHashMap$ValuesView.forEach(ConcurrentHashMap.java:4707) at org.apache.dubbo.config.deploy.DefaultModuleDeployer.referServices(DefaultModuleDeployer.java:364) at org.apache.dubbo.config.deploy.DefaultModuleDeployer.start(DefaultModuleDeployer.java:151) at org.apache.dubbo.config.deploy.DefaultApplicationDeployer.startModules(DefaultApplicationDeployer.java:617) at org.apache.dubbo.config.deploy.DefaultApplicationDeployer.doStart(DefaultApplicationDeployer.java:581) at org.apache.dubbo.config.deploy.DefaultApplicationDeployer.start(DefaultApplicationDeployer.java:554) at org.apache.dubbo.config.bootstrap.DubboBootstrap.start(DubboBootstrap.java:222) at org.apache.dubbo.config.bootstrap.DubboBootstrap.start(DubboBootstrap.java:212)

原提问者GitHub用户xxxcrel

展开
收起
大圣东游 2023-05-11 19:10:57 140 0
1 条回答
写回答
取消 提交回答
  • DubboReference里的stub值要类的权限定名 class.getName()

    原回答者GitHub用户BurningCN

    2023-05-12 11:04:04
    赞同 展开评论 打赏
问答分类:
问答地址:

阿里云拥有国内全面的云原生产品技术以及大规模的云原生应用实践,通过全面容器化、核心技术互联网化、应用 Serverless 化三大范式,助力制造业企业高效上云,实现系统稳定、应用敏捷智能。拥抱云原生,让创新无处不在。

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载