我没有eureka、负载均衡器等等。我想对运行后端实例的URI列表的请求进行负载平衡。
spring:
cloud:
gateway:
routes:
- id: myService-endpoints
uri: myServiceIp1, myServiceIp2
predicates:
- Path=/myservice/**
myServiceIp1和myServiceIp2是我的后端服务IP。在这种情况下,我如何实现负载平衡?
如果您不使用服务注册表,您仍然可以在应用程序中使用负载平衡。您只需要使用SimpleDiscoveryClient
,它允许您通过属性文件设置服务实例URI,如下所示:
spring.cloud.discovery.client.simple.instances.service1[0].uri=http://s11:8080
然后,您可以按照指南在Gateway中设置负载平衡路线,如下所示:
spring:
cloud:
gateway:
routes:
- id: myRoute
uri: lb://service
predicates:
- Path=/service/**