Search code examples
microservicesthrift

How to include a thrift file from a different micro service


I am new to micro service and thrift world, I wonder how to include a thrift file from a different micro service. ex: In my user micro service, I have

namespace go user


struct User {
    1: required string id;
    2: required string email;
    3: required string password;
    4: optional list<Order> roles;
}

and in my order micro service, I have

namespace go order


struct Order {
    1: required string id;
    2: required string orderNumber;
}

if I also want my User struct to have a list of Order, how do I include it from my order micro service?

Thanks


Solution

  • You need to include the file, the reference the type with the included prefix, like so:

    namespace go user
    
    include "order.thrift"
    
    struct User {
        1: required string id;
        2: required string email;
        3: required string password;
        4: optional list<order.Order> roles;
    }
    

    Recommended read: https://thrift.apache.org/docs/idl.html, escpecially this example