协议定义:
// 发送客流统计邮件
message SendPassengerEmailReq{
string title=1; //主题
string content=2; //内容
string sendto=3; //接收方,多个用;分割
repeated bytes attach=4; //可以有多个附件,附件就是CSV文件,以字节流方式传输
}
message SendPassengerEmailRsp{
ResponseInfo response_info = 1;
}
rpc SendPassengerEmail(SendPassengerEmailReq) returns (SendPassengerEmailRsp);
JAVA程序:
byte[] csv = writeCSV(sortMap,fileName);//将文件转成字节数组
//通知es发送邮件
SendPassengerEmailReq.Builder builder = SendPassengerEmailReq.newBuilder();
builder.setTitle(eSchedule.getTitle());
builder.setSendto(eSchedule.getSendTo());
ByteString bs = null;
if (null != csv) {
bs = ByteString.copyFrom(csv);//从字节数组中获取ByteString对象
}
builder.addAttach(bs);//添加到附件协议中去