0
votes

I created a sample Spring Cloud microservice by using Eureka server and Zuul Spring Cloud tools in my local system. It runs properly. I registered my microservice as client at eureka server project. And also registered my Zuul as client at Eureka server.

The below is my Eureka server project application.properties,

server.port=8071
eureka:  
numberRegistrySyncRetries: 1
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
  defaultZone: http://localhost:8071/eureka/
server:
enable-self-preservation: true

And the below code is my microservice application.property file content,

eureka.client.serviceUrl.defaultZone=http://localhost:8071/eureka/
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true

And My zuul application.properties code is,

eureka.client.serviceUrl.defaultZone=http://localhost:8071/eureka/
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
spring.application.name=eurekaZuulClient
ribbon.eureka.enabled=true
zuul:
 routes:
  espace-service:
   path: /espace/**
   stripPrefix: true
   serviceId: espace-service
   server.port=8090

Here my doubt is that when we deploying this application into cloud, What change we need to make in application.properties?, since we don't know about server.port and "eureka.client.serviceUrl.defaultZone" at cloud.Here I only running with localhost.

So how we need to follow cloud deployment procedure in configuration? I am beginner with Spring Cloud, and I have lot of confusions in these configuration.

1
Eureka needs to be deployed to a well known host:portspencergibb
Ok. But how i set my "defaultZone" ?. I needed that domain and port number.So how I will add their domain.And also what is the process of identification of that well known port that you mentioned?Jacob
A static ip (elastic IP in aws)spencergibb

1 Answers

1
votes

Its good to have known port for Eureka, so that we can easily check the status of various APIs. There are multiple ways to handle this for cloud deployment.

You can hard code the IP of the instance where eureka is deployed and separate it with profile names.

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
---
eureka:
  client:
    serviceUrl:
      defaultZone: http://172.0.0.1:8761/eureka/

The bit of configuration under the --- delimiter is for when the application is run under the cloud Spring profile. It’s easy to set a profile using the SPRING_PROFILES_ACTIVE environment variable. You can configure Cloud Foundry environment variables in your manifest.yml or, on Cloud Foundry Lattice, your Docker file.

If hostname can’t be determined by Java, then IP address is sent to Eureka. The only explict way of setting hostname is by using eureka.instance.hostname. You can set your hostname at the runtime using environment variable, for example eureka.instance.hostname=${HOST_NAME}

eureka:
  instance:
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/