用php做网站后台,中国纪检监察报,asp网站开发的开发环境,外贸型网站建设方法一.BRPC介绍 
BRPC百度开源的一个rpc框架#xff0c;它具有以下特性#xff1a; 
基于protobuf接口的RPC框架#xff0c;也提供json等其他数据格式的支持囊括baidu内部所有RPC协议#xff0c;支持多种第三方协议模块化设计#xff0c;层次清晰#xff0c;很容易添加自定义…一.BRPC介绍 
BRPC百度开源的一个rpc框架它具有以下特性 
基于protobuf接口的RPC框架也提供json等其他数据格式的支持囊括baidu内部所有RPC协议支持多种第三方协议模块化设计层次清晰很容易添加自定义协议全面的服务发现、负载均衡、组合访问支持可视化的内置服务和调试工具性能上领跑目前其他所有RPC产品 
支持的协议 baidu_std默认 hulu-pbrpc协议 nova-pbrpc协议 public/pbrpc协议 sofa-pbrpc协议 UB协议 ubrpc协议 HTTP协议 HTTPS协议 凤巢ITP协议 memcache协议 redis协议 mongo协议 hadoop rpc协议 
任何使用brpc::Server的进程都能用HTTP方式直接访问server本身的端口返回内容为各种内置服务。 通过浏览器直接访问图形界面更加直观否则用curl方式访问文本格式。 
brpc支持一个端口监听多种协议如可以同时监听baidu_std和http协议发来的请求。 
详细文档参见 https://github.com/brpc/brpc 二.Linux下安装brpc 
1. 编译环境安装gcc-4.8.2 1先安装gcc-c.x86_64 
yum install gcc-c.x86_642编译安装gcc-4.8.2 下载gcc-4.8.2-with-all-requires.tar 指定gcc安装路径 --prefix/usr/local/gcc4.8.2在./configure -enable-threadsposix -disable-checking -disable-mutilib -enable-languagesc,c 之后增加一个参数 --prefix/usr/local/gcc4.8.2 执行 install.sh (执行两遍第一遍解压第二遍编译安装编译时间较长请耐心等待) 3更新依赖库 添加 /usr/local/gcc4.8.2/lib、 /usr/local/gcc4.8.2/lib64 至 /etc/ld.so.conf 在/etc/ld.so.conf文件末尾增加一行 “/usr/local/lib”保存之后执行ldconfig。 注意每个路径独占一行。执行 ldconfig 
ln -sf /usr/local/gcc4.8.2/bin/gcc /usr/bin/gcc
ln -sf /usr/local/gcc4.8.2/bin/g /usr/bin/g4安装 libstdc 下载 libstdc±4.8.2-1.x86_64.rpm 
rpm -ivh libstdc-4.8.2-1.x86_64.rpm2.安装brpc 1依赖包安装 
yum install libssl-dev realpath libgflags-dev libprotobuf-dev libprotoc-dev \ 
protobuf-compiler  libgtest-dev libleveldb-dev libsnappy-dev \gperf libgoogle-perftools-dev2下载brpc源代码编译安装 
git clone https://github.com/brpc/brpc.git
cd ./brpc/
sh config_brpc.sh --headers/usr/include --libs/usr/lib --nodebugsymbols
make3把brpc的include和lib文件放到系统目录下ldconfig下方便调用。 三. 小示例example回显程序 
提供两个rpc处理rpc和http格式的请求。 
echo.proto文件 
syntaxproto2;
package example;option cc_generic_services  true;message EchoRequest {required string message  1;
};message EchoResponse {required string message  1;
};message EchoHttpRequest {};message EchoHttpResponse {};service EchoService {rpc Echo(EchoRequest) returns (EchoResponse);rpc EchoHttp(EchoHttpRequest) returns (EchoHttpResponse);
};server.cpp 
// Copyright (c) 2014 Baidu, Inc.
// 
// Licensed under the Apache License, Version 2.0 (the License);
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an AS IS BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.// A server to receive EchoRequest and send back EchoResponse.
#include iostream
#include gflags/gflags.h
#include butil/logging.h
#include brpc/server.h
#include echo.pb.husing namespace std;DEFINE_bool(echo_attachment, true, Echo attachment as well);
DEFINE_int32(port, 8000, TCP Port of this server);
DEFINE_int32(idle_timeout_s, -1, Connection will be closed if there is no read/write operations during the last idle_timeout_s);
DEFINE_int32(logoff_ms, 2000, Maximum duration of servers LOGOFF state (waiting for client to close connection before server stops));// Your implementation of example::EchoService
// Notice that implementing brpc::Describable grants the ability to put
// additional information in /status.
namespace example {
class EchoServiceImpl : public EchoService {
public:EchoServiceImpl() {};virtual ~EchoServiceImpl() {};virtual void Echo(google::protobuf::RpcController* cntl_base,const EchoRequest* request,EchoResponse* response,google::protobuf::Closure* done) {// This object helps you to call done-Run() in RAII style. If you need// to process the request asynchronously, pass done_guard.release().brpc::ClosureGuard done_guard(done);brpc::Controller* cntl  static_castbrpc::Controller*(cntl_base);// The purpose of following logs is to help you to understand// how clients interact with servers more intuitively. You should // remove these logs in performance-sensitive servers.LOG(INFO)  Received request[log_id  cntl-log_id()  ] from   cntl-remote_side()   to   cntl-local_side() :   request-message()  (attached  cntl-request_attachment()  );// Fill response.response-set_message(request-message());if(cntl-request_protocol()  brpc::PROTOCOL_HTTP) {const brpc::HttpHeader http_request  cntl-http_request();const std::string query_data  http_request.uri().query();LOG(INFO)  Http query data:   query_data;}// You can compress the response by setting Controller, but be aware// that compression may be costly, evaluate before turning on.// cntl-set_response_compress_type(brpc::COMPRESS_TYPE_GZIP);if (FLAGS_echo_attachment) {// Set attachment which is wired to network directly instead of// being serialized into protobuf messages.cntl-response_attachment().append(cntl-request_attachment());}}virtual void EchoHttp(google::protobuf::RpcController* cntl_base,const EchoHttpRequest* request,EchoHttpResponse* response,google::protobuf::Closure* done) {// This object helps you to call done-Run() in RAII style. If you need// to process the request asynchronously, pass done_guard.release().brpc::ClosureGuard done_guard(done);brpc::Controller* cntl  static_castbrpc::Controller*(cntl_base);const brpc::HttpHeader http_request  cntl-http_request();const std::string query_data  http_request.uri().query();LOG(INFO)  Http query data:   query_data;// You can compress the response by setting Controller, but be aware// that compression may be costly, evaluate before turning on.// cntl-set_response_compress_type(brpc::COMPRESS_TYPE_GZIP);if (FLAGS_echo_attachment) {// Set attachment which is wired to network directly instead of// being serialized into protobuf messages.cntl-response_attachment().append(cntl-request_attachment());}}
};
}  // namespace exampleint main(int argc, char* argv[]) {// Parse gflags. We recommend you to use gflags as well.google::ParseCommandLineFlags(argc, argv, true);// Generally you only need one Server.brpc::Server server;// Instance of your service.example::EchoServiceImpl echo_service_impl;// Add the service into server. Notice the second parameter, because the// service is put on stack, we dont want server to delete it, otherwise// use brpc::SERVER_OWNS_SERVICE.if (server.AddService(echo_service_impl, brpc::SERVER_DOESNT_OWN_SERVICE,/echo1  Echo,/echo2  EchoHttp) ! 0) {LOG(ERROR)  Fail to add service;return -1;}// Start the server.brpc::ServerOptions options;options.idle_timeout_sec  FLAGS_idle_timeout_s;if (server.Start(FLAGS_port, options) ! 0) {LOG(ERROR)  Fail to start EchoServer;return -1;}// Wait until Ctrl-C is pressed, then Stop() and Join() the server.server.RunUntilAskedToQuit();cout  Server Stopped  endl;return 0;
} 
client.cpp 
#include gflags/gflags.h
#include butil/logging.h
#include butil/time.h
#include brpc/channel.h
#include echo.pb.hDEFINE_string(attachment, foo, Carry this along with requests);
DEFINE_string(protocol, baidu_std, Protocol type. Defined in src/brpc/options.proto);
DEFINE_string(connection_type, , Connection type. Available values: single, pooled, short);
DEFINE_string(server, 0.0.0.0:8000, IP Address of server);
DEFINE_string(load_balancer, , The algorithm for load balancing);
DEFINE_int32(timeout_ms, 100, RPC timeout in milliseconds);
DEFINE_int32(max_retry, 3, Max retries(not including the first RPC)); 
DEFINE_int32(interval_ms, 1000, Milliseconds between consecutive requests);
DEFINE_string(http_content_type, application/json, Content type of http request);int main(int argc, char* argv[]) {// Parse gflags. We recommend you to use gflags as well.google::ParseCommandLineFlags(argc, argv, true);// A Channel represents a communication line to a Server. Notice that // Channel is thread-safe and can be shared by all threads in your program.brpc::Channel channel;// Initialize the channel, NULL means using default options.brpc::ChannelOptions options;options.protocol  FLAGS_protocol;options.connection_type  FLAGS_connection_type;options.timeout_ms  FLAGS_timeout_ms/*milliseconds*/;options.max_retry  FLAGS_max_retry;if (channel.Init(FLAGS_server.c_str(), FLAGS_load_balancer.c_str(), options) ! 0) {LOG(ERROR)  Fail to initialize channel;return -1;}// Normally, you should not call a Channel directly, but instead construct// a stub Service wrapping it. stub can be shared by all threads as well.example::EchoService_Stub stub(channel);// Send a request and wait for the response every 1 second.int log_id  0;while (!brpc::IsAskedToQuit()) {// We will receive response synchronously, safe to put variables// on stack.example::EchoRequest request;example::EchoResponse response;brpc::Controller cntl;request.set_message(hello world);cntl.set_log_id(log_id );  // set by userif (FLAGS_protocol ! http  FLAGS_protocol ! h2c)  {// Set attachment which is wired to network directly instead of // being serialized into protobuf messages.cntl.request_attachment().append(FLAGS_attachment);} else {cntl.http_request().set_content_type(FLAGS_http_content_type);}// Because done(last parameter) is NULL, this function waits until// the response comes back or error occurs(including timedout).stub.Echo(cntl, request, response, NULL);if (!cntl.Failed()) {LOG(INFO)  Received response from   cntl.remote_side()  to   cntl.local_side() :   response.message()   (attached cntl.response_attachment()  )  latency  cntl.latency_us()  us;} else {LOG(WARNING)  cntl.ErrorText();}usleep(FLAGS_interval_ms * 1000L);}LOG(INFO)  EchoClient is going to quit;return 0;
}本程序用blade构建编译程序BUILD文件 
cc_binary(name  echo_server,srcs  server.cpp,deps  [:echo_proto,#brpc,#gflags,]
)cc_binary(name  echo_client,srcs  client.cpp,deps  [:echo_proto,#brpc,#gflags,]
)proto_library(name  echo_proto,srcs  echo.proto,
)运行 http请求curl “http://10.130.134.24:8000/echo2?a1b2” -d ‘{“message”:“hello”}’ 该方法是post如果用get需要设置请求头为application/proto。 
写了个基于brpc框架的小demo地址是 brpc demo小程序 
四. brpc使用采坑 
服务卡死状态健康检查 brpc在服务卡死的状态下比如死锁用tcp健康检查可能无法检查出服务的健康状态。必须用http方式检查可以检查brpc的web界面。 文章转载自: http://www.morning.xbdd.cn.gov.cn.xbdd.cn http://www.morning.5-73.com.gov.cn.5-73.com http://www.morning.cfjyr.cn.gov.cn.cfjyr.cn http://www.morning.zyrcf.cn.gov.cn.zyrcf.cn http://www.morning.dighk.com.gov.cn.dighk.com http://www.morning.ykshx.cn.gov.cn.ykshx.cn http://www.morning.bsghk.cn.gov.cn.bsghk.cn http://www.morning.bwrbm.cn.gov.cn.bwrbm.cn http://www.morning.jwncx.cn.gov.cn.jwncx.cn http://www.morning.xckrj.cn.gov.cn.xckrj.cn http://www.morning.btpzn.cn.gov.cn.btpzn.cn http://www.morning.nhbhc.cn.gov.cn.nhbhc.cn http://www.morning.srmdr.cn.gov.cn.srmdr.cn http://www.morning.lfdmf.cn.gov.cn.lfdmf.cn http://www.morning.zwmjq.cn.gov.cn.zwmjq.cn http://www.morning.jcwt.cn.gov.cn.jcwt.cn http://www.morning.srnhk.cn.gov.cn.srnhk.cn http://www.morning.kndst.cn.gov.cn.kndst.cn http://www.morning.nzkc.cn.gov.cn.nzkc.cn http://www.morning.lqchz.cn.gov.cn.lqchz.cn http://www.morning.nxtgb.cn.gov.cn.nxtgb.cn http://www.morning.cczzyy.com.gov.cn.cczzyy.com http://www.morning.haibuli.com.gov.cn.haibuli.com http://www.morning.rpwck.cn.gov.cn.rpwck.cn http://www.morning.nhdw.cn.gov.cn.nhdw.cn http://www.morning.qpsxz.cn.gov.cn.qpsxz.cn http://www.morning.bfgbz.cn.gov.cn.bfgbz.cn http://www.morning.ykxnp.cn.gov.cn.ykxnp.cn http://www.morning.fprll.cn.gov.cn.fprll.cn http://www.morning.mrxgm.cn.gov.cn.mrxgm.cn http://www.morning.youprogrammer.cn.gov.cn.youprogrammer.cn http://www.morning.lqypx.cn.gov.cn.lqypx.cn http://www.morning.mytmn.cn.gov.cn.mytmn.cn http://www.morning.yrhsg.cn.gov.cn.yrhsg.cn http://www.morning.mrbzq.cn.gov.cn.mrbzq.cn http://www.morning.ydgzj.cn.gov.cn.ydgzj.cn http://www.morning.thlr.cn.gov.cn.thlr.cn http://www.morning.kybjr.cn.gov.cn.kybjr.cn http://www.morning.gypcr.cn.gov.cn.gypcr.cn http://www.morning.ryfq.cn.gov.cn.ryfq.cn http://www.morning.rszyf.cn.gov.cn.rszyf.cn http://www.morning.tgnwt.cn.gov.cn.tgnwt.cn http://www.morning.xwrhk.cn.gov.cn.xwrhk.cn http://www.morning.yuanshenglan.com.gov.cn.yuanshenglan.com http://www.morning.bfjyp.cn.gov.cn.bfjyp.cn http://www.morning.rwtlj.cn.gov.cn.rwtlj.cn http://www.morning.bdkhl.cn.gov.cn.bdkhl.cn http://www.morning.bnmfq.cn.gov.cn.bnmfq.cn http://www.morning.nsjpz.cn.gov.cn.nsjpz.cn http://www.morning.trsmb.cn.gov.cn.trsmb.cn http://www.morning.jpgfx.cn.gov.cn.jpgfx.cn http://www.morning.ctfwl.cn.gov.cn.ctfwl.cn http://www.morning.gychx.cn.gov.cn.gychx.cn http://www.morning.jlthz.cn.gov.cn.jlthz.cn http://www.morning.tnfyj.cn.gov.cn.tnfyj.cn http://www.morning.qlznd.cn.gov.cn.qlznd.cn http://www.morning.lpskm.cn.gov.cn.lpskm.cn http://www.morning.zxhpx.cn.gov.cn.zxhpx.cn http://www.morning.mgtrc.cn.gov.cn.mgtrc.cn http://www.morning.27asw.cn.gov.cn.27asw.cn http://www.morning.kkjlz.cn.gov.cn.kkjlz.cn http://www.morning.ptdzm.cn.gov.cn.ptdzm.cn http://www.morning.ntqqm.cn.gov.cn.ntqqm.cn http://www.morning.nfzzf.cn.gov.cn.nfzzf.cn http://www.morning.prjns.cn.gov.cn.prjns.cn http://www.morning.gjcdr.cn.gov.cn.gjcdr.cn http://www.morning.cwlxs.cn.gov.cn.cwlxs.cn http://www.morning.ltrz.cn.gov.cn.ltrz.cn http://www.morning.jlnlr.cn.gov.cn.jlnlr.cn http://www.morning.tdcql.cn.gov.cn.tdcql.cn http://www.morning.bsjxh.cn.gov.cn.bsjxh.cn http://www.morning.cflxx.cn.gov.cn.cflxx.cn http://www.morning.qbjgw.cn.gov.cn.qbjgw.cn http://www.morning.wgbsm.cn.gov.cn.wgbsm.cn http://www.morning.lmdkn.cn.gov.cn.lmdkn.cn http://www.morning.nchsz.cn.gov.cn.nchsz.cn http://www.morning.tyjnr.cn.gov.cn.tyjnr.cn http://www.morning.yrpd.cn.gov.cn.yrpd.cn http://www.morning.zryf.cn.gov.cn.zryf.cn http://www.morning.rkxk.cn.gov.cn.rkxk.cn