Skip to main content

An eureka client written in python, you can easily intergrate your python components with spring cloud.

Project description

python-eureka-client

Discription

This is an eureka client written in python, you can easily intergrate your python components with spring cloud.

Support Python Version

Python 2.7 / 3.6+ (It should also work at 3.5, not test)

Why choose

  • Register your python components to eureka server.
  • Support multiple eureka server registration.
  • Send heartbeat to eureka server.
  • Auto unregister from eureka server when your server down.
  • Discovery apps from eureka server.
  • Easy to use interface to use other REST service.
  • Auto try other nodes when one nodes down.

How to use

Install

pip install py_eureka_client

Use Both Registry And Discovery Service

This is the easiest way to use this component.

import py_eureka_client.eureka_client as eureka_client

your_rest_server_port = 9090
# The flowing code will register your server to eureka server and also start to send heartbeat every 30 seconds
eureka_client.init(eureka_server="http://your-eureka-server-peer1,http://your-eureka-server-peer2",
                                app_name="your_app_name",
                                instance_port=your_rest_server_port)

Then, in your business code, use

import py_eureka_client.eureka_client as eureka_client

res = eureka_client.do_service("OTHER-SERVICE-NAME", "/service/context/path")
print("result of other service" + res)

Only Register Your Server To Eureka Client

If your server only provide service, and does not need other components' service, you can only register your client to Eureka server and ignore the discovery client. Code is below:

import py_eureka_client.eureka_client as eureka_client

your_rest_server_port = 9090
# The flowing code will register your server to eureka server and also start to send heartbeat every 30 seconds
eureka_client.init_registry_client(eureka_server="http://your-eureka-server-peer1,http://your-eureka-server-peer2",
                                app_name="your_app_name",
                                instance_port=your_rest_server_port)

If you do not specify your host and ip just like the example above, the client will choose one that could connect to eureka server.

Only Use Discovery Service

If your service does not provide services but want to use other components' service, you can only use this discovery client.

First, init the discovery client after your server starts up.

import py_eureka_client.eureka_client as eureka_client

eureka_client.init_discovery_client("http://192.168.3.116:8761/eureka/, http://192.168.3.116:8762/eureka/")

Then, in your business code, use

import py_eureka_client.eureka_client as eureka_client

res = eureka_client.do_service("OTHER-SERVICE-NAME", "/service/context/path")
print("result of other service" + res)

do_service method will automatically try other nodes when one node return a HTTP error, until one success or all nodes being tried.

High Available Strategies

There are several HA strategies when using discovery client. They are:

  • HA_STRATEGY_RANDOM, default strategy, find an node randamly.
  • HA_STRATEGY_STICK, use one node until it going down.
  • HA_STRATEGY_OTHER, always use a different node from the last time.

In your init function or init_discovery_client, you can specify one of the above strategies:

import py_eureka_client.eureka_client as eureka_client
# General init method
eureka_client.init(eureka_server="http://your-eureka-server-peer1,http://your-eureka-server-peer2",
                   app_name="your_app_name",
                   instance_port=your_rest_server_port,
                   ha_ha_strategy=eureka_client.HA_STRATEGY_STICK)

# If you only use the discovery client
eureka_client.init_discovery_client("http://192.168.3.116:8761/eureka/, http://192.168.3.116:8762/eureka/",
                                    ha_ha_strategy=eureka_client.HA_STRATEGY_STICK)

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

py_eureka_client-0.3.0.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_eureka_client-0.3.0-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file py_eureka_client-0.3.0.tar.gz.

File metadata

  • Download URL: py_eureka_client-0.3.0.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7

File hashes

Hashes for py_eureka_client-0.3.0.tar.gz
Algorithm Hash digest
SHA256 ced4a9730327a475a051ab4ddf0cea886b801d33097083b43def7c32760a67db
MD5 1ee56a40ec8af5ccff6a67c97459de64
BLAKE2b-256 275c11ed5803d5532e02dd74b19d214534b483a593f0c5852650ffe0d9123a01

See more details on using hashes here.

File details

Details for the file py_eureka_client-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: py_eureka_client-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7

File hashes

Hashes for py_eureka_client-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 df4f94a12984e3057618b7fb2eb0168500df99a534b86cf8e5839d58e25ebb8f
MD5 ae94cb7d6f01de14ee042f8062056415
BLAKE2b-256 f091f786c2acae08e898dd590f5a69692971e58e83a4802a73e43541700c6491

See more details on using hashes here.

Supported by

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