Beispiel #1
0
 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 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)
Beispiel #3
0
 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
Beispiel #4
0
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)
Beispiel #5
0
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
#!/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()
Beispiel #7
0
#!/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)
Beispiel #8
0
"""
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)