python脚本去配合RefreshScope动态刷新配置
大家都知道哇,eureka注册中心的服务,一个服务可能对应了多个机子,就会有多个ip,虽然使用@refreshScope刷新不需要重启服务就能生效配置,但是如果有10多个机子也是很奔溃的哇。。。
像我这种偷懒选手,肯定是要找躺平的办法
(✪ω✪)
@RefreshScope怎么实现刷新的就不多解释了,找到对应的服务地址加上/refresh
就能实现刷新了
直接上代码!!
import requests
from bs4 import BeautifulSoup
from urllib.parse import urlparse
URL = '你的eureka注册中心地址'
header = {'Accept': "application/json, text/plain, */*",'content-type': "application/x-www-form-urlencoded;charset=UTF-8"}
r = requests.get(url = URL, headers = header)
html = r.text
soup = BeautifulSoup(html, features="html.parser")
# MY-SERVICE
current = soup.find("td",text="*****-SERVICE")
# print('current:', current)
parent = current.find_parent()
# print('parent:', parent)
child = parent.findChild()
# print('child:', child)
next = current.find_next("td").find_next("td").find_next("td")
# print('next:', next)
find_all = next.find_all("a")
# print('find_all:', find_all)
# 遍历所有ip
for find in find_all:
find_href_ = find['href']
# print("find_href_:",find_href_)
_url = urlparse((find_href_))
refreshUrl =_url.scheme +'://'+ _url.hostname +':'+ str(_url.port)+'/refresh'
print("refreshUrl:",refreshUrl)
# 刷新多个服务
responseValue = requests.post(url=refreshUrl, headers=header)
# 获取响应内容
print("显示响应内容:", responseValue.text)
不清楚大家的eureka展示是否一样,大致就是获取页面标签去搜索对应服务下所有的ip,然后酱酱酱子。
办法有很多,我这个蠢蠢的但是还能用!够够了。
今天很困,就说这么多吧