Skip to main content

Find service from Consul

Project description

Consul Service Finder

I got a problem when I try to simulate multiple service register on Consul server and the client can find one of the services to use the API.

I can use below URL to get all services but that is not what I want.

curl http://localhost:8500/v1/agent/services

Ideas

* Consul Query to search service by name

* Counte the service be used

* Return min count of services by same service name

Example


    cs = ConsulServiceFinder()
    # load query information from Consul
    cs.queryLoadFromConsul()
    cs.displayQuery()
    # create query by service name
    service_name = "my-service"
    cs.createQueryByServiceName(service_name)
    query_name = "query_" + service_name 
    cs.executeQuery(query_name)
    # request one service from query
    consulService = cs.requestOneService(query_name)
    # compose service url from consulService object
    print(cs.composeServiceUrl(consulService))

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

consulservicefinder-0.0.1.tar.gz (3.0 kB view hashes)

Uploaded Source

Built Distribution

consulservicefinder-0.0.1-py3-none-any.whl (3.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