mirror of
https://github.com/valitydev/thrift.git
synced 2024-11-07 10:48:51 +00:00
e59b73d3c2
* New style for Python is default now. * Symbols were replaced in newer versions of ZeroMQ (>=3.0). * Use Thrift's abstraction for `shared_ptr` instead of Boost. * Symbols were replaced in Python as well.
34 lines
804 B
Python
Executable File
34 lines
804 B
Python
Executable File
#!/usr/bin/env python
|
|
import zmq
|
|
import TZmqServer
|
|
import storage.ttypes
|
|
import storage.Storage
|
|
|
|
|
|
class StorageHandler(storage.Storage.Iface):
|
|
def __init__(self):
|
|
self.value = 0
|
|
|
|
def incr(self, amount):
|
|
self.value += amount
|
|
|
|
def get(self):
|
|
return self.value
|
|
|
|
|
|
def main():
|
|
handler = StorageHandler()
|
|
processor = storage.Storage.Processor(handler)
|
|
|
|
ctx = zmq.Context()
|
|
reqrep_server = TZmqServer.TZmqServer(processor, ctx, "tcp://0.0.0.0:9090", zmq.REP)
|
|
oneway_server = TZmqServer.TZmqServer(processor, ctx, "tcp://0.0.0.0:9091", zmq.PULL)
|
|
multiserver = TZmqServer.TZmqMultiServer()
|
|
multiserver.servers.append(reqrep_server)
|
|
multiserver.servers.append(oneway_server)
|
|
multiserver.serveForever()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|