栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python脚本去配合RefreshScope动态刷新配置

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python脚本去配合RefreshScope动态刷新配置

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")
# MYACCOUNT-PORTAL-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,然后酱酱酱子。

办法有很多,我这个蠢蠢的但是还能用!够够了。
今天很困,就说这么多吧

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1026648.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号