1、安装 pip install py_eureka_client
import socket
from flask import Flask
import py_eureka_client.eureka_client as eureka_client
import py_eureka_client.netint_utils as netint_utils
app = Flask(__name__)
# 获取本机ip地址
local_ip = socket.gethostbyname(socket.gethostname())
try:
my_host_name = netint_utils.get_host_by_ip(local_ip)
except Exception as e:
print(e)
my_host_name = "unknown_host"
my_app_name = "dade"
server_port = 5008
eureka_server_address = "http://127.0.0.1:6868/eureka"
my_instance_ip = local_ip + ":" + str(server_port)
# 注册服务
eureka_client.init(
eureka_server=eureka_server_address,
app_name=my_app_name,
instance_id=my_instance_ip,
instance_host=my_host_name
)
@app.route("/detect", methods=['POST'])
def detect():
# 接口服务封装于此
return "Hello World!"
if __name__ == '__main__':
app.run(debug=True, host="0.0.0.0", port=5008)