Skip to main content

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

Project details


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)

Uploaded Source

Built Distribution

discovery_client-0.1.3-py3-none-any.whl (9.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page