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
184 stars 43 forks source link

Eureka Client Is not reconnecting to Eureka Server after failure #32

Closed AlexBatt closed 3 years ago

AlexBatt commented 3 years ago

Hi, I'm trying to integrate python eureka client. I have a very simple python app with Flast webserver and uWSGI app server inside a docker container with Eureka server and other services . I've applied the suggested setup and it seems to be working. i.e. when python app is able to connect from the first attempt to Eureka server, every thing works very well. But when I restart my server using docker-compose, and all services come up the eureka service comes behind the python service, and the python service fails to connect to eureka. I've tried to use @retry with eureka_client.init(...) but it didn't work. can you please suggest a way for the python eureka client to retry connections to eureka server until the eureka server is up?

in logs i see the following error: Traceback (most recent call last): File "run.py", line 6, in 9090) File "./EurekaClient.py", line 13, in init init = eureka_client.init(eureka_server=eureka_server_url, app_name=app_name, instance_port=server_port) File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/py_eureka_client/eureka_client.py", line 1175, in init ha_strategy=ha_strategy) File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/py_eureka_client/eureka_client.py", line 1114, in init_discovery_client cli.start() File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/py_eureka_client/eureka_client.py", line 1098, in start [2020-09-21 16:03:41]-[EurekaClient]-[line:98] -WARNING: Eureka server [http://eureka:9090/eureka/] is down, use next url to try. self.pull_full_registry() File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/py_eureka_client/eureka_client.py", line 881, in pull_full_registry self.try_all_eureka_server(do_pull) File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/py_eureka_client/eureka_client.py", line 875, in try_all_eureka_server raise http_client.URLError("All eureka servers are down!") urllib.error.URLError: <urlopen error All eureka servers are down!> unable to load app 0 (mountpoint='') (callable not found or import error)

My Code: class EurekaClient:

def __init__(self, eureka_server_url, app_name, server_port):
      init = eureka_client.init(eureka_server=eureka_server_url, app_name=app_name, instance_port=server_port)

business code: app.py @app.route("/trigger") def trigger(): try: res = eureka_client.do_service("MY-SERVICE", "/python/") print("result of MY-SERVICE service: " + res) return res except: e = sys.exc_info()[0] print(e)

Thanks in advance, your help would be very much appriciated.

Thanks, Alex

AlexBatt commented 3 years ago

done some more digging: when the application is able to register to eureka I see in logs: DEBUG: sending heart beat to spring cloud server DEBUG: heartbeat url::http://eureka:9090/eureka/apps/AF-PYTHON-SERVICE/172.18.0.13%3Aaf-python-service%3A9090/status?value=UP&lastDirtyTimestamp=1600716333468 DEBUG: delta got: v.13::UP7

when the application fails to register: -DEBUG: sending heart beat to spring cloud server -DEBUG: heartbeat url::http://eureka:9090/eureka/apps/AF-PYTHON-SERVICE/172.18.0.10%3Aaf-python-service%3A9090/status?value=UP&lastDirtyTimestamp=1600717216172

when trying to access the url i get the following response: (attached Screenshot 2020-09-21 225959 )

all the data is present but it fails to register, I don't see any differences between successful and unsuccessful responses.

keijack commented 3 years ago

I am sorry response late. It seems you are using the code in the main brunch? But not in Pypi ? It should try to do the register after the status update error. If you want to do a retry, you should stop the client first:

cli = eureka_client.get_client()
cli.stop()
eureka_client.init(...)
AlexBatt commented 3 years ago

thanks for you response, I'll try the retry, can you please elaborate, what do you mean by "It seems you are using the code in the main brunch? But not in Pypi ?", in my requirements.txt file I use py_eureka_client==0.7.8, am I missing anything?

keijack commented 3 years ago

I‘m sorry, I just made a mistake, in the new code, I merged the RegistryClient and DiscoveryClient into EurekaClient, just like the filename in your code. I will check it this problem later, quit busy these days.

AlexBatt commented 3 years ago

is there any previous version that worked, that i can use for now?

keijack commented 3 years ago

I'm sorry, I think the previous version may have the same problem.

keijack commented 3 years ago

The problem is that I didn't catch the pull delta exception and that the discovery timer is stopped when the eureka server is done. I have fixed it and please upgrade to 0.7.9 to make it work.

AlexBatt commented 3 years ago

The issue is resolved, thank you for your quick response. great feature!!!