Browse Source

Update tutorial (#372)

liyingxin 1 month ago
parent
commit
1cbe518a0c

+ 2 - 0
tutorial/tutorial-01-srpc_pb_server.cc

@@ -53,6 +53,8 @@ int main()
 
 	if (server.start(1412) == 0)
 	{
+		printf("SRPC framework SRPC Protobuf server is running on 1412\n"
+			   "Try ./srpc_pb_client to send requests.\n\n");
 		wait_group.wait();
 		server.stop();
 	}

+ 1 - 0
tutorial/tutorial-02-srpc_pb_client.cc

@@ -38,6 +38,7 @@ int main()
 		else
 			printf("status[%d] error[%d] errmsg:%s\n",
 					ctx->get_status_code(), ctx->get_error(), ctx->get_errmsg());
+		wait_group.done();
 	});
 
 	//sync

+ 2 - 0
tutorial/tutorial-03-srpc_thrift_server.cc

@@ -53,6 +53,8 @@ int main()
 
 	if (server.start(1412) == 0)
 	{
+		printf("SRPC framework SRPC protocol server with thrift IDL is running on 1412\n"
+			   "Try ./srpc_thrift_client to send requests.\n\n");
 		wait_group.wait();
 		server.stop();
 	}

+ 1 - 0
tutorial/tutorial-04-srpc_thrift_client.cc

@@ -52,6 +52,7 @@ int main()
 		else
 			printf("status[%d] error[%d] errmsg:%s\n",
 					ctx->get_status_code(), ctx->get_error(), ctx->get_errmsg());
+		wait_group.done();
 	});
 
 	//sync

+ 2 - 0
tutorial/tutorial-05-brpc_pb_server.cc

@@ -55,6 +55,8 @@ int main()
 
 	if (server.start(1412) == 0)
 	{
+		printf("SRPC framework BRPC Protobuf server is running on 1412\n"
+			   "Try ./brpc_pb_client to send requests.\n\n");
 		wait_group.wait();
 		server.stop();
 	}

+ 2 - 0
tutorial/tutorial-06-brpc_pb_client.cc

@@ -43,6 +43,8 @@ int main()
 
 		while (ctx->get_attachment(&attachment, &len))
 			printf("get attachment [%.*s] len=%zu\n", (int)len, attachment, len);
+
+		wait_group.done();
 	});
 
 	//sync

+ 2 - 0
tutorial/tutorial-07-thrift_thrift_server.cc

@@ -52,6 +52,8 @@ int main()
 
 	if (server.start(1412) == 0)
 	{
+		printf("SRPC framework Thrift protocol server with thrift IDL is running on 1412\n"
+			   "Try ./thrift_thrift_client to send requests.\n\n");
 		wait_group.wait();
 		server.stop();
 	}

+ 2 - 0
tutorial/tutorial-10-server_async.cc

@@ -71,6 +71,8 @@ int main(int argc, char *argv[])
 
 	if (server.start(1412) == 0)
 	{
+		printf("Asynchronous server with HTTP requests is running on 1412\n"
+			   "Try ./client_task or ./srpc_pb_client to trigger this example.\n\n");
 		wait_group.wait();
 		server.stop();
 	}

+ 2 - 1
tutorial/tutorial-11-trpc_pb_server.cc

@@ -63,7 +63,8 @@ int main()
 
 	if (server.start(1412) == 0)
 	{
-		printf("SRPC framework TRPC server running on 1412...\n");
+		printf("SRPC framework TRPC server is running on 1412\n"
+			   "Try ./trpc_pb_client to send requests.\n\n");
 		wait_group.wait();
 		server.stop();
 	}

+ 1 - 0
tutorial/tutorial-12-trpc_pb_client.cc

@@ -38,6 +38,7 @@ int main()
 		else
 			printf("status[%d] error[%d] errmsg:%s\n",
 					ctx->get_status_code(), ctx->get_error(), ctx->get_errmsg());
+		wait_group.done();
 	});
 
 	//sync

+ 2 - 1
tutorial/tutorial-13-trpc_http_server.cc

@@ -63,7 +63,8 @@ int main()
 
 	if (server.start(1412) == 0)
 	{
-		printf("SRPC framework TRPCHttp server running on 1412...\n");
+		printf("SRPC framework TRPCHttp server is running on 1412\n"
+			   "Try ./trpc_http_client to send requests.\n\n");
 		wait_group.wait();
 		server.stop();
 	}

+ 7 - 0
tutorial/tutorial-15-srpc_pb_proxy.cc

@@ -38,8 +38,13 @@ private:
 public:
 	void Echo(EchoRequest *request, EchoResponse *response, RPCContext *context) override
 	{
+		printf("Proxy Server Echo() get and transfer request:\n%s\n",
+				request->DebugString().c_str());
+
 		auto *task = this->client->create_Echo_task([response](EchoResponse *resp,
 															   RPCContext *ctx) {
+			printf("Proxy Server Echo() get and transfer response:\n%s\n",
+				   resp->DebugString().c_str());
 			if (ctx->success())
 				*response = std::move(*resp);
 		});
@@ -67,6 +72,8 @@ int main()
 
 	if (server.start(61412) == 0)
 	{
+		printf("Proxy server serving on 61412 and redirect to backend server 127.0.0.1:1412\n"
+			   "Try start ./srpc_pb_server as backend and send requests to 61412.\n\n");
 		wait_group.wait();
 		server.stop();
 	}

+ 3 - 0
tutorial/tutorial-16-server_with_metrics.cc

@@ -73,6 +73,9 @@ int main()
 
 	if (server.start(1412) == 0)
 	{
+		printf("Server with metrics for Promethes(port:8080) is running on 1412\n"
+			   "Try ./srpc_pb_client to send requests.\n"
+			   "Try ' curl http://localhost:8080/metrics ' to get prometheus data.\n");
 		wait_group.wait();
 		server.stop();
 	}

+ 2 - 0
tutorial/tutorial-17-http_server.cc

@@ -59,6 +59,8 @@ int main()
 
 	if (server.start(1412) == 0)
 	{
+		printf("HTTP protocol server is running on 1412\n"
+			   "Try ./http_client to send requests.\n\n");
 		wait_group.wait();
 		server.stop();
 	}

+ 2 - 0
tutorial/tutorial-18-http_client.cc

@@ -45,6 +45,8 @@ void callback(WFHttpTask *task)
 		fflush(stdout);
 		fprintf(stderr, "\nfinish print body. body_len = %zu\n", body_len);
 	}
+
+	wait_group.done();
 }
 
 int main()