I have two micro services registered with eureka server. one is in python flask called dashboard service and another in spring boot called controller service. i want to call spring boot micro service from python micro service using service name.
my python code is
config.py
eureka_client.init_registry_client(eureka_server= <eurekaServer>,
app_name="dashboard-service",
instance_port=<port>)
routes.py
@cache.route("/get_data", methods=['POST'])
@cross_origin()
def get_data():
try:
data = request.get_json()
headers = request.headers
url = "http://controller-service/data"
response = requests.post(url, json=data, headers=headers)
logger.info(res)
return res.json()
except Exception as e:
logger.exception(e)
logger.debug(traceback.format_exc())
return None
url = "http://controller-service/data", i gave this as url because in spring boot i saw that this url is wokring to call other micro service without mentioning ip and port. but form python flask i am not able to call the service.
in spring boot it was working with
url = "http://controller-service/data"
restTemplate.getForObject("http://controller-service/data")
i am new to python and flask so please help on how to call another micro service from py eureka client using eureka registered client service name
you should eureka_client, to visit the Java service. Just like you visit other components in Java using RestTemplate but not HTTPClient. In Python, you should use the functions provided by the library, but not the raw urllib.
import py_eureka_client.eureka_client as eureka_client
try:
res = eureka_client.do_service("controller-service", "/data")
print("result of other service" + res)
except urllib.request.HTTPError as e:
# If all nodes are down, a `HTTPError` will raise.
print(e)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With