python關聯eureka實現高並發


彌補網上python關聯微服務空白,結合多個pythonweb框架實踐,找到一個可行的方案
python加入到eureka,實現java和python的完美結合
# coding:utf-8
import tornado.httpserver
import tornado.ioloop
import tornado.options
from tornado.web import RequestHandler
import py_eureka_client.eureka_client as eureka_client
from tornado.options import define, options
import time

define("port", default=8085, help="run on the given port", type=int)

#restfulAPI功能實現在這里
class DiseaseHandler(RequestHandler):
    def get(self):
        name = self.get_argument("name","")
        age = self.get_argument("age", "")
        print("外部請求調用開始姓名:{},年齡:{}".format(name,age))
        time.sleep(10)
        print("休眠時間{}".format(10))
        self.write("hello world   welcome to you")

def eurekaclient():
    tornado.options.parse_command_line()
    # 注冊eureka服務
    eureka_client.init_registry_client(eureka_server="http://localhost:8091/eureka/",
                                       app_name="python-test",
                                       instance_port=8085)
    #提供外部調用的接口
    app = tornado.web.Application(handlers=[(r"/test", DiseaseHandler)])
    http_server = tornado.httpserver.HTTPServer(app)
    http_server.listen(options.port)
#並發數量
http_server.start(10) tornado.ioloop.IOLoop.instance().start() print(
"eureka exec") if __name__ == "__main__": eurekaclient()

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM