keijack / python-eureka-client

A eureka client written in python. Support registering your python component to Eureka Server, as well as calling remote services by pulling the the Eureka registry.
MIT License
184 stars 43 forks source link

register to Eureka,but couldn't get service from register center #3

Closed moshowgame closed 5 years ago

moshowgame commented 5 years ago

现在可以用了。顺利注册到Eureka上面去,但是获取Eureka服务的时候,获取不了。

`# coding:utf-8 import tornado.httpserver import tornado.ioloop import tornado.options import tornado.web import py_eureka_client.eureka_client as eureka_client from tornado.options import define, options define("port", default=3333, help="run on the given port", type=int)

class IndexHandler(tornado.web.RequestHandler): def get(self): username = self.get_argument('username', 'Hello') self.write(username + ', Administrator User!')

if name == "main":

blog.csdn.net/moshowgame

tornado.options.parse_command_line()
#注册eureka服务
eureka_client.init_registry_client(eureka_server="http://eureka1x:9091/eureka/,http://eureka2x:9092/eureka/",
                        app_name="python-tornado-xyweb",
                        instance_port=3333)
#获取eureka服务
res = eureka_client.do_service("GRATEWAY", "/service/context/path")
print("result of other service" + res)
app = tornado.web.Application(handlers=[(r"/", IndexHandler)])
http_server = tornado.httpserver.HTTPServer(app)
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()`
keijack commented 5 years ago

由于发现服务和注册服务是分开的,所以在全局配置好注册服务之后,你还需要使用以下的方法来配置你的发现服务:

eureka_client.init_discovery_client("http://eureka1x:9091/eureka/,http://eureka2x:9092/eureka/")