Search code examples
pythonspring-bootmicroservices

How to register python microservices with my eureka server (spring boot)


Inorder to register microservices with eureka server we need to add following config in our microservice

eureka.client.service-url.defaultZone=${DISCOVERY_URL:http://localhost:8761}/eureka/
eureka.client.service-url.instance.leaseRenewalIntervalInSeconds=1
eureka.client.service-url.instance.leaseExpirationDurationInSeconds=1

But i need to create microservice in python and to register with eureka server. So how should i achieve?

Thanks in Advance


Solution

  • Need to have REST implementation that follows Eureka-REST-operations . Below is a sample implementation that follow Eureka REST in Python.

    Refer to full documentation at Python client for Netflix Eureka

    from eureka.client import EurekaClient
    import logging
    
    logging.basicConfig()
    
    
    ec = EurekaClient("MyApplication",
                      eureka_domain_name="test.yourdomain.net",
                      region="eu-west-1",
                      vip_address="http://app.yourdomain.net/",
                      port=80,
                      secure_vip_address="https://app.yourdomain.net/",
                      secure_port=443
    )
    print ec.get_zones_from_dns()
    print ec.get_eureka_urls()
    print ec.register()
    print ec.update_status("UP")  # Or ec.register("UP")
    print ec.heartbeat()