keijack / python-eureka-client

A eureka client written in python. Support registering your python component to Eureka Server, as well as calling remote services by pulling the the Eureka registry.
MIT License
183 stars 43 forks source link

Python eureka service is getting registered deregistered in prod multiple times #71

Open RajatDudejaj opened 1 year ago

RajatDudejaj commented 1 year ago

Hi Keijack,

Nice tutorial. I am having Python and spring boot services on eureka but Python service is frequently coming in Last 1000 newly registered leases and no other service is coming. It is not getting heartbeat, may I know the reason or solution for the same? My register method

def register_eureka(should_register=True): server_host = 'xyz.com' eureka_url = 'https://xyz.com/' homePageUrl = 'https://' + server_host healthCheckUrl = 'https://' + server_host + '/healthCheck' eureka_client.init(eureka_server=eureka_url, app_name='AppName', zone='zone1', instance_host=server_host, instance_secure_port_enabled=True, instance_unsecure_port_enabled=False, instance_secure_port=443, home_page_url=homePageUrl, status_page_url=healthCheckUrl, health_check_url=healthCheckUrl, ha_strategy=eureka_client.HA_STRATEGY_RANDOM, instance_port=8080, should_register=should_register)

My method to get service from eureka:

def getUpInstancesFromEureka(serviceName):

# register_eureka(should_register=False) # this wont not register eureka everytime we call this method
client = eureka_client.get_client()
app = client.applications.get_application(serviceName)
up_instances = app.up_instances
#up_instances_same_zone = app.up_instances_in_zone(client.zone)
#up_instances_other_zone = app.up_instances_not_in_zone(client.zone)
print("Following instances are UP:")
for instance in up_instances:
    print(instance.hostName)

if len(up_instances) < 1:
    raise Exception("No eureka instances UP for service --> " + serviceName)

instanceIndex = random.randint(0,len(up_instances) - 1)
print("Selecting instance --> " + up_instances[instanceIndex].hostName)

url = 'https://' + up_instances[instanceIndex].hostName
return url