[英]Load Balancing micro services using Spring cloud Netflix OSS
I have a microservice built using Spring Boot and Netflix OSS. 我有一个使用Spring Boot和Netflix OSS构建的微服务。 I have used Central config server, Eureka and Zuul.
我已经使用了中央配置服务器,Eureka和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.
所有实例都在Eureka中注册,但是请求仅发送到最后注册的服务器。
How to load balance services. 如何负载均衡服务。 Should I use ribbon in Zuul to load balance?
我应该在Zuul中使用色带进行负载平衡吗? 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 ZUUL配置
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. 在Eureka上正确注册应用程序将达到目的。
Below entries will uniquely register services with Eureka. 下面的条目将向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}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.