/zqrpc

Protocol Buffer RPC using zeromq

Primary LanguageC++MIT LicenseMIT

ZQRPC: Protocol Buffer RPC transport

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.

Usage

Server

  1. 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");
  1. Set Listening endpoints.
	rpc_server.EndPoint("tcp://*.9038");
	rpc_server.EndPoint("tcp://*.9039");
  1. Register the service of the handler implementations.
	zqrpc::ServiceBase *service = new EchoServiceImpl();
	rpc_server.RegisterService(service);
  1. Start the server service with n=5 workers
	rpc_server.Start(5);
  1. Stop the server gracefully
	rpc_server.Stop();

Client

  1. Start the context with n=1 string(s)
	context = new zmq::context_t(1);
  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);
  1. We need a controller, request and reply
	zqrpc::ZController controller;
	echo::EchoRequest request;
	echo::EchoResponse response;
  1. To have a single request
	long timeout=100; // milliseconds
	stub.Echo1(&controller, &request,&response, timeout);
	if (controller.ok() ) // have got result 
	.....
  1. 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 
	...
	

Compile

Requirements

  • 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+)

To Compile

mkdir build
cd build
cmake .. 
make

Run the example

  1. On one terminal from the build directory run
export GLOG_logtostderr=1
./example/EchoServer
  1. On another terminal from the build directory run
export GLOG_logtostderr=1 
./example/EchoClient

##Thank You

Kevin Sapper (sappo)