def titanic_request(pipe): worker = MajorDomoWorker("tcp://localhost:5555", "titanic.request") reply = None while True: # Send reply if it's not null # And then get next request from broker request = worker.recv(reply) if not request: break # Interrupted, exit # Ensure message directory exists if not os.path.exists(TITANIC_DIR): os.mkdir(TITANIC_DIR) # Generate UUID and save message to disk uuid = uuid4().hex filename = request_filename(uuid) with open(filename, 'w') as f: pickle.dump(request, f) # Send UUID through to message queue pipe.send(uuid) # Now send UUID back to client # Done by the worker.recv() at the top of the loop reply = ["200", uuid]
def titanic_request(pipe): worker = MajorDomoWorker("tcp://localhost:5555", "titanic.request") reply = None while True: # Send reply if it's not null # And then get next request from broker request = worker.recv(reply) if not request: break # Interrupted, exit # Ensure message directory exists if not os.path.exists(TITANIC_DIR): os.mkdir(TITANIC_DIR) # Generate UUID and save message to disk uuid = str(uuid4()) filename = request_filename(uuid) with open(filename, 'w') as f: pickle.dump(request, f) # Send UUID through to message queue pipe.send(uuid) # Now send UUID back to client # Done by the worker.recv() at the top of the loop reply = ["200", uuid]
def titanic_request(pipe, verbose=False): worker = MajorDomoWorker("tcp://localhost:5555", b"titanic.request", verbose) reply = None # Ensure message directory exists TITANIC_DIR.mkdir(parents=True, exist_ok=True) while True: # Send reply if it's not null # And then get next request from broker request = worker.recv(reply) if not request: break # Interrupted, exit # Generate UUID and save message to disk uuid = uuid4().hex filename = request_filename(uuid) with open(filename, 'wb') as f: pickle.dump(request, f) # Send UUID through to message queue pipe.send(uuid.encode()) # Now send UUID back to client # Done by the worker.recv() at the top of the loop reply = [b"200", uuid.encode()]
def main(): verbose = '-v' in sys.argv worker = MajorDomoWorker("tcp://localhost:5555", b"echo", verbose) reply = None while True: request = worker.recv(reply) if request is None: break # Worker was interrupted reply = request # Echo is complex... :-)
def main(): verbose = '-v' in sys.argv worker = MajorDomoWorker("tcp://localhost:5555", "echo", verbose) reply = None while True: request = worker.recv(reply) if request is None: break # Worker was interrupted reply = request # Echo is complex... :-)
def main(): verbose = '-v' in sys.argv worker = MajorDomoWorker("tcp://localhost:5555", b"reverse", verbose) reply = None while True: request = worker.recv(reply) if request is None: break # Worker was interrupted # reverse the content of the message in form of [msg] request = [request[0].decode()[::-1].encode()] reply = request # Reverse is complex… :-)
def main(): """ This is the main function """ print(main.__doc__) verbose = '-v' in sys.argv worker = MajorDomoWorker("tcp://localhost:5555", b"square", verbose) reply = None while True: request = worker.recv(reply) if request is None: break # print(request) num = int(request[0].decode()) # print(num) reply = [str(num**2).encode()]
def main(): global publisher worker = MajorDomoWorker('tcp://localhost:5555', 'ST_MESSAGE_SERVER', False) reply = None context = zmq.Context.instance() publisher = context.socket(zmq.PUB) publisher.bind('tcp://*:5556') while True: request = worker.recv(reply) print '--------------', request if request is None: continue result = processMessage(request[0]) print result reply = [result]
def titanic_close(): worker = MajorDomoWorker("tcp://localhost:5555", "titanic.close") reply = None while True: request = worker.recv(reply) if not request: break # Interrupted, exit uuid = request.pop(0) req_filename = request_filename(uuid) rep_filename = reply_filename(uuid) # should these be protected? Does zfile_delete ignore files # that have already been removed? That's what we are doing here. if os.path.exists(req_filename): os.remove(req_filename) if os.path.exists(rep_filename): os.remove(rep_filename) reply = ["200"]
def titanic_close(verbose=False): worker = MajorDomoWorker("tcp://localhost:5555", b"titanic.close", verbose) reply = None while True: request = worker.recv(reply) if not request: break # Interrupted, exit uuid = request.pop(0).decode() req_filename = request_filename(uuid) rep_filename = reply_filename(uuid) # should these be protected? Does zfile_delete ignore files # that have already been removed? That's what we are doing here. if req_filename.exists(): req_filename.unlink() if rep_filename.exists(): rep_filename.unlink() reply = [b"200"]
def titanic_reply(): worker = MajorDomoWorker("tcp://localhost:5555", "titanic.reply") reply = None while True: request = worker.recv(reply) if not request: break # Interrupted, exit uuid = request.pop(0) req_filename = request_filename(uuid) rep_filename = reply_filename(uuid) if os.path.exists(rep_filename): with open(rep_filename, 'r') as f: reply = pickle.load(f) reply = ["200"] + reply else: if os.path.exists(req_filename): reply = ["300"] # pending else: reply = ["400"] # unknown
def titanic_reply(verbose=False): worker = MajorDomoWorker("tcp://localhost:5555", b"titanic.reply", verbose) reply = None while True: request = worker.recv(reply) if not request: break # Interrupted, exit uuid = request.pop(0).decode() req_filename = request_filename(uuid) rep_filename = reply_filename(uuid) if rep_filename.exists(): with open(rep_filename, 'rb') as f: reply = pickle.load(f) reply = [b"200"] + reply else: if req_filename.exists(): reply = [b"300"] # pending else: reply = [b"400"] # unknown