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
discovery_client = Consul('localhost', 8500)
discovery_client.register('myapp', 5000)
discovery_client.find_service('consul')
Integration with Flask + threading.
import threading
import time
from discovery.client import Consul
from flask import Flask
app = Flask(__name__)
discovery_client = Consul('localhost', 8500)
discovery_client.register('myapp', 5000)
@app.before_first_request
def enable_service_registry():
def probe_discovery_connection():
while True:
discovery_client.consul_is_healthy()
time.sleep(10)
thread = threading.Thread(target=probe_discovery_connection)
thread.start()
using asyncio
client using asyncio
import asyncio
from discovery.aioclient import Consul
loop = asyncio.get_event_loop()
async def service_discovery():
await discovery_client.register('myapp', 5000)
discovery_client = Consul('localhost', 8500, loop)
loop.run_until_complete(service_discovery)
using aiohttp
server using iohttp + asyncio
from discovery.aioclient import Consul
from aiohttp import web
import asyncio
async def service_discovery():
await discovery_client.register('myapp', 5000)
async def handle(request):
name = request.match_info.get('name', 'Anonymous')
text = "Hello, " + name
return web.Response(text=text)
app = web.Application()
app.on_startup(service_discovery)
app.add_routes([web.get('/', handle),
web.get('/{name}', handle)])
web.run_app(app)
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.1.3.tar.gz
(4.0 kB
view hashes)
Built Distribution
Close
Hashes for discovery_client-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb8055b0a89ed93d9011d3b1ab47e52737b8df8642b87b1b867491664bee496a |
|
MD5 | ea9c571b3bd837965876aef09b1c21c4 |
|
BLAKE2b-256 | 47f5f2b3842182bd2f91295df935e8b741d9f454bc0ba0874116b06046517b25 |