apache / dubbo-samples

samples for Apache Dubbo
Apache License 2.0
2.24k stars 1.92k forks source link

Triple 可以与 Hessian 一起用吗 #396

Closed duansheli closed 2 years ago

duansheli commented 2 years ago

文档里只有 Triple + protobuf 的教程 image

没看到 Triple 协议 Hessian 序列化方式 的例子

duansheli commented 2 years ago

@guohao

guohao commented 2 years ago

可以的,设置对应的序列化类型即可

@guohao

duansheli commented 2 years ago

用的配置

dubbo.protocol.name=tri
dubbo.protocol.serialization=hessian2
dubbo.provider.serialization=hessian2
dubbo.provider.protocol=tri

启动 provider 失败,报错

Extension instance (name: tri, class: interface org.apache.dubbo.rpc.Protocol) couldn't be instantiated: null  

Caused by: java.lang.NoClassDefFoundError: com/google/protobuf/MessageOrBuilder
    at java.base/java.lang.ClassLoader.defineClass1(Native Method) ~[na:na]
    at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1012) ~[na:na]
    at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150) ~[na:na]
    at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862) ~[na:na]
    at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760) ~[na:na]
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681) ~[na:na]
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639) ~[na:na]
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[na:na]
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[na:na]
    at java.base/java.lang.ClassLoader.defineClass1(Native Method) ~[na:na]
    at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1012) ~[na:na]
    at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150) ~[na:na]
    at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862) ~[na:na]
    at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760) ~[na:na]
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681) ~[na:na]
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639) ~[na:na]
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[na:na]
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[na:na]
    at grpc.health.v1.HealthDubbo.init(HealthDubbo.java:12) ~[dubbo-3.0.4.jar:3.0.4]
    at grpc.health.v1.Health.<clinit>(Health.java:12) ~[dubbo-3.0.4.jar:3.0.4]
    at org.apache.dubbo.rpc.protocol.tri.service.TriBuiltinService.<init>(TriBuiltinService.java:58) ~[dubbo-3.0.4.jar:3.0.4]
    at org.apache.dubbo.rpc.protocol.tri.TripleProtocol.<init>(TripleProtocol.java:49) ~[dubbo-3.0.4.jar:3.0.4]
    ... 35 common frames omitted

protocol 设置成 dubbo 就能正常启动

AlbumenJ commented 2 years ago

@duansheli 加一下 protobuf 的依赖

        <dependency>
            <groupId>com.google.protobuf</groupId>
            <artifactId>protobuf-java</artifactId>
            <version>3.14.0</version>
        </dependency>