thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jens Geyer" <jensge...@hotmail.com>
Subject Re: Thrift optional type for rpc response
Date Wed, 20 Nov 2013 15:57:58 GMT
Hi Aditya Sarawgi,

I think  most of the confusion originates from making a mental difference 
between call arguments and response data. Think of the service function call 
as something like

    response = service.function( arg1, arg2, arg3)

The args could be a struct as well, like

  request = struct {
    1: i32 arg1
    2: string arg2
    3: bool arg3
  }

thus we could write

    response = service.function( request)

Now let's assume for a moment, that we could do the following with Thrift 
(which we actually can't):

    void service.function( in request, out response)

In fact, behind the scenes, exactly that happens. Both request and response 
are transported in a struct, and responses additionally do carry any 
exception info that might need to be returned from the client to be raised 
there.

You see, there is no conceptual difference between a request and response 
data. The only difference is, that Thrift IDL syntax does not allow multiple 
fields to be returned, so you have to wrap them into a struct. But that is a 
purely syntactical limitation.


> 1) Should optional be ever used in a response

Yes, of yourse. It absolutely makes sense to be able to return only some 
data, for various reasons. I can give you plenty of examples.

> 2) If doesn't return the msgs until I do a
> _return.__set_msgs(vector_of_msgs) which looks hacky to me.

Maybe I overlook something, but of course you have to assign the return 
value somehow. What language is that?

> Any guidance on this is much appreciated, the documentation is really 
> sparse.

Maybe you want to look at the tutorials, which do a pretty good job 
explaining the fundamentals. I'm not sure what extra documentation you are 
looking for with regard to the above?

Have fun,
JensG


-----Urspr√ľngliche Nachricht----- 
From: Aditya Sarawgi
Sent: Wednesday, November 20, 2013 9:53 AM
To: user@thrift.apache.org
Subject: Thrift optional type for rpc response

Hi Everyone,

I have some questions about the way I am using thrift optional types or
rather I am not sure if this is the right way to use it. The thrift file
looks something like this

namespace something

struct Response {
1: Status status,
2: optional list<string> msgs

}

service Something {
  Respone getMessages(1: i16 id)
}

Now first of all I am confused by the following

1) Should optional be ever used in a response
2) If doesn't return the msgs until I do a
_return.__set_msgs(vector_of_msgs) which looks hacky to me.

Any guidance on this is much appreciated, the documentation is really
sparse.

Thanks
Aditya Sarawgi 


Mime
View raw message