def _post_(self): user_id = str(self.current_user.get("_id", None)) user_name = str(self.current_user.get("name", None)) import time create_time = time.time() # 数据库操作 insertData = {} insertData["user_id"] = user_id insertData["status"] = 'start' insertData["logs"] = [{ "create_time": create_time, "info": { "stream": "started user registry" }, "user_id": user_id }] result = yield self.s_registry.insert_registry(insertData) # 加入队列 msg = Message( json.dumps({ "registry_id": result["registry_id"], "user_id": user_id, "user_name": user_name })) send_message(msg, settings.RUN_REGISTRY_EXCHANGE, settings.RUN_REGISTRY_ROUTING) if result is None: self.render_error(error_code=404, msg="not data") else: insertData["_id"] = result["registry_id"] self.write_result(data=insertData)
def on_queue_declare(self, q_info): callback_queue = q_info.queue self.ch.consume(callback_queue, self.on_response) self.corr_id = str(uuid.uuid4()) msg = Message(str(self.n), delivery_mode=2, reply_to=callback_queue, correlation_id=self.corr_id) self.ch.publish(msg, exchange='', routing_key='rpc_queue')
def _post_(self): project_url = self.get_argument("project_url",None) project_name = self.get_argument("project_name",None) storage_path = self.get_argument("storage_path",None) user_id = str(self.current_user.get("_id",None)) user_name = str(self.current_user.get("name",None)) create_time = time.time() # 数据库操作 insertData = {} insertData["project_url"] = project_url insertData["project_name"] = project_name insertData["storage_path"] = storage_path insertData["user_id"] = user_id insertData["status"] = 'created' insertData["logs"] = [{"create_time":create_time,"info":{"stream":"started run application:"+project_name},"user_id":user_id}] result = yield self.s_application.insert_application(insertData) # 加入队列 msg = Message( json.dumps({ "application_id":result["_id"], "project_url":project_url, "project_name":project_name, "storage_path":storage_path, "user_id":user_id, "user_name":user_name, 'app_count':1, "reply_to":'service_logs' })) send_message(msg,settings.RUN_APPLICATION_EXCHANGE,settings.RUN_APPLICATION_ROUTING) if result is None: self.render_error(error_code=404,msg="not data") else: insertData["_id"] = result["_id"] self.write_result(data=insertData)
def on_request(msg): n = int(msg.body) print " [.] fib(%s)" % n response = str(fib(n)) response_msg = Message(response, delivery_mode=2, correlation_id=msg.correlation_id) ch.publish(response_msg, exchange='', routing_key=msg.reply_to) msg.ack()
def _post_(self): access_type = self.get_argument("type",None) application_id = self.get_argument("id",None) access_content = self.get_argument("content","") container_info =yield self.s_application.find_one(application_id) if container_info is None: container_info = {} # 从数据库获取,切记不要对外公开 container_host = container_info.get("run_host",None) container_name = container_info.get("app_name",None) if container_host is None or container_name is None: self.render_error(error_code=404,msg="not success") user_id = str(self.current_user.get("_id",None)) user_name = str(self.current_user.get("name",None)) create_time = time.time() # 数据库操作 accessData = {} accessData["access_type"] = access_type accessData["application_id"] = application_id accessData["container_name"] = container_name accessData["container_host"] = container_host accessData["access_content"] = access_content accessData["user_id"] = user_id accessData["status"] = 'start' accessData["logs"] = [ { "create_time":create_time, "info":"started access application:"+application_id+",it is hosted in "+container_host, "user_id":user_id } ] result= yield self.s_application_access.access_application(accessData) # 加入队列 msg = Message( json.dumps({ "access_id":result, "access_type":access_type, "access_content":access_content, "application_id":application_id, "container_host":container_host, "container_name":container_name, "user_id":user_id, "user_name":user_name, "reply_to":'access_logs' })) send_message(msg,settings.ACCESS_APPLICATION_EXCHANGE,settings.ACCESS_APPLICATION_ROUTING+"."+container_host) if result is None: self.render_error(error_code=404,msg="not data") else: accessData["_id"] = str(result) self.write_result(data=accessData)
def _post_(self): project_url = self.get_argument("project_url", None) project_name = self.get_argument("project_name", None) project_id = self.get_argument("project_id", None) user_id = str(self.current_user.get("_id", None)) user_name = str(self.current_user.get("name", None)) create_time = time.time() # 数据库操作 insertData = {} insertData["project_url"] = project_url insertData["project_name"] = project_name insertData["project_id"] = project_id insertData["user_id"] = user_id insertData["status"] = 'created' insertData["logs"] = [{ "create_time": create_time, "info": { "stream": "started build project:" + project_name }, "user_id": user_id }] result = yield self.s_service.insert_service(insertData) # 加入队列 msg = Message( json.dumps({ "project_url": project_url, "project_name": project_name, "project_id": project_id, "user_id": user_id, "user_name": user_name, "reply_to": 'service_logs' })) send_message(msg, settings.CREATE_SERVICE_EXCHANGE, settings.CREATE_SERVICE_ROUTING) if result is None: self.render_error(error_code=404, msg="not data") else: insertData["_id"] = str(result) self.write_result(data=insertData)
#! /usr/bin/env python import logging import sys from tornado.ioloop import IOLoop from stormed import Connection, Message # delivery_mode=2 makes message persistent routing_key = sys.argv[1] if len(sys.argv) > 1 else 'anonymous.info' msg = Message(' '.join(sys.argv[2:]) or 'Hello World!') def on_connect(): ch = conn.channel() ch.exchange_declare(exchange='topic_logs', type='topic') ch.publish(msg, exchange='topic_logs', routing_key=routing_key) conn.close(callback=done) def done(): print " [x] Sent %r:%r" % (routing_key, msg.body) io_loop.stop() logging.basicConfig() conn = Connection(host='localhost') conn.connect(on_connect) io_loop = IOLoop.instance() io_loop.start()
#! /usr/bin/env python import logging import sys from tornado.ioloop import IOLoop from stormed import Connection, Message # delivery_mode=2 makes message persistent msg = Message(' '.join(sys.argv[1:]) or 'Hello World!', delivery_mode=2) def on_connect(): ch = conn.channel() ch.queue_declare(queue='task_queue', durable=True) ch.publish(msg, exchange='', routing_key='task_queue') conn.close(callback=done) def done(): print " [x] Sent %r" % msg.body io_loop.stop() logging.basicConfig() conn = Connection(host='localhost') conn.connect(on_connect) io_loop = IOLoop.instance() io_loop.start()
#! /usr/bin/env python import logging from tornado.ioloop import IOLoop from stormed import Connection, Message msg = Message('Hello World!') def on_connect(): ch = conn.channel() ch.queue_declare(queue='hello') ch.publish(msg, exchange='', routing_key='hello') conn.close(callback=done) def done(): print " [x] Sent 'Hello World!'" io_loop.stop() logging.basicConfig() conn = Connection(host='localhost') conn.connect(on_connect) io_loop = IOLoop.instance() io_loop.start()
def get(self): req_id = str(id(self)) request_map[req_id] = self msg = Message(req_id, delivery_mode=1) ch.publish(msg, exchange=XNAME)
#! /usr/bin/env python import logging import sys from tornado.ioloop import IOLoop from stormed import Connection, Message # delivery_mode=2 makes message persistent msg = Message(' '.join(sys.argv[1:]) or 'info: Hello World!') def on_connect(): ch = conn.channel() ch.exchange_declare(exchange='logs', type='fanout') ch.publish(msg, exchange='logs', routing_key='') conn.close(callback=done) def done(): print " [x] Sent %r" % msg.body io_loop.stop() logging.basicConfig() conn = Connection(host='localhost') conn.connect(on_connect) io_loop = IOLoop.instance() io_loop.start()