简单介绍下RPC: RPC 即远程过程调用,主要是屏蔽了远程方法和本地方法的区别,像调用本地方法一样调用。隐藏了网络调用的复杂性,使我们只关注业务逻辑的实现。 RPC主要包括: 1、 网络层,主要使用tcp 2、序列化 因为网络传输需要使用二进制的数据进行传输,所以需要把对象进行序列化 3、网络协议 自定义协议 一般不使用http协议,是因为http协议内容比较大 2、 Http协议无状态 4、反序列化 5、执行
网络协议的设计: 协议头:协议版本号、数据大小,协议头大小、序列化版本 协议头扩展: 协议体:方法名、类名、key名等
序列化方式: JDK序列化: JSON序列化: 占用体积大 ,因为java没有支持的JSON类型,所以需要反射成已有的类型,所以慢 hession:压缩体积小、速度快,但是不支持LinkedHashMap/LinkedHashSet等特定类型 protoBuffer: 需要生命IDL ,使用IDL生成特定的序列化工具类。 protoStaffer: 很快,但是不支持一些类型。不支持null,不支持特定的List、Map对象。