thrift实践

thrift exercises

  1. how to define a DTO?


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

  1. how to define enum?

    // 定义枚举
    enum STUDENT_SEXY {
    MAN = 1,
    FEMALE = 2
    }

  2. how to refer an class?


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

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

  1. how to use container?

    struct StudentDTO {
    1:i64 id,
    2:string name,
    3:STUDENT_SEXY sexy,
    4:list courses //使用容器
    }
  2. how to name a package (namespace)?
    namespace java com.xxxx.crm.demo.dto
  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 : 1:i64 id中1的值

reference

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

你可能感兴趣的:(thrift实践)