python 连接 Eureka
https://blog.51cto.com/u_15484875/4894826
https://blog.csdn.net/wangnu_043/article/details/102698847 (主要看这个)
py-eureka-client==0.10.5
注册服务
import py_eureka_client.eureka_client as eureka_client
eureka_client.init(
eureka_server="http://discovery:xxxx@test-discovery.center.xxxx.cn/eureka",
app_name="lucax2", #应用名字
should_register=True, #是否在注册中心展示
instance_port=8000) #展示的端口
调用服务的接口

import urllib
try:
res = eureka_client.do_service("PLATFORM-ACCOUNTHUB", "/1111accounts/10000",
# 返回类型,默认为 `string`,可以传入 `json`,如果传入值是 `json`,那么该方法会返回一个 `dict` 对象
return_type="string")
print(res)
except urllib.request.HTTPError as e:
# If all nodes are down, a `HTTPError` will raise.
print(e)
获取所有应用服务名和ip
https://www.pythonheidong.com/blog/article/750548/c880386a12df1ab2e83b/
client = eureka_client.get_client()
for app in client.applications.applications:
for ins in app.instances:
print("[%s] %s:%d" % (ins.instanceId, ins.ipAddr, ins.port.port))
#ins.secureVipAddress 为服务名
dir(ins) 可以看到各种方法 可以选用
说明
https://gitee.com/keijack/python-eureka-client
https://github.com/keijack/python-eureka-client

浙公网安备 33010602011771号