Coder Social home page Coder Social logo

recall's Introduction

recall

Build Status

Python High performance RPC framework based on protobuf

Example

Suppose you want to write an Hello RPC service by recall, then you will define the following protocol:

// hello.proto

option py_generic_services = true; // This is required
message HelloRequest {
  string data;
}

message HelloResponse {
  string data;
}

service HelloService {
  rpc HelloMethod (HelloRequest) returns (HelloResponse);
}

Then compile the proto file:

$ protoc --python_out=. hello.proto

Then you can write your Hello service server like the following:

import hello_pb2
from recall.server import RpcServer

class HelloServiceImpl(hello_pb2.HelloService):
    def HelloMethod(self, rpc_controller, request, done):
        print 'recv', request.data
        return hello_pb2.HelloResponse(data='world')

if __name__ == '__main__':
    addr = ('0.0.0.0', 12345)
    print 'server listen at %s' % str(addr)
    server = RpcServer(addr)
    server.register_service(HelloServiceImpl())
    server.run(print_stat_interval=60)

And to access Hello service, you can simply use RpcClient like the following:

import hello_pb2
from recall.controller import RpcController
import recall.client

if __name__ == '__main__':
    client = recall.client.RpcClient()
    channel = client.get_tcp_channel(('127.0.0.1', 12345))
    stub = hello_pb2.HelloService_Stub(channel)

    req = hello_pb2.HelloRequest(data='hello')
    controller = RpcController()
    rsp = stub.HelloMethod(controller, req, None)
    print 'recv', rsp.data

Installation

You can install recall by simply using pip:

$ pip install recall

Or you can install recall by github source code:

$ git clone https://github.com/airekans/recall.git
$ cd recall
$ sudo python setup.py install

recall's People

Contributors

airekans avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.