Register on eureka server on a different machine - spring

I have a microservice architecture in developement mode with an API Gateway running on localhost:8080, some services on localhost:8081...8084 and an eureka server on localhost:8761.
The services register with eureka and everything works fine on my local machine.
I'm trying to deploy the services to azure as single containers. So each service will end up with a unique url.
How can I tell my eureka clients (api gateway and services) where the eureka server is running?
No matter what I try, it will always try to find the eureka server at localhost:8761. These are my settings for the API gateway:
eureka:
instance:
instance-id: ${spring.application.name}:${random.uuid}
client:
service-url:
default-zone: ${EUREKA_HOST:http://localhost:8761}/eureka/
I always end up with this error:
How can I get the services to connect to a eureka server that runs on something like https://example.azurewebsites.net:8761 ? The variable EUREKA_HOST has the correct value since I can use it at other places without problem.

Related

Spring boot micro service Deployment

I am new to Micro services architecture.. I want know if it is required to deploy all Spring boot micro services in the same local network ..? As Eureka Discovery service uses Private/Internal IP Address for Registration , i am unable to call a services from another service deployed in different local network...
Please let me know how micro services deployed across multiple Sub nets should communicate each other in this case
or is there a way to tell eureka to use only public IP Address..?
Not sure if this would help, but by default, your eureka client will try to connect to the default localhost:8761 where the eureka discovery server should exist.
In case you have a different location for your discovery-service you can use the following in the application.properties file in your client services.
eureka.client.service-url.defaultZone=http://{address}-{port}/eureka

Fargate service discovery for eureka clients

We are planning to host our eureka discovery server in the same vpn as our fargate services. What configuration we have to provide in our client container configuration to enable them to seamlessly connect with our discovery server. The discovery server is not hosted on fargate , it is on separate EC2 machine.
You need to point the clients to the Eureka server including the following configuration on the client's application.yml:
spring:
application:
name: <client-name>
eureka:
client:
serviceUrl:
defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
The EUREKA_URI environment variable need to be set on containers with the Eureka address. The additional localhost URL allows apps run without containers on dev workstations along with a local copy of Eureka (just another boot app).

Programmatically find Eureka server host and port

I want to setup Eureka server for service registry and erueka clients that will get access rest api using the service registry from Eureka server. But we use mesos as our container management system and when we start the Eureka server we will not know which host and port it is running on. So there is an api that we can use that gives us the complete url where Eureka server will be running. Now all the examples for Eureka client that I have seen have hard coded the Eureka server in the config file. Is it possible for Eureka clients to use that api and get the url for Eureka server.
FYI: we are using spring boot and have our own DC and are not on any cloud
I think I found the answer but if someone can confirm that will be great. I need to create my own EurekaClientConfigBean and override the following methods:
public void setEurekaServiceUrlPollIntervalSeconds(int eurekaServiceUrlPollIntervalSeconds)
List<String> getEurekaServerServiceUrls(String zone);

Eureka Client register with multiple Eureka server issue

In my case want to register one microservice with multiple Eureka server from different zone.
I have tried with putting:
defaultZone: http://192.168.207.24:9002/eureka/,http://192.168.207.24:9003/eureka/
but in this case eureka client is getting registered with second one not on both.

Eureka service can not be found when running in Docker Container

So I have a very simple setup of a Eureka server and one service. When running locally with tomcat everything works perfect. However, when I run these locally in docker containers.. the service registers to the eureka server but whenever I make the http calls via FeignClient it says there is no load balance for the service (Cant find service). It acts as if the service can find the eureka server but the server can not find the service. And once again, only broken when runnind in docker containers.
My Eureka server
spring.application.name=eureka-service
server.port=8761
eureka.client.fetch-registry=false
eureka.client.register-with-eureka=false
My Service
spring.application.name=users-service
server.port=8081
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=false
eureka.instance.prefer-ip-address=true
eureka.client.service-url.defaultZone=http://**EurekaServerIp**:8761\eureka
I was able to fix it by making sure my Eureka server, Services and Zuul gateway were running on the same (Overlay) docker network. However, I now need to find a way to only make the zuul gateway accessible from outside the network, and protect all the services.
EDIT: I found a very easy way to expose gateways and hide services with docker --link, here is a good article https://exampledriven.wordpress.com/2016/06/24/spring-boot-docker-example/

Resources