SHARE
TWEET

bino:flask_zmq

a guest Aug 5th, 2014 230 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from flask import Flask, jsonify, request, abort, make_response
  2. import datetime
  3. import zmq
  4. import threading
  5. import time
  6. import requests
  7. app = Flask(__name__)
  8.  
  9. @app.route('/itemd', methods = ['POST'])
  10. def post_item() :
  11.         zpush.send_json(request.json)
  12.  
  13. def consumer():
  14.     print 'CONSUMER STARTED'
  15.     zpullctx = zmq.Context()
  16.     zpull = zpushctx.socket(zmq.PULL)
  17.     zpull.connect("inproc://zmq1")
  18.     while True:
  19.         data = zpull.recv_json()
  20.         print data
  21.  
  22. if __name__ == '__main__':
  23.     zpushctx = zmq.Context()
  24.     zpush = zpushctx.socket(zmq.PUSH)
  25.     zpush.bind("tcp://127.0.0.1:5557")
  26.     time.sleep(0.1)
  27.     threading.Thread(target=consumer,).start()
  28.     app.run(debug = True)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top