1. 通过proto文件生成java文件夹
vi test1.proto
syntax = “proto2”;
package example;
message Hello{
required string name = 1;
required int32 id = 2;
}
生成Test1.java
protoc –java_out=pbdir test1.proto
2. 将Test1.java拷贝到src/main/java/example目录下
3. 通过spark streaming读取kafka上的pb数据
import Test1._
createKafkaStream(ssc, pb_topic, kafkaParams1).map(r => r._2).map(r => {val p = Hello.parseFrom(r.getBytes); p.getId + “\\t” + p.getName})