@@ -9,11 +9,12 @@ A industrial-grade RPC framework used throughout [Baidu](http://ir.baidu.com/pho
You can use it to:
* Build a server that can talk in multiple protocols (**on same port**), or access all sorts of services
* restful http/https, h2/h2c (compatible with [grpc](https://github.com/grpc/grpc), will be opensourced). using http in brpc is much more friendly than [libcurl](https://curl.haxx.se/libcurl/).
*[redis](docs/en/redis_client.md) and [memcached](docs/en/memcache_client.md), thread-safe, more friendly and performant than the official clients
*[redis](docs/en/redis_client.md) and [memcached](docs/en/memcache_client.md), thread-safe, more friendly and performant than the official clients.
*[rtmp](https://github.com/brpc/brpc/blob/master/src/brpc/rtmp.h)/[flv](https://en.wikipedia.org/wiki/Flash_Video)/[hls](https://en.wikipedia.org/wiki/HTTP_Live_Streaming), for building [live-streaming services](docs/cn/live_streaming.md).
* hadoop_rpc (may be opensourced)
*[rdma](https://en.wikipedia.org/wiki/Remote_direct_memory_access) support (will be opensourced)
* all sorts of protocols used in Baidu: [baidu_std](docs/cn/baidu_std.md), [streaming_rpc](docs/en/streaming_rpc.md), hulu_pbrpc, [sofa_pbrpc](https://github.com/baidu/sofa-pbrpc), nova_pbrpc, public_pbrpc, ubrpc, [thrift](docs/en/thrift.md) and nshead-based ones.
*[thrift](docs/en/thrift.md) support, thread-safe, more friendly and performant than the official clients.
* all sorts of protocols used in Baidu: [baidu_std](docs/cn/baidu_std.md), [streaming_rpc](docs/en/streaming_rpc.md), hulu_pbrpc, [sofa_pbrpc](https://github.com/baidu/sofa-pbrpc), nova_pbrpc, public_pbrpc, ubrpc and nshead-based ones.
* Access protobuf-based protocols with HTTP+json, probably from another language.
* Build [HA](https://en.wikipedia.org/wiki/High_availability) distributed services using an industrial-grade implementation of [RAFT consensus algorithm](https://raft.github.io) which is opensourced at [braft](https://github.com/brpc/braft)
* Servers can handle requests [synchronously](docs/en/server.md) or [asynchronously](docs/en/server.md#asynchronous-service).
[thrift](https://thrift.apache.org/)is a RPC framework used widely in production area which was developed by Facebook, In order to access thrift servers more conveniently and make full use of bthread's capability of concurrency, brpc directly supports the thrift protocol.
[thrift](https://thrift.apache.org/)is a RPC framework used widely in production environment which was developed by Facebook. In order to access thrift servers more conveniently and make full use of concurrency ability of bthread, brpc directly supports the thrift protocol.
Check [example/thrift_extension_c++](https://github.com/brpc/brpc/tree/master/example/thrift_extension_c++/) for an example.
Advantages compared to the official thrift client:
- Thread safety. No need to set up separate clients for each thread.
- Support synchronous, asynchronous, semi-synchronous accesses etc. Support [ParallelChannel etc](combo_channel.md) to define access patterns declaratively.
- Supports synchronous, asynchronous, batch synchronous, batch asynchronous, and other access methods. Combination channels such as ParallelChannel are also supported.
- Support various connection types(short, connection pool). Support timeout, backup request, cancellation, tracing, built-in services, and other benefits offered by brpc.
# Compile and Run
In order to not depend on and compile with thrift library for most of the users, the thrift protocol wasn't supported in brpc by default. configure brpc with --with-thrift if you want to enable thrift protocol in brpc(actually it works with a Macro ENABLE_THRIFT_FRAMED_PROTOCOL)
In order to not depend on and compile with thrift library for most users, the thrift protocol wasn't supported in brpc by default. Configure brpc with --with-thrift if you want to enable thrift protocol in brpc.
Install Thrift in Ubuntu
```bash
Download thrift source code from offical [web site](https://thrift.apache.org/download)
sh config_brpc.sh --headers=/usr/include --libs=/usr/lib --nodebugsymbols--with-thrift
```
Link with libbrpc_thrift.a if the user want to enable thrift protocol
Thrift extension was supported via static library, libbrpc.a was generated after compile, link with it if users want to enable thrift protocol.
# Thrift message definition, echo.thrift:
```c++
...
...
@@ -68,7 +71,7 @@ if (thrift_channel.Init(Flags_server.c_str(), FLAGS_load_balancer.c_str(), &opti
}
...
```
construct thrift request and send to server, ThriftMessage is a template class, the native thrift message was delegated by and can be accessed directly by raw() method.
Construct a thrift request and send it to server, ThriftMessage is a template class that hosts thrift navtive messages, raw() methods can directly manipulate native thrift messages.
```c++
// wrapper thrift raw request into ThriftMessage
...
...
@@ -88,9 +91,9 @@ construct thrift request and send to server, ThriftMessage is a template class,
}
```
# Server process with thrift message
User need to implement it's own thrift handler which was inherited from brpc::ThriftService
Only the method name can obtained in server side due to the limit of thrift protocol itself, the service name wasn't passed to server actually, it means that only one thrift service can be set in one brpc server
# Server side processing upstream thrift requests
Users need to implement their own thrift handler which was inherited from brpc::ThriftService.
Due to the limitation of thrift protocol itself, only the method name can be obtained on the server (via the controller.thrift_method_name() method), and the service name cannot be obtained. This is consistent with the native thrift implementation, which means that there can only be one thrift service in one brpc server.