Unverified Commit 66f17bca authored by Ge Jun's avatar Ge Jun Committed by GitHub

Update thrift.md

parent 7bd28453
......@@ -10,12 +10,12 @@ Advantages compared to the official solution:
- Support various connection types(short, connection pool). Support timeout, backup request, cancellation, tracing, built-in services, and other benefits offered by brpc.
# Compile
To reuse the parsing code, brpc depends on the thrift lib and the code generated by thrift tools to support thrift. Please read official documents to find out methods to write thrift files, generate code, compilations etc.
brpc depends on the thrift lib and the code generated by thrift tools to reuse the parsing code. Please read official documents to find out how to write thrift files, generate code, compilations etc.
brpc does not enable thrift support or depend on the thrift lib by default. If the thrift support is needed, config brpc with extra --with-thrift.
Install thrift under Ubuntu
Read [Official wiki](https://thrift.apache.org/docs/install/debian) to install depended libs and tools, then download the thrift source code from [official site](https://thrift.apache.org/download), uncompress and compile。
Read [Official wiki](https://thrift.apache.org/docs/install/debian) to install depended libs and tools, then download thrift source code from [official site](https://thrift.apache.org/download), uncompress and compile。
```bash
wget http://www.us.apache.org/dist/thrift/0.11.0/thrift-0.11.0.tar.gz
tar -xf thrift-0.11.0.tar.gz
......@@ -32,14 +32,14 @@ sh config_brpc.sh --headers=/usr/include --libs=/usr/lib --with-thrift
# Client accesses thrift server
Steps:
- Create a Channel with protocol set to brpc::PROTOCOL_THRIFT
- Define and use brpc::ThriftMessage<Native-Request> as the request, brpc::ThriftMessage<Native-Response> as the response. raw() method returns the native thrift message.
- Create a Channel setting protocol to brpc::PROTOCOL_THRIFT
- Define and use brpc::ThriftMessage<Native-Request> as the request, brpc::ThriftMessage<Native-Response> as the response. Call raw() method to get the native thrift message.
- Set method-name for thrift via Controller::set_thrift_method_name()
Example code:
```c++
#include <brpc/channel.h>
#include <brpc/thrift_message.h>         // 定义了ThriftMessage
#include <brpc/thrift_message.h>         // Defines ThriftMessage
...
DEFINE_string(server, "0.0.0.0:8019", "IP Address of thrift server");
......@@ -56,8 +56,7 @@ if (thrift_channel.Init(Flags_server.c_str(), FLAGS_load_balancer.c_str(), &opti
...
// wrapper thrift raw request into ThriftMessage
// example::[EchoRequest/EchoResponse]是thrfit原生定义的消息(通过thrift代码生成工具生成)
// example::[EchoRequest/EchoResponse] are generated by thrift
brpc::ThriftMessage<example::EchoRequest> req;
brpc::ThriftMessage<example::EchoResponse> res;
......@@ -73,7 +72,7 @@ if (cntl.Failed()) {
```
# Server processes thrift requests
Inherit brpc::ThriftService to implement the processing code, which may call the native handler generated by thrift to re-use older entry directly, or read the request and set the response directly just as in other protobuf services.
Inherit brpc::ThriftService to implement the processing code, which may call the native handler generated by thrift to re-use existing entry directly, or read the request and set the response directly just as in other protobuf services.
```c++
class MyThriftProtocol : public brpc::ThriftService {
public:
......@@ -108,7 +107,7 @@ private:
};
```
After implementing the thrift service, set to ServerOptions.thrift_service and start the service.
Set the implemented service to ServerOptions.thrift_service and start the service.
```c++
brpc::Server server;
brpc::ServerOptions options;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment