dubbo 传递数据序列化配置

1 实体类对象必须序列化

import java.io.Serializable

data class XXXXBean(
    // ****
    // 字段
) : Serializable

2 创建SerializationOptimizerImpl

import org.apache.dubbo.common.serialize.support.SerializationOptimizer

class SerializationOptimizerImpl : SerializationOptimizer {
    override fun getSerializableClasses(): Collection> {
        val classes: MutableList> = LinkedList()
        classes.add(XXXBean::class.java)
        return classes
    }
}

3  服务端和消费端都要添加依赖

    api("de.javakaffee:kryo-serializers:0.45")
    api("com.esotericsoftware:kryo:4.0.2")

    implementation ("org.apache.dubbo:dubbo:2.7.5")

 4 服务端yml文件添加配置

dubbo:
  application:
    name: xxx
  protocol:
    name: dubbo
    port: -1
    //下面这俩是配置传递对象的
    serialization: kryo
    optimizer: org.kuaifang.manager.iot.SerializationOptimizerImpl
  registry:
    id: xxxxxx
    address: zookeeper://127.0.0.1:2181

5 消费端yml只需要添加
 

serialization: kryo

 

 

好了

dubbo 传递对象序列化配置就完事了。

你可能感兴趣的:(dubbo+zk,服务崛起之路,java,后端,spring,boot,spring)