- Description
- Download/Installation
- Usage
- Releases
- Bugs/Issues/Enhancements
- Have questions or want to contribute to this project?
Description
Google's protocol buffer library makes writing rpc services easy, but it does not contain a rpc implementation. The transport details are left up to the user to implement.
This is a simple tcp/ip socket based rpc implementation in java and python for people who want a simple implementation of their protobuf rpc services.
See:
Download/Installation
Java
The libraries in the download section are compiled with Java 1.6, alternatively, you can download the source and use it directly.
You will also need the google protobuf library (version 2.2.0) in your classpath. You can get it from http://code.google.com/p/protobuf/downloads/list
Python
Python egg in download section.
Or checkout source from svn: http://code.google.com/p/protobuf-socket-rpc/source/browse/#svn/trunk/python
Usage
For a service MyService with a method MyMethod that takes in a MyRequest protobuf message and returns a MyResponse protobuf message.
Java
Sample server side usage code:
// Start server
SocketRpcServer socketRpcServer = new SocketRpcServer(serverPort,
Executors.newFixedThreadPool(threadPoolSize));
socketRpcServer.registerService(new MyServiceImpl());
socketRpcServer.run();Sample client side usage code:
// Create channel
SocketRpcChannel socketRpcChannel = new SocketRpcChannel(host, port);
SocketRpcController rpcController = socketRpcChannel.newRpcController();
// Call service
MyService myService = MyService.newStub(socketRpcChannel);
myService.myMethod(rpcController, myRequest,
new RpcCallback<MyResponse>() {
public void run(MyResponse myResponse) {
System.out.println("Received Response: " + myResponse);
}
});
// Check success
if (rpcController.failed()) {
System.err.println(String.format("Rpc failed %s : %s", rpcController.errorReason(),
rpcController.errorText()));
}Python
Sample server side usage code:
// Start server server = protobuf.server.SocketRpcServer(port) server.registerService(MyServiceImpl()) server.run()
Sample client side usage code:
// Define callback
class Callback:
def run(self,response):
print "Received Response: %s" % response
// Create channel
channel = protobuf.channel.SocketRpcChannel(hostname,port)
controller = channel.newController()
// Call service
service = MyService_Stub(channel)
service.myMethod(controller,request,Callback())
// Check success
if controller.failed():
print "Rpc failed %s : %s" % (controller.error,controller.reason)Releases
See ReleaseNotes
Please join the discussion group to be notified of new releases.
Bugs/Issues/Enhancements
If you find any issues/bugs or would like to suggest a new feature/enhancement, please create create a new issue. http://code.google.com/p/protobuf-socket-rpc/issues/list
Have questions or want to contribute to this project?
Please post a message on the discussion group, http://groups.google.com/group/protobuf-socket-rpc