brpc有很多的內(nèi)建服務(wù)缸血,便于生產(chǎn)環(huán)境使用,本次分析內(nèi)建服務(wù)基本統(tǒng)一部分械筛,各服務(wù)不同數(shù)據(jù)統(tǒng)計(jì)等實(shí)現(xiàn)這里暫時(shí)不討論捎泻,后續(xù)會(huì)分析幾個(gè)具體內(nèi)部實(shí)現(xiàn)。
如果你想看看內(nèi)建服務(wù)只需啟動(dòng)一個(gè)demo服務(wù)埋哟,執(zhí)行簡單的命令:
curl localhost:8003
[host build]$ curl localhost:8003
__
/ /_ _________ _____
/ __ \/ ___/ __ \/ ___/
/ /_/ / / / /_/ / /__
/_.___/_/ / .___/\___/
/_/
github : https://github.com/brpc/brpc
/status : Status of services
/connections : List all connections
/flags : List all gflags
/flags/port : List the gflag
/flags/guard_page_size;help* : List multiple gflags with glob patterns (Use $ instead of ? to match single character)
/flags/NAME?setvalue=VALUE : Change a gflag, validator will be called. User is responsible for thread-safety and consistency issues.
/vars : List all exposed bvars
/vars/rpc_num_sockets : List the bvar
/vars/rpc_server*_count;iobuf_blo$k_* : List multiple bvars with glob patterns (Use $ instead of ? to match single character)
/rpcz : Recent RPC calls(disabled)
/rpcz/stats : Statistics of rpcz
/rpcz?time=2021/01/22-19:50:38 : RPC calls before the time
/rpcz?time=2021/01/22-19:50:38&max_scan=10 : N RPC calls at most before the time
Other filters: min_latency, min_request_size, min_response_size, log_id, error_code
/rpcz?trace=N : Recent RPC calls whose trace_id is N
/rpcz?trace=N&span=M : Recent RPC calls whose trace_id is N and span_id is M
/hotspots/cpu : Profiling CPU (disabled)
/hotspots/heap : Profiling heap (disabled)
/hotspots/growth : Profiling growth of heap (disabled)
curl -H 'Content-Type: application/json' -d 'JSON' 172.17.226.15:8003/ServiceName/MethodName : Call method by http+json
/version : Version of this server, set by Server::set_version()
/health : Test healthy
/vlog : List all VLOG callsites
/sockets : Check status of a Socket
/bthreads : Check status of a bthread
/ids : Check status of a bthread_id
/protobufs : List all protobuf services and messages
/list : json signature of methods
/threads : Check pstack (disabled)
/dir : Browse directories and files (disabled)
[lfz@iz2zec6g7egdxs0gpgesoiz build]$ curl localhost:8003/hotspots/cpu
Error: cpu profiler is not enabled.
Read the docs: docs/cn/{cpu_profiler.md,heap_profiler.md}
brpc內(nèi)建的服務(wù)統(tǒng)一使用了rpc請(qǐng)求框架完成服務(wù)的搭建工作笆豁。
基本統(tǒng)一的default_method來請(qǐng)求需要的功能郎汪。
如果你大概了解brpc使用方式,看一下下文內(nèi)容就明白了闯狱。
以下是實(shí)現(xiàn)的proto文件一部分煞赢。
package brpc;
...
message IndexRequest {}
message IndexResponse {}
message FlagsRequest {}
message FlagsResponse {}
message VersionRequest {}
message VersionResponse {}
message HealthRequest {}
message HealthResponse {}
message StatusRequest {}
message StatusResponse {}
message ProtobufsRequest {}
message ProtobufsResponse {}
message ConnectionsRequest {}
message ConnectionsResponse {}
message ListRequest {}
message ListResponse {
repeated google.protobuf.ServiceDescriptorProto service = 1;
}
message VarsRequest {}
message VarsResponse {}
message BthreadsRequest {}
message BthreadsResponse {}
message IdsRequest {}
message IdsResponse{}
message SocketsRequest {}
message SocketsResponse {}
message RpczRequest {}
message RpczResponse {}
message ThreadsRequest {}
message ThreadsResponse {}
message DirRequest {}
message DirResponse {}
message VLogRequest {}
message VLogResponse {}
message MetricsRequest {}
message MetricsResponse {}
message BadMethodRequest {
required string service_name = 1;
}
message BadMethodResponse {}
service index {
rpc default_method(IndexRequest) returns (IndexResponse);
}
service version {
rpc default_method(VersionRequest) returns (VersionResponse);
}
service health {
rpc default_method(HealthRequest) returns (HealthResponse);
}
service status {
rpc default_method(StatusRequest) returns (StatusResponse);
}
service protobufs {
rpc default_method(ProtobufsRequest) returns (ProtobufsResponse);
}
service connections {
rpc default_method(ConnectionsRequest) returns (ConnectionsResponse);
}
service list {
rpc default_method(ListRequest) returns (ListResponse);
}
service threads {
rpc default_method(ThreadsRequest) returns (ThreadsResponse);
}
service vlog {
rpc default_method(VLogRequest) returns (VLogResponse);
}
service bthreads {
rpc default_method(BthreadsRequest) returns (BthreadsResponse);
}
service ids {
rpc default_method(IdsRequest) returns (IdsResponse);
}
service sockets {
rpc default_method(SocketsRequest) returns (SocketsResponse);
}
service brpc_metrics {
rpc default_method(MetricsRequest) returns (MetricsResponse);
}
service badmethod {
rpc no_method(BadMethodRequest) returns (BadMethodResponse);
}
...