美文网首页
thrift实践

thrift实践

作者: L寻欢 | 来源:发表于2017-07-03 17:07 被阅读88次

thrift exercises

  1. how to define a DTO?

<code>
struct CourseDTO {
1:i64 id,
2:string title,
3:string teacherName,
4:i64 beginTime
}
</code>

  1. how to define enum?
    <code>
    // 定义枚举
    enum STUDENT_SEXY {
    MAN = 1,
    FEMALE = 2
    }
    </code>

  2. how to refer an class?

<code>
include "../dto/StudentDTO.thrift"
service CourseRemoteService {
list<StudentDTO.CourseDTO> queryAllCourse();
}
</code>

引用其他文件定义的thrift struct,可以使用include的关键字,然后 通过include的文件名和struct名来引用

  1. how to use container?
    <code>
    struct StudentDTO {
    1:i64 id,
    2:string name,
    3:STUDENT_SEXY sexy,
    4:list<CourseDTO> courses //使用容器
    }
    </code>
  2. how to name a package (namespace)?
    <code>namespace java com.xxxx.crm.demo.dto</code>
  3. how to control the version ?
  • Don’t change the numeric tags for any existing fields.
  • Any new fields that you add should be optional. This means that any messages serialized by code using your "old" message format can be parsed by your new generated code, as they won’t be missing any required elements. You should set up sensible default values for these elements so that new code can properly interact with messages generated by old code. Similarly, messages created by your new code can be parsed by your old code: old binaries simply ignore the new field when parsing. However, the unknown fields are not discarded, and if the message is later serialized, the unknown fields are serialized along with it — so if the message is passed on to new code, the new fields are still available.
  • Non-required fields can be removed, as long as the tag number is not used again in your updated message type (it may be better to rename the field instead, perhaps adding the prefix "OBSOLETE_", so that future users of your .thrift can’t accidentally reuse the number).
  • Changing a default value is generally OK, as long as you remember that default values are never sent over the wire. Thus, if a program receives a message in which a particular field isn’t set, the program will see the default value as it was defined in that program’s version of the protocol. It will NOT see the default value that was defined in the sender’s code.
numeric tags : <code>1:i64 id</code>中1的值

reference

  1. thrift-missing-guide
  2. Thrift: Scalable Cross-Language Services Implementation

相关文章

  • thrift实践

    thrift exercises how to define a DTO? struct CourseDTO {1...

  • Thrift更新最佳实践

    之前仅仅知道用thrift,下午没事讨论到了thrift在更新idl的时候注意事项,补一补知识。 转载:https...

  • Thirft

    一、About thrift二、什么是thrift,怎么工作?三、Thrift IDL四、Thrift D...

  • Docker&k8s微服务学习实践(二)

    一、下载配置thrift 从Thrift官网 http://thrift.apache.org/ 下载thrift...

  • thrift 指南

    /usr/local/opt/thrift@0.9/bin/thrift -gen java a.thrift会在...

  • Thrift学习

    Thrift源码剖析 Thrift源码分析及一个完整的例子 CSDN Thrift源码分析 Thrift二进制序列...

  • thrift 简介

    thrift 基本概念、数据类型thrift 简介一 thrift 基本类概述、序列化协议thrift 简介二 t...

  • Thrift 异步Service的原理

    Thrift 异步Service的原理 定义一个Thrift Service Thrift Service方法会提...

  • C# 通过Thrift访问Hbase

    1、确保Hbase中已经开启Thrift服务2、Thrift官网( http://thrift.apache.or...

  • 聊一聊序列化-Thrift

    认识Thrift Thrift is an interface definition language and b...

网友评论

      本文标题:thrift实践

      本文链接:https://www.haomeiwen.com/subject/vmkzcxtx.html