discovery service client
Project description
discovery-client
discovery-client package sync/async for consul.
Installing
Install and update using pip:
pip install -U discovery-client
Dependencies
Async client only
Usage Example
using standard client
from discovery.client import Consul
dc = Consul('localhost', 8500)
dc.find_service('consul')
Integration with Flask + threading.
import json
import threading
from discovery.client import Consul
from flask import Flask
app = Flask(__name__)
dc = Consul('discovery', 8500)
dc.register('standard-client', 5000)
@app.route('/manage/health')
def health():
return json.dumps({'status': 'UP'})
@app.route('/manage/info')
def info():
return json.dumps({'app': 'standard-client'})
@app.before_first_request
def enable_service_registry():
def probe_discovery_connection():
dc.consul_is_healthy()
thread = threading.Thread(target=probe_discovery_connection)
thread.start()
using asyncio
client using asyncio
import asyncio
from discovery import aioclient
loop = asyncio.get_event_loop()
dc = aioclient.Consul('localhost', 8500, loop)
search_one_task = loop.create_task(dc.find_service('consul'))
search_all_task = loop.create_task(dc.find_services('consul'))
loop.run_until_complete(search_one_task)
loop.run_until_complete(search_all_task)
using aiohttp
server using aiohttp + asyncio
import asyncio
from aiohttp import web
from discovery.aioclient import Consul
async def service_discovery(app):
app.loop.create_task(dc.register('aio-client', 5000))
asyncio.sleep(15)
app.loop.create_task(dc.consul_is_healthy())
async def handle_info(request):
return web.json_response({'app': 'aio-client'})
async def handle_status(request):
return web.json_response({'status': 'UP'})
app = web.Application()
dc = Consul('discovery', 8500, app.loop)
app.on_startup.append(service_discovery)
app.add_routes([web.get('/manage/health', handle_status),
web.get('/manage/info', handle_info)])
web.run_app(app, host='0.0.0.0', port=5000)
Links
- License: Apache License
- Code: https://github.com/amenezes/discovery-client
- Issue tracker: https://github.com/amenezes/discovery-client/issues
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
discovery-client-0.2.0.tar.gz
(4.8 kB
view hashes)
Built Distribution
Close
Hashes for discovery_client-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c707eca3e4bdae95b60ef3eef7487a9c2ac56bdc8d9533e681515c2b2ea3b9a |
|
MD5 | 0acff6244dcbae291c0400381bb8d355 |
|
BLAKE2b-256 | 8d3919bfe3b232fad7e6586e4ad61c3f7c3bdd3443c35e9638131171acd4dd20 |