### Compile Hello World Example Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/zh/quick_start.md After successfully compiling the tRPC-Cpp framework, this command compiles the Hello World example code using Bazel. It targets all components within the examples/helloworld directory. ```shell bazel build //examples/helloworld/... ``` -------------------------------- ### Build tRPC-CPP Project (Shell) Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/en/quick_start.md This shell command demonstrates how to compile the updated tRPC-CPP HelloWorld example using Bazel. Ensure Bazel is installed and configured correctly for your project. ```shell bazel build //examples/helloworld/... ``` -------------------------------- ### Compile HelloWorld Example Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/en/quick_start.md After successfully compiling the tRPC-Cpp framework, this command compiles the HelloWorld example. It builds all targets related to the HelloWorld example, preparing it for execution. ```Shell bazel build //examples/helloworld/... ``` -------------------------------- ### Run tRPC-Cpp Hello World Client Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/zh/quick_start.md This command runs the client test program for the Hello World example. It requires a client configuration file to connect to the server. ```shell ./bazel-bin/examples/helloworld/test/fiber_client --client_config=./examples/helloworld/test/conf/trpc_cpp_fiber.yaml ``` -------------------------------- ### tRPC-Cpp Documentation Links Source: https://github.com/trpc-group/trpc-cpp/blob/main/README.zh_CN.md Provides links to essential documentation for tRPC-Cpp, including setup, quick start, basic tutorials, user guides, and API references. ```text Documentation Compile and install Quick start Basic tutorial User guide API interface ``` -------------------------------- ### Run HelloWorld Server Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/en/quick_start.md This command starts the HelloWorld server. It requires specifying the configuration file path for the tRPC-Cpp fiber implementation. ```Shell ./bazel-bin/examples/helloworld/helloworld_svr --config=./examples/helloworld/conf/trpc_cpp_fiber.yaml ``` -------------------------------- ### Run tRPC-Cpp Examples with Bazel Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/zh/setup_env.md This snippet demonstrates how to compile and run the example applications provided with the tRPC-Cpp framework after cloning the repository. It assumes the user is in the root directory of the cloned repository. ```shell # 进入根目录trpc-cpp cd trpc-cpp # 用bazel编译并运行框架提供的example示例 ./run_examples.sh ``` -------------------------------- ### Install Bazel on Ubuntu Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/zh/setup_env.md This snippet shows how to install Bazel on Ubuntu, including installing JDK dependencies and downloading/installing the Bazel installer script. It also includes a command to verify the Bazel version. ```shell apt install g++ unzip zip apt-get install default-jdk mkdir -p /root/env/bazel wget https://github.com/bazelbuild/bazel/releases/download/3.5.1/bazel-3.5.1-installer-linux-x86_64.sh -O /root/env/bazel/bazel.sh chmod +x /root/env/bazel/bazel.sh /root/env/bazel/bazel.sh > /dev/null rm -rf /root/env bazel --version ``` -------------------------------- ### tRPC-Cpp Documentation Links Source: https://github.com/trpc-group/trpc-cpp/blob/main/README.md Provides links to essential documentation for tRPC-Cpp, covering environment setup, quick start guides, basic tutorials, user guides, and API references. ```text Docs - [compile & install](docs/en/setup_env.md) - [quick start](docs/en/quick_start.md) - [basic tutorial](docs/en/basic_tutorial.md) - [user guide](docs/README.md) - [api reference](https://trpc-group.github.io/trpc-cpp.github.io/) ``` -------------------------------- ### Install GCC from Source Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/zh/setup_env.md This snippet outlines the process of installing GCC by compiling it from source code. It involves cloning the GCC source repository, configuring the build, compiling, and installing the compiler. ```shell # Download the source code git clone git://gcc.gnu.org/git/gcc.git yourSomeLocalDir ./configure make make install ``` -------------------------------- ### Install tRPC-Cpp via make install Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/zh/setup_env.md This snippet shows the process of installing tRPC-Cpp into the system after cloning the repository. It involves creating a build directory, configuring the build with CMake (optionally enabling shared library build), compiling the project, and then installing it. ```shell # 可checkout切换到最新的版本 git clone https://github.com/trpc-group/trpc-cpp.git cd trpc-cpp mkdir build && cd build # 默认编译静态库,可以通过cmake选项编译动态库: -DTRPC_BUILD_SHARED=ON cmake .. make -j8 make install ``` -------------------------------- ### Run Helloworld Example Script Source: https://github.com/trpc-group/trpc-cpp/blob/main/examples/helloworld/README.md Executes a shell script to quickly compile and run the Helloworld program. This is a convenient way to get the example up and running. ```shell sh examples/helloworld/run.sh ``` -------------------------------- ### Clone tRPC-Cpp Repository Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/zh/quick_start.md This command downloads the tRPC-Cpp framework source code from GitHub. It's the first step in setting up the development environment. ```shell git clone https://github.com/trpc-group/trpc-cpp ``` -------------------------------- ### Run HelloWorld Client Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/en/quick_start.md This command runs the HelloWorld client, which sends RPC requests to the running server. It requires a client configuration file path. ```Shell ./bazel-bin/examples/helloworld/test/fiber_client --client_config=./examples/helloworld/test/conf/trpc_cpp_fiber.yaml ``` -------------------------------- ### Install Bazel on CentOS Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/zh/setup_env.md This snippet shows how to install Bazel on CentOS, including installing JDK dependencies and downloading/installing the Bazel installer script. It also includes a command to verify the Bazel version. ```shell yum install java-11-openjdk yum install java-11-openjdk-devel mkdir -p /root/env/bazel wget https://github.com/bazelbuild/bazel/releases/download/3.5.1/bazel-3.5.1-installer-linux-x86_64.sh -O /root/env/bazel/bazel.sh chmod +x /root/env/bazel/bazel.sh /root/env/bazel/bazel.sh > /dev/null rm -rf /root/env bazel --version ``` -------------------------------- ### Run tRPC-CPP Server (Shell) Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/en/quick_start.md This command shows how to run the tRPC-CPP HelloWorld server after compilation. It specifies the path to the executable and the configuration file. ```shell ./bazel-bin/examples/helloworld/helloworld_svr --config=./examples/helloworld/conf/trpc_cpp_fiber.yaml ``` -------------------------------- ### Run Helloworld Server Source: https://github.com/trpc-group/trpc-cpp/blob/main/examples/features/fiber_forward/README.md Command to start the TRPC-CPP helloworld server using a specified configuration file. ```shell $ ./bazel-bin/examples/helloworld/helloworld_svr --config=./examples/helloworld/conf/trpc_cpp_fiber.yaml ``` -------------------------------- ### Clone tRPC-Cpp Repository Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/en/quick_start.md This command clones the tRPC-Cpp repository from GitHub to your local machine. It is the first step in setting up the tRPC-Cpp environment. ```Shell git clone https://github.com/trpc-group/trpc-cpp ``` -------------------------------- ### Run tRPC-Cpp Examples with CMake Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/zh/setup_env.md This snippet shows how to compile and run the example applications of the tRPC-Cpp framework using CMake after cloning the repository. It assumes the user is in the root directory of the cloned repository. ```shell # 进入根目录trpc-cpp cd trpc-cpp # 用cmake编译并运行框架提供的examples ./run_examples_cmake.sh ``` -------------------------------- ### Run tRPC Streaming RPC Example Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/zh/trpc_protocol_streaming_service.md Provides the shell command to run the tRPC streaming RPC example located in the tRPC-Cpp code repository. ```shell sh examples/features/trpc_stream/run.sh ``` -------------------------------- ### View HelloWorld Server Log Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/en/quick_start.md This command displays the log output from the HelloWorld server, which can be used to verify the RPC requests and responses. ```Shell cat helloworld_fiber.log ``` -------------------------------- ### Run Fiber Forward Server Source: https://github.com/trpc-group/trpc-cpp/blob/main/examples/features/fiber_forward/README.md Command to start the TRPC-CPP Fiber forward proxy server with its configuration. ```shell $ ./bazel-bin/examples/features/fiber_forward/proxy/fiber_forward --config=./examples/features/fiber_forward/proxy/trpc_cpp_fiber.yaml ``` -------------------------------- ### Original HelloWorld Service Definition Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/en/quick_start.md This is the original Protocol Buffers definition for the HelloWorld service, defining the SayHello RPC method and its request/reply message types. ```Protobuf syntax = "proto3"; package trpc.test.helloworld; service Greeter { rpc SayHello (HelloRequest) returns (HelloReply) {} } message HelloRequest { string msg = 1; } message HelloReply { string msg = 1; } ``` -------------------------------- ### Build and Run tRPC-Cpp Examples with Bazel Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/en/setup_env.md Instructions for compiling and running the tRPC-Cpp examples after cloning the repository. This uses the provided run_examples.sh script. ```sh cd trpc-cpp # Compile and run the examples provided by the framework using Bazel /run_examples.sh ``` -------------------------------- ### Run HTTP Example Script Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/en/http_protocol_client.md Executes a shell script to run an example demonstrating HTTP service interaction with tRPC-CPP. This script likely starts a client that sends various HTTP requests (GET, POST, HEAD) and verifies the responses. ```shell sh examples/features/http/run.sh ``` -------------------------------- ### Run Compilation and Execution Script Source: https://github.com/trpc-group/trpc-cpp/blob/main/examples/features/http_upload_download/README.md Executes a shell script to compile and run the HTTP upload/download example programs. This is a convenient way to get started. ```shell sh examples/features/http_upload_download/run.sh ``` -------------------------------- ### Build and Run tRPC-Cpp Examples with Bazel Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/en/setup_env.md This snippet shows how to compile and execute the example applications provided by the tRPC-Cpp framework using Bazel. It assumes the tRPC-Cpp repository has already been cloned to the local machine. ```shell cd trpc-cpp # Compile and run the examples provided by the framework using Bazel ./run_examples.sh ``` -------------------------------- ### Proto 文件组织 Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/zh/basic_tutorial.md Proto 文件目录结构包含 WORKSPACE 文件、BUILD 文件和 proto 文件本身。WORKSPACE 文件标识项目为 Bazel 项目,BUILD 文件用于 Bazel 规则管理 proto 文件,server/client 的 BUILD 文件可以依赖 proto 文件生成的 C++ 桩代码。 ```markdown - WORKSPACE文件:表示此proto目录是一个bazel项目,在forward bazel项目的WORKSPACE文件里,作为独立项目通过 `local_repository` 引入到forward项目中。 - BUILD文件:使用bazel规则来组织管理proto文件,forward项目的server/client的BUILD文件里,可通过 `@proto//:xxx_proto` 依赖对应proto文件生成的C++桩代码。 - proto文件:包含2个带依赖关系的proto文件,`forward.proto` 依赖 `deps/message.proto`,其文件组织位置关系,保持与trpc-cpp-tutorial下一致。 ``` -------------------------------- ### Accessing HTTP Service via URL (Bash) Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/en/http_protocol_service.md Provides an example of how to access the registered HTTP service using curl after the application has started. It shows a sample GET request to the '/foo' path and the expected response. ```bash # GET /foo HTTP/1.1 # e.g: curl http://$ip:$port/foo $ hello world! ``` -------------------------------- ### tRPC-Cpp Server Implementation Steps Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/en/basic_tutorial.md This outlines the key steps for implementing a tRPC service in C++. It covers choosing a runtime, defining process-level and service-level classes, registering plugins, handling initialization and destruction, and starting the application. ```text 1. Choose a runtime environment (thread model) and configure it in the global->threadmodel section of the tRPC-Cpp configuration YAML file. 2. Define a process-level class (e.g., ForwardServer) inheriting from `TrpcApp`. Override `RegisterPlugins`, `Initialize`, and `Destroy` methods for custom operations. 3. Define a service-level class (e.g., ForwardServiceServiceImpl) inheriting from the auto-generated service class. Override RPC methods, accepting `ServerContext`, request, and response parameters. 4. Register any custom plugins (e.g., Codec) in the `RegisterPlugins` method. 5. Perform process-level business initialization in `Initialize`, including pulling remote configurations and starting thread pools. Then, register the service implementation instance using `RegisterService`. 6. Implement process-level business destruction in `Destroy`, typically stopping resources created in `Initialize`, such as thread pools. 7. Use the process-level implementation class in the program's entry point (`main`), calling its `Main` and `Wait` functions to launch the application. ``` -------------------------------- ### Constructing Redis Commands Manually (Incorrect Example) Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/en/redis_client_guide.md Demonstrates an incorrect way to construct and send a Redis 'get' command using tRPC-Cpp. It highlights the potential for errors when manually creating commands instead of using provided interfaces. ```cpp // wrong example auto get_ctx = trpc::MakeClientContext(proxy); trpc::redis::Reply get_reply; std::string get_cmd = "get key"; // forbidden auto get_status = proxy->Command(get_ctx, &get_reply, std::move(get_cmd)); if (!mset_status.OK()) { std::cout << "redis get command error: " << mset_status.ErrorMessage() << std::endl; gProgramRet = -1; } else { std::cout << "redis get command success. reply: " << get_reply << std::endl; } ``` -------------------------------- ### Build and Run tRPC-Cpp Examples with CMake Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/en/setup_env.md Instructions for compiling and running the tRPC-Cpp examples using CMake after cloning the repository. This uses the provided run_examples_cmake.sh script. ```sh cd trpc-cpp # Compile and run the examples provided by the framework using Cmake ./run_examples_cmake.sh ``` -------------------------------- ### Install CMake on Ubuntu Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/zh/setup_env.md This snippet shows how to install CMake on Ubuntu using apt. It also includes a command to check the installed CMake version. ```shell apt install cmake cmake -version ``` -------------------------------- ### Run Example Script Source: https://github.com/trpc-group/trpc-cpp/blob/main/examples/features/http_async_upload_download/README.md Executes a shell script to quickly compile and run the HTTP async upload/download example. This is a convenient way to get the example working. ```shell sh examples/features/http_async_upload_download/run.sh ``` -------------------------------- ### Run HelloWorld Server Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/zh/basic_tutorial.md This shell command demonstrates how to compile and run the HelloWorld server example using Bazel. It specifies the configuration file to be used for the server startup. ```shell ./bazel-bin/examples/helloworld/helloworld_svr --config=./examples/helloworld/conf/trpc_cpp_fiber.yaml ``` -------------------------------- ### Synchronous Redis Command Call Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/en/redis_client_guide.md Provides an example of making a synchronous call to a Redis command using the initialized TRPC C++ proxy. It shows how to create a client context, execute a command (e.g., GET), and handle the reply, including checking for errors, nil replies, and successful string responses. ```cpp trpc::ClientContextPtr ctx = trpc::MakeClientContext(proxy); trpc::redis::Reply reply; auto status = proxy->Command(ctx, &reply, trpc::redis::cmdgen{}.get("trpc_cpp_redis_fiber")); if (!status.OK()) { std::cout << "Fiber call redis get command fail, error msg:" << status.ErrorMessage() << std::endl; gProgramRet = -1; } else if (reply.IsError()) { std::cout << "Fiber call redis get command fail, error msg:" << reply.GetString() << std::endl; } else if (reply.IsNil()) { std::cout << "Fiber call redis get command return Nil" << std::endl; } else { std::cout << "Fiber call redis get command success, reply:" << reply.GetString() << std::endl; } ``` -------------------------------- ### Run TRPC-CPP Attachment Demo Client (Shell) Source: https://github.com/trpc-group/trpc-cpp/blob/main/examples/features/trpc_attachment/README.md Starts the TRPC-CPP attachment demo client program. Requires the client binary and its client configuration file. ```shell $ ./bazel-bin/examples/features/trpc_attachment/client/client --client_config=./examples/features/trpc_attachment/client/trpc_cpp_fiber.yaml ``` -------------------------------- ### Run TRPC-CPP Attachment Demo Server (Shell) Source: https://github.com/trpc-group/trpc-cpp/blob/main/examples/features/trpc_attachment/README.md Starts the TRPC-CPP attachment demo server program. Requires the server binary and its configuration file. ```shell $ ./bazel-bin/examples/features/trpc_attachment/server/demo_server --config=./examples/features/trpc_attachment/server/trpc_cpp_fiber.yaml ``` -------------------------------- ### tRPC-Cpp Contribution Guide Source: https://github.com/trpc-group/trpc-cpp/blob/main/README.zh_CN.md Guides potential contributors on how to get involved with tRPC-Cpp, directing them to the contribution guidelines and open issues. ```text How to Contribute Check CONTRIBUTING.zh_CN.md Check issues ``` -------------------------------- ### Shell Script to Run tRPC Async Stream Example Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/en/trpc_protocol_streaming_service.md A shell script to execute the tRPC asynchronous streaming example. This command navigates to the example directory and runs the client program. ```shell sh examples/features/trpc_async_stream/run.sh ``` -------------------------------- ### Define tRPC Hello World Service (protobuf) Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/zh/quick_start.md This Protocol Buffers definition outlines the 'Greeter' service with a 'SayHello' RPC method that takes a 'HelloRequest' and returns a 'HelloReply'. It also defines the structure for these messages. ```protobuf syntax = "proto3"; package trpc.test.helloworld; service Greeter { rpc SayHello (HelloRequest) returns (HelloReply) {} } message HelloRequest { string msg = 1; } message HelloReply { string msg = 1; } ``` -------------------------------- ### Run tRPC-Cpp Hello World Server Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/zh/quick_start.md This command executes the compiled Hello World server application. It requires a configuration file to specify server settings, such as the tRPC C++ fiber configuration. ```shell ./bazel-bin/examples/helloworld/helloworld_svr --config=./examples/helloworld/conf/trpc_cpp_fiber.yaml ``` -------------------------------- ### Start Server Program Source: https://github.com/trpc-group/trpc-cpp/blob/main/examples/features/trpc_flatbuffers/README.md Launches the Flatbuffers demo server. It requires specifying the configuration file path for the server. ```shell # start server $ ./bazel-bin/examples/features/trpc_flatbuffers/server/demoserver --config=./examples/features/trpc_flatbuffers/server/trpc_cpp_fiber.yaml ``` -------------------------------- ### Install CMake on CentOS Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/zh/setup_env.md This snippet shows how to install CMake on CentOS using yum and create a symbolic link to make 'cmake' command available. It also includes a command to check the installed CMake version. ```shell yum install -y cmake3 ln -s /usr/bin/cmake3 /usr/bin/cmake cmake -version ``` -------------------------------- ### tRPC-Cpp Redis Client: Prohibited Manual Command String Construction Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/zh/redis_client_guide.md Manually constructing Redis command strings by concatenating strings is discouraged and can lead to errors. The tRPC-Cpp framework recommends using the `trpc::redis::cmdgen{}` series of interfaces to generate commands. This example shows the incorrect way to construct a 'get' command, which should be avoided. ```cpp // 错误用法示例 auto get_ctx = trpc::MakeClientContext(proxy); trpc::redis::Reply get_reply; std::string get_cmd = "get key"; // 禁止这样自己拼字符串 auto get_status = proxy->Command(get_ctx, &get_reply, std::move(get_cmd)); if (!mset_status.OK()) { std::cout << "redis get command error: " << mset_status.ErrorMessage() << std::endl; gProgramRet = -1; } else { std::cout << "redis get command success. reply: " << get_reply << std::endl; } ``` -------------------------------- ### Build and Run tRPC-Cpp Examples with CMake Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/en/setup_env.md This snippet outlines the process of compiling and running tRPC-Cpp example applications using CMake. It requires cloning the tRPC-Cpp repository first and then executing the provided script. ```shell cd trpc-cpp # Compile and run the examples provided by the framework using Cmake ./run_examples_cmake.sh ``` -------------------------------- ### Execute tRPC Stream Example (Shell) Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/en/trpc_protocol_streaming_service.md This shell script command navigates to the tRPC stream example directory and executes the necessary script to run the example. It's used to experience a synchronous streaming RPC service. ```shell sh examples/features/trpc_stream/run.sh ``` -------------------------------- ### Run Client Program Source: https://github.com/trpc-group/trpc-cpp/blob/main/examples/features/trpc_flatbuffers/README.md Starts the Flatbuffers demo client. The client needs its configuration file to connect to the server. ```shell # Run the client program $ ./bazel-bin/examples/features/trpc_flatbuffers/client/client --client_config=./examples/features/trpc_flatbuffers/client/trpc_cpp_fiber.yaml ``` -------------------------------- ### Install GCC on CentOS using SCL Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/zh/setup_env.md This snippet demonstrates how to install GCC 7 and its C++ compiler on CentOS using the Software Collections (SCL) repository. It includes enabling the devtoolset-7 environment to use the installed GCC version. ```shell yum install centos-release-scl-rh centos-release-scl yum install devtoolset-7-gcc devtoolset-7-gcc-c++ scl enable devtoolset-7 bash ``` -------------------------------- ### Run trpc-cpp Json Demo Client Source: https://github.com/trpc-group/trpc-cpp/blob/main/examples/features/trpc_noop/README.md This command starts the trpc-cpp demo client. It specifies the client binary and its configuration file, which contains client-specific settings for connecting to the server. ```shell $ ./bazel-bin/examples/features/trpc_noop/client/client --client_config=./examples/features/trpc_noop/client/trpc_cpp_fiber.yaml ``` -------------------------------- ### trpc-cpp: Synchronous HTTP Get Example Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/en/unit_testing.md Demonstrates a synchronous HTTP GET request using HttpServiceProxy in trpc-cpp. This function is used as a basis for mocking the network transport in unit tests. ```cpp using HttpServiceProxyPtr = std::shared_ptr<::trpc::http::HttpServiceProxy>; Status GetContent(HttpServiceProxyPtr& proxy, const std::string& url, rapidjson::Document* json) { auto client_context = ::trpc::MakeClientContext(proxy); return proxy->Get(context, url, json); } ``` -------------------------------- ### Handling Specific HTTP Methods and Path Parameters Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/en/http_protocol_service.md Provides examples of registering specific HTTP methods (GET, Head, Delete) with path parameters. It shows how to handle a DELETE request to / and a GET request for any path. ```cpp Delete("/"); }); // The first matching route takes priority. `/api/teapot` will come here. Get("/teapot", [](auto ctx, auto req, auto rep) { rep->SetStatus(::trpc::http::ResponseStatus::kIAmATeapot); }); // Whereas `/api/coffee_pot` will come here. Get("", TRPC_HTTP_HANDLER(coffee_pot_controller, CoffeePotController::Brew)); }); }); // clang-format on } ``` -------------------------------- ### Install and Integrate tRPC-Cpp via make install Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/en/setup_env.md This snippet provides instructions for installing tRPC-Cpp using `make install` and then integrating it into a CMake project. It covers cloning the repository, building it (optionally as a shared library), installing it, and configuring the CMakeLists.txt to find the installed headers and libraries, including setting paths for the stub code generation tools. ```shell # You can install the lastest verion by: git checkout tags/vx.x.x git clone https://github.com/trpc-group/trpc-cpp.git cd trpc-cpp mkdir build && cd build # By default, tRPC-Cpp will build as static lib. If you need dynamic lib, add cmake option: -DTRPC_BUILD_SHARED=ON cmake .. make -j8 make install # install at /usr/local/trpc-cpp/trpc ``` ```cmake # set install path of tRPC-Cpp set(TRPC_INSTALL_PATH /usr/local/trpc-cpp/trpc) # Load hearders and libs include(${TRPC_INSTALL_PATH}/cmake/config/trpc_config.cmake) include_directories(${INCLUDE_INSTALL_PATHS}) link_directories(${LIBRARY_INSTALL_PATHS}) # Set path of stub code genretated tool include(${TRPC_INSTALL_PATH}/cmake/tools/trpc_utils.cmake) set(PB_PROTOC ${TRPC_INSTALL_PATH}/bin/protoc) set(TRPC_CPP_PLUGIN ${TRPC_INSTALL_PATH}/bin/trpc_cpp_plugin) ``` -------------------------------- ### Redis Client Output Examples Source: https://github.com/trpc-group/trpc-cpp/blob/main/examples/features/redis/README.md This shows example output from the Redis client programs, demonstrating successful execution of set and get commands for both Fiber and Future asynchronous models. ```text Fiber call redis set command success. Fiber call redis get command success, reply: support_redis .... Futre Async call redis set command success Futre Async call redis get command success, reply: support_redis xxx ``` -------------------------------- ### Client Output Example Source: https://github.com/trpc-group/trpc-cpp/blob/main/examples/features/https/README.md This is an example of the output produced by the TRPC-CPP HTTPS client after successfully making requests to the server. It indicates the success of various HTTP methods like GET, HEAD, and POST. ```text name: GET(https)string, ok: 1 name: HEAD(https) response, ok: 1 name: HEAD https://github.com/, ok: 1 name: POST(https) string, ok: 1 name: POST(https) json, ok: 1 final result of http calling: 1 ``` -------------------------------- ### View Server Log Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/zh/quick_start.md This command displays the content of the server's log file, 'helloworld_fiber.log', which can be found in the directory where the server was started. The logs provide information about incoming requests and server activity. ```shell cat helloworld_fiber.log ``` -------------------------------- ### Compile Helloworld with Bazel Source: https://github.com/trpc-group/trpc-cpp/blob/main/examples/helloworld/README.md Compiles the client and server programs for the Helloworld example using Bazel. This command builds all necessary targets within the examples/helloworld directory. ```shell bazel build //examples/helloworld/... ``` -------------------------------- ### Get ServiceProxy in Pure Client Mode Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/zh/client_guide.md Illustrates obtaining a `ServiceProxy` in a pure client mode. It defines `ServiceProxyOption` with specific network, connection, timeout, selector, and target parameters, then uses these options to get a `ForwardServiceProxy`. ```cpp int Run() { trpc::ServiceProxyOption option; // proxy配置 option.name = FLAGS_target; option.codec_name = "trpc"; option.network = "tcp"; option.conn_type = "long"; option.timeout = 1000; option.selector_name = "direct"; option.target = FLAGS_addr; auto prx = trpc::GetTrpcClient()->GetProxy<::trpc::test::route::ForwardServiceProxy>(FLAGS_target, option); // 其他逻辑省略 } ``` -------------------------------- ### tRPC-Cpp Examples Source: https://github.com/trpc-group/trpc-cpp/blob/main/README.md Directs users to example projects for tRPC-Cpp, including a 'helloworld' demo and a demo showcasing various features. ```text Examples - [helloworld demo](examples/helloworld) - [various features demo](examples/features) ``` -------------------------------- ### Client-Only Plugin and Filter Registration Example (C++) Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/zh/custom_telemetry.md Provides an example of registering a custom telemetry plugin and its client filter in a client-only application scenario, typically done after configuration initialization and before other modules start. ```cpp int main(int argc, char* argv[]) { ParseClientConfig(argc, argv); TrpcPlugin::GetInstance()->RegisterTelemetry(MakeRefCounted()); TrpcPlugin::GetInstance()->RegisterClientFilter(std::make_shared()); return ::trpc::RunInTrpcRuntime([]() { return Run(); }); } ``` -------------------------------- ### Run tRPC Client Source: https://github.com/trpc-group/trpc-cpp/blob/main/examples/features/trpc_compressor/README.md Starts the tRPC client program, providing the client configuration file path for the compressor/decompressor demo. ```shell $ ./bazel-bin/examples/features/trpc_compressor/client/client --client_config=./examples/features/trpc_compressor/client/trpc_cpp_fiber.yaml ``` -------------------------------- ### Install Bazel 3.5.1 on Ubuntu Source: https://github.com/trpc-group/trpc-cpp/blob/main/docs/en/setup_env.md This section details the steps to install Bazel version 3.5.1 on Ubuntu, including installing prerequisites like JDK and GCC, downloading the Bazel installer, and making it executable. ```sh # install jdk apt install g++ unzip zip apt-get install default-jdk # install bazel mkdir -p /root/env/bazel wget https://github.com/bazelbuild/bazel/releases/download/3.5.1/bazel-3.5.1-installer-linux-x86_64.sh -O /root/env/bazel/bazel.sh chmod +x /root/env/bazel/bazel.sh /root/env/bazel/bazel.sh > /dev/null rm -rf /root/env # check version bazel --version ```