Closed JackyLucifer closed 1 year ago
例子中的接收到什么输出什么
询问一下,如何在处理的时候再去调用别的处理 类似有几部需要处理,怎么能自动触发下一步,我这里现在是两步 怎么能再第一个Echo中调用Echo2
class EchoServerImpl : public sofa::pbrpc::test::EchoServer { public: EchoServerImpl() {} virtual ~EchoServerImpl() {}
private: virtual void Echo(google::protobuf::RpcController controller, const sofa::pbrpc::test::EchoRequest request, sofa::pbrpc::test::EchoResponse response, google::protobuf::Closure done) { sofa::pbrpc::RpcController cntl = static_cast<sofa::pbrpc::RpcController>(controller); SLOG(INFO, "Echo(): request message from %s: %s", cntl->RemoteAddress().c_str(), request->message().c_str()); if (cntl->IsHttp()) { SLOG(INFO, "HTTP-PATH=\"%s\"", cntl->HttpPath().c_str()); std::map<std::string, std::string>::const_iterator it; const std::map<std::string, std::string>& query_params = cntl->HttpQueryParams(); for (it = query_params.begin(); it != query_params.end(); ++it) { SLOG(INFO, "QueryParam[\"%s\"]=\"%s\"", it->first.c_str(), it->second.c_str()); } const std::map<std::string, std::string>& headers = cntl->HttpHeaders(); for (it = headers.begin(); it != headers.end(); ++it) { SLOG(INFO, "Header[\"%s\"]=\"%s\"", it->first.c_str(), it->second.c_str()); } } response->set_message("echo message: " + request->message()); done->Run(); } virtual void Echo2(google::protobuf::RpcController controller, const sofa::pbrpc::test::EchoRequest request, sofa::pbrpc::test::EchoResponse response, google::protobuf::Closure done) { sofa::pbrpc::RpcController cntl = static_cast<sofa::pbrpc::RpcController>(controller); SLOG(INFO, "Echo(): request message from %s: %s", cntl->RemoteAddress().c_str(), request->message().c_str()); if (cntl->IsHttp()) { SLOG(INFO, "HTTP-PATH=\"%s\"", cntl->HttpPath().c_str()); std::map<std::string, std::string>::const_iterator it; const std::map<std::string, std::string>& query_params = cntl->HttpQueryParams(); for (it = query_params.begin(); it != query_params.end(); ++it) { SLOG(INFO, "QueryParam[\"%s\"]=\"%s\"", it->first.c_str(), it->second.c_str()); } const std::map<std::string, std::string>& headers = cntl->HttpHeaders(); for (it = headers.begin(); it != headers.end(); ++it) { SLOG(INFO, "Header[\"%s\"]=\"%s\"", it->first.c_str(), it->second.c_str()); } } response->set_message("echo message: " + request->message()); done->Run(); } };
例子中的接收到什么输出什么
询问一下,如何在处理的时候再去调用别的处理 类似有几部需要处理,怎么能自动触发下一步,我这里现在是两步 怎么能再第一个Echo中调用Echo2
class EchoServerImpl : public sofa::pbrpc::test::EchoServer { public: EchoServerImpl() {} virtual ~EchoServerImpl() {}
private: virtual void Echo(google::protobuf::RpcController controller, const sofa::pbrpc::test::EchoRequest request, sofa::pbrpc::test::EchoResponse response, google::protobuf::Closure done) { sofa::pbrpc::RpcController cntl = static_cast<sofa::pbrpc::RpcController>(controller); SLOG(INFO, "Echo(): request message from %s: %s", cntl->RemoteAddress().c_str(), request->message().c_str()); if (cntl->IsHttp()) { SLOG(INFO, "HTTP-PATH=\"%s\"", cntl->HttpPath().c_str()); std::map<std::string, std::string>::const_iterator it; const std::map<std::string, std::string>& query_params = cntl->HttpQueryParams(); for (it = query_params.begin(); it != query_params.end(); ++it) { SLOG(INFO, "QueryParam[\"%s\"]=\"%s\"", it->first.c_str(), it->second.c_str()); } const std::map<std::string, std::string>& headers = cntl->HttpHeaders(); for (it = headers.begin(); it != headers.end(); ++it) { SLOG(INFO, "Header[\"%s\"]=\"%s\"", it->first.c_str(), it->second.c_str()); } } response->set_message("echo message: " + request->message()); done->Run(); } virtual void Echo2(google::protobuf::RpcController controller, const sofa::pbrpc::test::EchoRequest request, sofa::pbrpc::test::EchoResponse response, google::protobuf::Closure done) { sofa::pbrpc::RpcController cntl = static_cast<sofa::pbrpc::RpcController>(controller); SLOG(INFO, "Echo(): request message from %s: %s", cntl->RemoteAddress().c_str(), request->message().c_str()); if (cntl->IsHttp()) { SLOG(INFO, "HTTP-PATH=\"%s\"", cntl->HttpPath().c_str()); std::map<std::string, std::string>::const_iterator it; const std::map<std::string, std::string>& query_params = cntl->HttpQueryParams(); for (it = query_params.begin(); it != query_params.end(); ++it) { SLOG(INFO, "QueryParam[\"%s\"]=\"%s\"", it->first.c_str(), it->second.c_str()); } const std::map<std::string, std::string>& headers = cntl->HttpHeaders(); for (it = headers.begin(); it != headers.end(); ++it) { SLOG(INFO, "Header[\"%s\"]=\"%s\"", it->first.c_str(), it->second.c_str()); } } response->set_message("echo message: " + request->message()); done->Run(); } };