spring-cloud / spring-cloud-gateway

An API Gateway built on Spring Framework and Spring Boot providing routing and more.
http://cloud.spring.io
Apache License 2.0
4.53k stars 3.33k forks source link

DiscoveryClientRouteDefinitionLocator cannot find proper service when use metadata in Path Predicate #1299

Open JasonHao123 opened 5 years ago

JasonHao123 commented 5 years ago

I'm using spring-cloud-gateway to dynamically redirect to services registered in consul, but in my case, the same serviceId may have different tags for different instance. For example: service ID: user-service instance1 Tags: version: 1.0 instance2 Tags: version: 1.1

my spring cloud configuration looks like: predicates:

But I DiscoveryClientRouteDefinitionLocator Line 100
.map(instances -> instances.get(0)).filter(includePredicate) So only one version works, need take metadata into consideration. Further more, even have different RouteDefinition for different version, gateway can load service, but cannot locate correct version, I guess that is because DiscoveryClient will return all instances according serviceId.

ryanjbaxter commented 5 years ago

This seems similar too https://github.com/spring-cloud/spring-cloud-commons/pull/172.

We would probably need to enhance the DiscoveryClient interface to make this work.