def getApolloData(self, key): ''' :param key: 传入key :return: 返回apollo上对应的key键的value值 ''' client = ApolloClient(app_id=self.appid, config_server_url=self.url) client.start() return client.get_value(key, namespace=self.ns)
def apollo_client(self, app_id='yuanjie', cluster='yuanjie', config_server_url="http://106.54.227.205:8080"): """ client.get_value('yuanjie') :param app_id: :param cluster: :param config_server_url: :return: """ client = ApolloClient(app_id, cluster, config_server_url) client.start() return client
def apollo_client(): client = ApolloClient(app_id=APP_ID, config_server_url=URL, cycle_time=CYCLE_TIME, timeout=300) client.start() notification_num = 10000000000000 while True: num = client._notification_map['application'] if notification_num != num: notification_num = num res = client.get_value('hahaha') print('-------res', res) k8s = K8s() k8s.update_configmap({'hahaha': res}) time.sleep(CYCLE_TIME)
def apo_client(section, file_name): """ 获取apollo连接 :return: ApolloClient """ apollo_host = ini_conf(section=section, option='host', default='127.0.0.1', file_name=file_name) apollo_port = ini_conf(section=section, option='port', default=8080, file_name=file_name) apollo_cluster = ini_conf(section=section, option='cluster', default='default', file_name=file_name) apollo_app_id = ini_conf(section=section, option="app_id", default="", file_name=file_name) print("Debug apollo configure: {} {} {} {}".format(apollo_host, apollo_port, apollo_cluster, apollo_app_id)) ap_client = ApolloClient(app_id=apollo_app_id, config_server_url='http://' + apollo_host + ':' + str(apollo_port), cluster=apollo_cluster, timeout=300) ap_client.start() return ap_client
def apo_client(): """ 获取apollo客户端连接 return: ApolloClient """ print("debug apollo configures {} {} {} {} {}".format( apollo_host, apollo_port, apollo_cluster, apollo_namespace, apollo_app_id)) ap_client = ApolloClient(apollo_app_id, config_server_url='http://' + apollo_host + ':' + apollo_port, cluster=apollo_cluster, timeout=300) return ap_client
def getApolloData(key): ''' :param key: 传入key :return: 返回apollo上对应的key键的value值 ''' props = properties.Properties(r"./env.properties") url = props.get('appurl') appid = props.get('appid') ns = props.get('ns') client = ApolloClient(app_id=appid, config_server_url=url) client.start() print(client.get_value(key, namespace=ns)) return client.get_value(key, namespace=ns)
import time import threading from pyapollo import ApolloClient client = ApolloClient('Mengniu-Rec-test') def client_loop(loop_interval=3): while True: client.start() time.sleep(loop_interval) threading.Thread(target=client_loop, args=(3, )).start() def recommend(): v = client.get_value("source_id_weight") return v
from pyapollo import ApolloClient logging.basicConfig(level=logging.INFO, filename="new.log", filemode="a", format='%(levelname)s %(message)s', datefmt='%a, %d %b %Y %H:%M:%S') logger = logging.getLogger() node_ip = os.getenv("NODE_NAME", "default") pod_name = os.getenv("POD_NAME", "default") pod_namespace = os.getenv("POD_NAMESPACE", "default") pod_ip = os.getenv("POD_IP", "default") app_id = os.getenv("APP_ID", "SampleApp") cluster = os.getenv("CLUSTER", "default") config_server_url = os.getenv("CONFIG_SERVER_URL", "") svc_name = os.getenv("SVC_NAME") namespace = os.getenv("NAMESPACE", "default") client = None if config_server_url != "": client = ApolloClient(app_id=app_id, cluster=cluster, config_server_url=config_server_url, timeout=65, ip=svc_name) #client.start() t = threading.Thread(target=client.start, kwargs={"catch_signals": False}) t.start()
#!/usr/bin/env python # -*- coding: utf-8 -*- from pyapollo import ApolloClient client = ApolloClient(app_id="SampleApp", timeout=65) client.start(use_eventlet=True) timeout = client.get_value('timeout', namespace="demo") print("Timeout value is:%s" % timeout) # client.stop()
#!/usr/bin/env python # -*- coding:utf-8 -*- from pyapollo import ApolloClient from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): x = client.get_value("timeout", 10, "application") return x client = ApolloClient(app_id="test01", cluster="cluster1", config_server_url="http://10.14.41.63:8080", cache_file_path="./") if __name__ == '__main__': client.start() app.run(port=44556)
""" Author: Atom Create time: 2020-08-27 10:21 IDE: PyCharm """ import time import os from pyapollo import ApolloClient while True: client = ApolloClient(app_id='pm',config_server_url='http://192.168.102.202:8080') client.start(5) content=(client.get_value('pm')) fo = open("/work/code/.env","w") fo.write(content) fo.close() time.sleep(60)