The idea is to create a mechanism for sending multiple requests if parallel and getting their answers when needed. In between, the client thread is free to do its own work. It is not necessary to fetch results in the same order as they have been submitted.
Please have a look at the examples folder.
- Start the context with n=1 string(s) and set up the server
context = new zmq::context_t(1); zqrpc::RpcServer rpc_server(context); // zqrpc::RpcServer rpc_server(context,".extn");
- Set Listening endpoints.
rpc_server.EndPoint("tcp://*.9038"); rpc_server.EndPoint("tcp://*.9039");
- Register the service of the handler implementations.
zqrpc::ServiceBase *service = new EchoServiceImpl(); rpc_server.RegisterService(service);
- Start the server service with n=5 workers
rpc_server.Start(5);
- Stop the server gracefully
rpc_server.Stop();
- Start the context with n=1 string(s)
context = new zmq::context_t(1);
- Create a channel to connect to a tcp host/port OR ipc OR inproc
zqrpc::RpcChannel rpc_channel(context,"http://127.0.0.1:9038"); echo::EchoService::Stub stub(&rpc_channel);
- We need a controller, request and reply
zqrpc::ZController controller; echo::EchoRequest request; echo::EchoResponse response;
- To have a single request
long timeout=100; // milliseconds stub.Echo1(&controller, &request,&response, timeout); if (controller.ok() ) // have got result .....
- For several parallel requests send them together and receive the results as you need them. Order of receive need not match that of send. The timeout holds for that request only, please refer to the example provided for a timer implementation.
// Send stub.Echo1_Send(&controller1, &request1); stub.Echo1_Send(&controller2, &request2); stub.Echo2_Send(&controller3, &request3); // Receive .. timeout holds for that particular request stub.Echo1_Recv(&controller1, &response1,timeout); if (controller1.ok() ) // have got result ... stub.Echo1_Recv(&controller2, &response2,timeout); if (controller2.ok() ) // have got result ... stub.Echo2_Recv(&controller3, &response3,timeout); if (controller3.ok() ) // have got result ...
- a C++ compiler ( g++/clang++)
- cmake ( v2.8+ )
- ZeroMQ ( v4.0.5+ )
- Google Protocol Buffers ( v2.5 )
- Google Logging Framework - glog ( v0.3.3 )
- Boost ( v1.48+)
mkdir build cd build cmake .. make
- On one terminal from the build directory run
export GLOG_logtostderr=1 ./example/EchoServer
- On another terminal from the build directory run
export GLOG_logtostderr=1 ./example/EchoClient
##Thank You
Kevin Sapper (sappo)