| 40 | EchoServiceImpl() = default; |
| 41 | ~EchoServiceImpl() override = default; |
| 42 | void Echo(google::protobuf::RpcController* cntl_base, |
| 43 | const EchoRequest* request, |
| 44 | EchoResponse* response, |
| 45 | google::protobuf::Closure* done) override { |
| 46 | // This object helps you to call done->Run() in RAII style. If you need |
| 47 | // to process the request asynchronously, pass done_guard.release(). |
| 48 | brpc::ClosureGuard done_guard(done); |
| 49 | |
| 50 | auto cntl = static_cast<brpc::Controller*>(cntl_base); |
| 51 | |
| 52 | // The purpose of following logs is to help you to understand |
| 53 | // how clients interact with servers more intuitively. You should |
| 54 | // remove these logs in performance-sensitive servers. |
| 55 | LOG(INFO) << "Received request[log_id=" << cntl->log_id() |
| 56 | << "] from " << cntl->remote_side() |
| 57 | << " to " << cntl->local_side() |
| 58 | << ": " << request->message() |
| 59 | << ", request compress type=" << cntl->request_compress_type() |
| 60 | << ", attached=" << cntl->request_attachment(); |
| 61 | |
| 62 | // Fill response. |
| 63 | response->set_message(request->message()); |
| 64 | cntl->set_response_compress_type((brpc::CompressType)FLAGS_compress_type); |
| 65 | |
| 66 | // You can compress the response by setting Controller, but be aware |
| 67 | // that compression may be costly, evaluate before turning on. |
| 68 | // cntl->set_response_compress_type(brpc::COMPRESS_TYPE_GZIP); |
| 69 | |
| 70 | if (FLAGS_echo_attachment) { |
| 71 | // Set attachment which is wired to network directly instead of |
| 72 | // being serialized into protobuf messages. |
| 73 | cntl->response_attachment().append(cntl->request_attachment()); |
| 74 | } |
| 75 | } |
| 76 | }; |
| 77 | } // namespace example |
| 78 |
no test coverage detected