Spring cloud registering multiple instances of same service - spring

I am developing a microservice, using Spring Boot, that exposes REST Endpoint. Because of scalability, I have to run multiple instances of this services on a different port. What will be the configurations for the applications so that it can register with eureka and requests are load balanced? I am using Spring cloud config, Eureka server and zuul.

Attaching following entries in the client properties file will do the trick. This is for Spring cloud config dalston
eureka.instance.instanceId=${spring.application.name}:${spri‌​ng.application.insta‌​nce_id:${random.valu‌​e}}

I guess you meant to register with Eureka instead of Config server.
To register multiple instances that might be running in the same host but listening on a different port you would need to set eureka.instance.metadataMap.instanceId to a unique value maybe using:
eureka.instance.metadataMap.instanceId=${spring.application.name}:${random.int}

Related

Is there a way to load-balance the eureka server (spring boot)

We are using spring boot with eureka for service discovery. Need to understand that Can we use multiple instance of spring boot eureka server behind the load balancer?
Yes, using peer awareness. They will synchronise with each other and you can communicate with any of the instances through the load balancer.

Spring Boot Actuator + Spring Boot Admin - Is there a way to define a custom management url?

Is there a way I can define the port for the management URLs (not the management.server.port) so that spring boot admin can identify the actuator URLs from the spring boot app for monitoring?
I'm running the spring boot app in a docker container and it's externally exposed on a different port using the Kubernetes NodePort.
If you are using service discovery for application lookup you could define the exposed management port in instance metadata. This metadata is used to build up the management URL.
More details documented here:
http://codecentric.github.io/spring-boot-admin/current/#spring-cloud-discovery-support
Handling is done in de.codecentric.boot.admin.server.cloud.discovery.DefaultServiceInstanceConverter
Example for Eureka:
eureka.instance.metadata-map.management.port=[K8S-EXPOSED-PORT]
If you are using Service Discovery, take a look into DefaultServiceInstanceConverter, try specifying the management.port property.
If you are not using Service Discovery, then take a look into de.codecentric.boot.admin.server.domain.values.Registration, you might need to use the builder apis to register your application correctly (try to set managementUrl properly). Note, you will need to do this in your client application (the one which is being monitored).

Registering Spring Cloud Microservice with Eureka server

I am trying to create spring cloud microservices and also need to include eureka server and zuul as spring cloud tools. Now I created one module in my one spring boot project. I registered that service with eureka server. And also I created one spring boot project for adding zuul service discovery and also registered with eureka project.
Here my doubt is that When I am adding another module as another spring boot project, Can I register that application also with my current eureka server as client? What type of relation that eureka server project and microservice having? one-To-One or One-To-Many? Can I register 3 or 4 microservices with one eureka server as client?
Eureka Server will let you add as many microservices (modules of spring boot projects like you said).
From Spring Cloud landing page:
As long as Spring Cloud Netflix and Eureka Core are on the classpath
any Spring Boot application with #EnableEurekaClient will try to
contact a Eureka server on http://localhost:8761 (the default value of
eureka.client.serviceUrl.defaultZone):
That means that you can use a single eureka server for multiple microservices which are registered as clients to the eureka server.
So yes, it's a One-To-Many relationship.
You will want at one point to look into multiple Eureka servers used in load balancing, for redundancy purposes, but for now you will be fine.

Load Balancing micro services using Spring cloud Netflix OSS

I have a microservice built using Spring Boot and Netflix OSS. I have used Central config server, Eureka and Zuul. Because of scalability multiple instances of the services is running on different port. All the instances are registered in Eureka but requests are going to only last registered server.
How to load balance services. Should I use ribbon in Zuul to load balance? Please let me know how to achieve load balancing on same service running on multiple instances.
If there is a code change required a snippet then please post a code snippet as well.
Application Config
spring.application.name=book-service
server.port=0
eureka.client.region = default
eureka.client.registryFetchIntervalSeconds = 5
eureka.client.serviceUrl.defaultZone=http://discUser:discPassword#localhost:10082/eureka/
#eureka.instance.metadataMap.instanceId=${spring.application.name}:${spring.application.instance_id:${random.value}}
eureka.instance.instanceId=${spring.application.name}:${spring.application.instance_id:${random.value}}
eureka.instance.leaseRenewalIntervalInSeconds=5
eureka.instance.leaseExpirationDurationInSeconds=5
Eureka Config
spring.application.name=discovery
server.port=10082
eureka.instance.hostname=localhost
eureka.client.serviceUrl.defaultZone=http://discUser:discPassword#localhost:10082/eureka/
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
spring.session.store-type=hash-map
ZUUL Config
spring.application.name=gateway
server.port=10080
eureka.client.region = default
eureka.client.registryFetchIntervalSeconds = 5
management.security.sessions=always
zuul.routes.book-service.path=/book-service/**
zuul.routes.book-service.sensitive-headers=Set-Cookie,Authorization
hystrix.command.book-service.execution.isolation.thread.timeoutInMilliseconds=600000
#zuul.routes.rating-service.path=/rating-service/**
#zuul.routes.rating-service.sensitive-headers=Set-Cookie,Authorization
#hystrix.command.rating-service.execution.isolation.thread.timeoutInMilliseconds=600000
zuul.routes.discovery.path=/discovery/**
zuul.routes.discovery.sensitive-headers=Set-Cookie,Authorization
zuul.routes.discovery.url=http://localhost:8082
hystrix.command.discovery.execution.isolation.thread.timeoutInMilliseconds=600000
logging.level.org.springframework.web.=debug
logging.level.org.springframework.security=debug
logging.level.org.springframework.cloud.netflix.zuul=debug
spring.session.store-type=hash-map
Registering application properly with Eureka will do the trick.
Below entries will uniquely register services with Eureka.
#eureka.instance.metadataMap.instanceId=${spring.application.name}:${spring.application.instance_id:${random.value}}
eureka.instance.instanceId=${spring.application.name}:${spring.application.instance_id:${random.value}}

Netflix Arcaius serving as config service for multiple Spring Boot micro-services

I'm having a problem with how to use just Netflix Archaius to work as a config server for multiple Spring Boot microservices. Previously when I applied Eureka and Spring Cloud Config Server in my multiple-services project built with Spring Boot, each microservie would get its own .properties file from the Spring Cloud Config server through the discovery function of the Eureka service. But now I need to change the Spring Cloud Config Server into a Netflix Archaius service, from which the Spring Boot microservices will get .properties file, i have no idea about how to achieve it. Is there any good idea for my reference? Thanks in advance.
Finally I gave up using Netflix Archaius to pull properties file for microservices. Instead, I wrote down required key-value-pair properties into the application.properties of each springboot microservice. Since all the springboot microservices will be deployed in the DCOS platform in the form of docker containers, some inconstant properties were configured into the marathon deployment scripts, which could be populated into the springboot applet. In this way I managed to configure the key-value-pair properties from the outside instead of being hardcoded in the program codes.

Resources