Example: Thrift over ZeroMQ
PyCon KR 2018
from callosum import Peer
from callosum.upper.thrift import ThriftServerAdaptor
import thriftpy
simple_thrift = thriftpy.load(
'simple.thrift',
module_name='simple_thrift')
class SimpleDispatcher:
async def echo(self, msg):
return msg
async def add(self, a, b):
return a + b
async def serve():
peer = Peer(bind='tcp://127.0.0.1:5000')
adaptor = ThriftServerAdaptor(
peer,
simple_thrift.SimpleService,
SimpleDispatcher())
peer.handle_function('simple',
adaptor.handle_function)
# here is the same open-listen-close routine
(Server)
service SimpleService {
string echo(1:string msg),
i64 add(1:i64 a, 2:i64 b),
}