zoukankan      html  css  js  c++  java
  • python注册到eureka

    由于python提供的服务没有加入到注册中心,没有办法实现高可用
    现将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
    
    define("port", default=8085, help="run on the given port", type=int)
    
    class IndexHandler(RequestHandler):
        def get(self):
            username = self.get_argument('username', 'Hello')
            self.write(username + ', Administrator User!')
    
    #restfulAPI功能实现在这里
    class TestHandler(RequestHandler):
        def get(self):
            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"/", IndexHandler),
                                                (r"/test", TestHandler)])
        http_server = tornado.httpserver.HTTPServer(app)
        http_server.listen(options.port)
        tornado.ioloop.IOLoop.instance().start()
        print("eureka exec")
    
    if __name__ == "__main__":
        eurekaclient()

    #参考
    #https://blog.csdn.net/xc_zhou/article/details/80637714
    #https://pypi.org/project/py-eureka-client/
  • 相关阅读:
    微信开发笔记-调用自定义分享接口
    应试教育
    AJAX学习笔记
    日志管理-Log4net
    linq学习笔记
    委托学习笔记后续:泛型委托及委托中所涉及到匿名方法、Lambda表达式
    Webservice服务创建、调用笔记
    设计模式(23)---迭代器模式
    设计模式(22)---备忘录模式
    设计模式(21)---访问者模式
  • 原文地址:https://www.cnblogs.com/mutong1228/p/10371734.html
Copyright © 2011-2022 走看看