palAlaa
palAlaa

Reputation: 9858

First program with Apache Thrift - Where should I define the interface? in client or server code

I am making a php client which request a function from java service through apache thrift. I am following this tutorial for php client code. I need to understand something, the interface that's generated as file.thrift should be on client and server or only at one side?

And something else, in client code, how can I call the client object that call the server function? In the tutorial I follow this line

$client = new HbaseClient($protocol);

how he defined this class?

and in apache thrift tutorial he defeined the same in python client

# Create a client to use the protocol encoder
client = Calculator.Client(protocol)

the Calculator object is it the service provided from the server that identified in the interface? and same question the interface should be in both client and server ??

Please help, I am really stuck.

Upvotes: 3

Views: 878

Answers (1)

JensG
JensG

Reputation: 13411

I am following this tutorial

Here are the real ones: http://thrift.apache.org/tutorial/

the interface that's generated as file.thrift should be on client and server or only at one side?

The starting point is the IDL file. IDL means Interface Definition Language and it is simply a file, which describes the API contract between a server and a client. The server's task is to implement the interface described in the contract so that the client can call it.

To put the IDL file to use, you run the Thruift Compiler to generate some code for both ends. If the server and the client are using the same language (say Java) it is enough to just generate the code one time and use it in both projects:

  thrift -r -gen java MyApiContract.thrift

creates a gen-java folder with the files in it.

If it happens that the server and the client are different types of code (e.g Java and PHP), then you will need to generate code for both of them:

  thrift -r -gen java -gen php MyApiContract.thrift

which will generate two folders, gen-java and gen-php, respectively.

Since Thrift is a cross-platform, cross-language framework, having client and server written in different languages is not such a unusual case at all.

Upvotes: 2

Related Questions