python关联eureka实现高并发

时间:2022-08-01 16:11:56
弥补网上python关联微服务空白,结合多个pythonweb框架实践,找到一个可行的方案
python加入到eureka,实现java和python的完美结合
# coding:utf-
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=, 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()
print("休眠时间{}".format())
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=)
#提供外部调用的接口
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()