thrift/contrib/zeromq/test-server.py
Stefan Bolus e59b73d3c2 THRIFT-4571: Updated ZeroMQ examples to ZeroMQ version >= 3.0. (#1556)
* 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.
2018-05-14 08:48:09 -04:00

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()