Git Product home page Git Product logo

pyapollo's Introduction

PyApollo - Python Client for Ctrip's Apollo

License

方便Python接入配置中心框架 Apollo 所开发的Python版本客户端。 Tested with python 2.7 & 3.6

Installation

python setup.py install

Features

  • 实时同步配置
  • 灰度配置

Missing Features

  • 客户端容灾

Usage

  • 启动客户端长连接监听
client = ApolloClient(app_id=<appId>, cluster=<clusterName>, config_server_url=<configServerUrl>)
client.start()
  • 获取Apollo的配置
    client.get_value(Key, DefaultValue)
    

Contribution

License

The project is licensed under the Apache 2 license.

Reference

Apollo : https://github.com/ctripcorp/apollo

pyapollo's People

Contributors

caimaoy avatar filamoon avatar jaredtan95 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyapollo's Issues

请问pyapollo暂时不支持集群么?

机器已经添加了server.properties文件,但是读取到的位置依然是default,并非是新增的集群。
所以请问是pyapllo暂时不支持集群么?

每次都会超时,如何获取配置之后直接关闭连接,不需要变更通知

代码:
def test_apollo():
client = pyapollo.ApolloClient(app_id='pubtrans-analysis', cluster='default', config_server_url='http://192.168.110.24:8080', timeout=60)
client.start()
zookeeper = client.get_value('zookeeper', 'default_value')
print zookeeper
client.stop()
配置能获取到,但是过一会儿就会报错,具体内容如下
ReadTimeout: HTTPConnectionPool(host='192.168.110.24', port=8080): Read timed out. (read timeout=60)

uwsgi+django项目中配置的apollo, 不能获取最新apollo数据

问题:

在uwsgi+django项目中接入apollo后发现,使用get_value获取到的数据是项目启动时cache中的数据,不能之后更新的apollo数据。

调试:

1、 在 uncached_http_get 和get_value中分别打印了cache中的值,
在apollo后台修改数据,这时,uncached_http_get 会打印出最近的cache数据,
再调用get_value,发现,cache中值是旧的数据。

2、 直接使用python manage runserver 启动项目,重复1的操作,发现,可以获取到最新的cache数据。

结论:

uwsgi启动项目使 get_vaule中的self 和 uncached_http_get 中的self并非一个对象。

不知道这个算不算bug,还是我uwsgi启的方式不对。如果有人碰到和我一样的问题并解决的朋友,请回复我一下,谢谢!

超时时间35秒太少了,要请求超时报错

apollo官方写的 注1:由于服务端会hold住请求30秒,所以请确保客户端访问服务端的超时时间要大于30秒,最好是60秒以上,因为Apollo后续可能会调整服务端hold住请求的时间为60秒。

目前写的35秒会超时,改成60秒以上则正常

連線會超時

第一次發起連線正常
但後面.stop 沒正常停止

仔細看除錯應是時序沒對準 在.stop運行前 又多跑了一次request

thread 模式下用户编写的代码无法收到 signal.SIGINT 信号

我在用 pyapollo 的 thread 模式编写 demo 时,signal.SIGINT 信号被 self._signal_handler 收到,导致 demo 程序无法退出。可否让 ApolloClient 不响应 signal.SIGINT,signal.SIGTERM 和 signal.SIGABRT 信号,改由用户在退出函数中显示调用 stop() 函数。

线程安全

请问这个是生产环境使用的代码吗?使用线程模式的话,连锁都不需要加吗?比如后台轮询线程会遍历 self._notification_map,前台线程在调用 get_value 的时候也有可能会修改 self._notification_map,这种情况下,应该会 crash 吧?之前并没有做个 python 多线程,求教

使用时 报错

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 445, in _make_request
six.raise_from(e, None)
File "", line 3, in raise_from
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 440, in _make_request
httplib_response = conn.getresponse()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1349, in getresponse
response.begin()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 316, in begin
version, status, reason = self._read_status()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 277, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/socket.py", line 704, in readinto
return self._sock.recv_into(b)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/requests/adapters.py", line 440, in send
resp = conn.urlopen(
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 755, in urlopen
retries = retries.increment(
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/util/retry.py", line 532, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/packages/six.py", line 770, in reraise
raise value
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 699, in urlopen
httplib_response = self._make_request(
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 447, in _make_request
self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 336, in _raise_timeout
raise ReadTimeoutError(
urllib3.exceptions.ReadTimeoutError: HTTPConnectionPool(host='127.0.0.1', port=7890): Read timed out. (read timeout=35)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/yingliming/Desktop/xlhy/python_apollo_demo/demo.py", line 4, in
client.start()
File "/Users/yingliming/Desktop/xlhy/python_apollo_demo/apolloclient.py", line 63, in start
self._long_poll()
File "/Users/yingliming/Desktop/xlhy/python_apollo_demo/apolloclient.py", line 121, in _long_poll
r = requests.get(url=url, params={
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/requests/api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/requests/api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/requests/sessions.py", line 529, in request
resp = self.send(prep, **send_kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/requests/sessions.py", line 645, in send
r = adapter.send(request, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/requests/adapters.py", line 532, in send
raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPConnectionPool(host='127.0.0.1', port=7890): Read timed out. (read timeout=35)

client 无法连接:JSONDecodeError

client = pyapollo.ApolloClient(app_id='py-rds', cluster='default', config_server_url='http://10.64.141.26:11118')
client.start()
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\hjyang\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pyapollo-0.0.1.dev1-py3.6.egg\pyapollo\apollo_client.py", line 63, in start
self._long_poll()
File "C:\Users\hjyang\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pyapollo-0.0.1.dev1-py3.6.egg\pyapollo\apollo_client.py", line 135, in long_poll
data = r.json()
File "C:\Users\hjyang\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\models.py", line 896, in json
return complexjson.loads(self.text, **kwargs)
File "C:\Users\hjyang\AppData\Local\Programs\Python\Python36-32\lib\json_init
.py", line 354, in loads
return _default_decoder.decode(s)
File "C:\Users\hjyang\AppData\Local\Programs\Python\Python36-32\lib\json\decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\hjyang\AppData\Local\Programs\Python\Python36-32\lib\json\decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.