主要是通过request进行续期:
# --*-- coding=utf-8 --*--
# author BillFang
import time
import threading
import requests
from urllib.parse import urlencode
from sanic import Sanic
import json
from sanic.response import json as js
app = Sanic("python ap")
@app.get("/api/python")
def home(request):
print("你调用到这个地方了。。。{}")
return js({"helloe": "world"})
def add_instance(username, password, service_name, ip, port, cluster_name=None,
weight=1.0, metadata=None, ephemeral=True, group_name="DEFAULT_GROUP"):
params = {
"ip": ip,
"port": port,
"serviceName": service_name,
"weight": weight,
"enable": True,
"healthy": True,
"clusterName": cluster_name,
"ephemeral": ephemeral,
"groupName": group_name
}
nacos_config_url = "http://localhost:8848/nacos/v1/ns/instance"
resp = requests.post(url=nacos_config_url, data=params)
if resp.status_code == 200:
request_heart(us

本文介绍了如何使用Python实现通过Nacos API进行服务实例的注册和续期,以及定期发送心跳以维护服务状态。重点在于request_heart函数,它负责定时发送请求更新服务实例信息。
最低0.47元/天 解锁文章
311

被折叠的 条评论
为什么被折叠?



