apache / dubbo

The java implementation of Apache Dubbo. An RPC and microservice framework.
https://dubbo.apache.org/
Apache License 2.0
40.48k stars 26.43k forks source link

@DubboService是否支持配置回调参数 #7022

Closed ZAKLLL closed 3 years ago

ZAKLLL commented 3 years ago

Environment

Steps to reproduce this issue

  1. 文档中提供的支持回调方式的服务注册需要生命某个具体参数为callback
    <bean id="callbackService" class="com.callback.impl.CallbackServiceImpl" />
    <dubbo:service interface="com.callback.CallbackService" ref="callbackService" connections="1" callbacks="1000">
    <dubbo:method name="addListener">
        <dubbo:argument index="1" callback="true" />
        <!--也可以通过指定类型的方式-->
        <!--<dubbo:argument type="com.demo.CallbackListener" callback="true" />-->
    </dubbo:method>
    </dubbo:service>

    当我使用@DubboService,无法找到对应的方法,参数配置,是否有注解支持声明回调 直接调用会抛出回调参数需要被序列化的异常

    Caused by: java.lang.IllegalStateException: Serialized class com.xxx.system.rest.TestController$1 must implement java.io.Serializable
    at com.alibaba.com.caucho.hessian.io.SerializerFactory.getDefaultSerializer(SerializerFactory.java:417)
    at com.alibaba.com.caucho.hessian.io.SerializerFactory.getSerializer(SerializerFactory.java:391)
    at com.alibaba.com.caucho.hessian.io.Hessian2Output.writeObject(Hessian2Output.java:411)
    at org.apache.dubbo.common.serialize.hessian2.Hessian2ObjectOutput.writeObject(Hessian2ObjectOutput.java:98)
    at org.apache.dubbo.rpc.protocol.dubbo.DubboCodec.encodeRequestData(DubboCodec.java:185)
    at org.apache.dubbo.remoting.exchange.codec.ExchangeCodec.encodeRequest(ExchangeCodec.java:238)
    at org.apache.dubbo.remoting.exchange.codec.ExchangeCodec.encode(ExchangeCodec.java:69)
    at org.apache.dubbo.rpc.protocol.dubbo.DubboCountCodec.encode(DubboCountCodec.java:40)
    at org.apache.dubbo.remoting.transport.netty4.NettyCodecAdapter$InternalEncoder.encode(NettyCodecAdapter.java:69)
    at io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:107)
    ... 25 more
kimmking commented 3 years ago

callback类需要实现 java.io.Serializable

ZAKLLL commented 3 years ago

callback类需要实现 java.io.Serializable

对callbackListener 实现java.io.Serializable 如下


    @GetMapping("/callback1/{id}")
    public void callback1(@PathVariable String id) {
        callbackService.addListener(id, new MyCallbackListener());
    }

    static class MyCallbackListener implements CallbackListener, Serializable {
        @Override
        public void changed(String msg) {
            System.out.println(msg);
        }
    }

重新进行调用时抛出异常如下

2020-12-16 09:48:12.829  WARN 20980 --- [:18888-thread-6] o.a.d.r.p.dubbo.DecodeableRpcInvocation  :  [DUBBO] Decode argument failed: ObjectDeserializer[interface com.xxx.callback.CallbackListener], dubbo version: 2.7.8, current host: 172.23.16.1

java.lang.UnsupportedOperationException: ObjectDeserializer[interface com.xxx.callback.CallbackListener]
    at com.alibaba.com.caucho.hessian.io.ObjectDeserializer.readObject(ObjectDeserializer.java:77) ~[dubbo-2.7.8.jar:2.7.8]
    at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObjectInstance(Hessian2Input.java:2848) ~[dubbo-2.7.8.jar:2.7.8]
    at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2175) ~[dubbo-2.7.8.jar:2.7.8]
    at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2104) ~[dubbo-2.7.8.jar:2.7.8]
    at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2148) ~[dubbo-2.7.8.jar:2.7.8]
    at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2104) ~[dubbo-2.7.8.jar:2.7.8]
    at org.apache.dubbo.common.serialize.hessian2.Hessian2ObjectInput.readObject(Hessian2ObjectInput.java:101) ~[dubbo-2.7.8.jar:2.7.8]
    at org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation.decode(DecodeableRpcInvocation.java:143) [dubbo-2.7.8.jar:2.7.8]
    at org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation.decode(DecodeableRpcInvocation.java:80) [dubbo-2.7.8.jar:2.7.8]
    at org.apache.dubbo.remoting.transport.DecodeHandler.decode(DecodeHandler.java:57) [dubbo-2.7.8.jar:2.7.8]
    at org.apache.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:44) [dubbo-2.7.8.jar:2.7.8]
    at org.apache.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:57) [dubbo-2.7.8.jar:2.7.8]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_131]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_131]
    at java.lang.Thread.run(Thread.java:748) [na:1.8.0_131]

服务端抛出回调参数为Null的NPE

CrazyHZM commented 3 years ago

Try it with the latest version, if you still have problems, you can reopen the issues