spring-cloud / spring-cloud/spring-cloud-gateway
DiscoveryClientRouteDefinitionLocator cannot find proper service when use metadata in Path Predicate
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 4.9k
- Forks
- 3.5k
- Avg merge
- 20h 57m
- Merged PRs (30d)
- 8
Description
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:
- Path='/'+serviceId+'/'+metadata['version']+'/**'
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading DiscoveryClientRouteDefinitionLocator around line 100 and trace how instances are selected before includePredicate is applied. Use the stated Consul setup with multiple instances of user-service and different version tags to inspect route selection. Done means separate metadata-based Path Predicate routes locate the matching service instance rather than only the first instance returned.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100