Skip to content
Advertisement

Route order in Spring Cloud Gateway

We are implementing routes programmatically using a implementation of RouteDefinitionLocator. We have two services which should register at the same route path, where one of them is meant as a fallback if the other one does not exist. The preferred route with the specific path is:

RouteDefinition{id='CompositeDiscoveryClient_ms-1400133464', predicates=[PredicateDefinition{name='Path', args={pattern=/yambas/rest/apps/*/models/ms/**}}], filters=[FilterDefinition{name='RewritePath', args={regexp=/yambas/rest/apps/(?<remaining>.*), replacement=/ms/apps/${remaining}}}], uri=lb://ms, order=0}

And the more general one, which should only fire if other route was found:

RouteDefinition{id='CompositeDiscoveryClient_yambas-1171178634', predicates=[PredicateDefinition{name='Path', args={pattern=/yambas/rest/**}}], filters=[], uri=lb://yambas, order=0}

Thus, when calling /yambas/rest/apps/bla/models/ms, the first route should be used, and when calling /yambas/rest/apps/bla/models/otherms/*, the second (fallback ) should be used.

Problem is, that even the order attribute at the route seems not to solve this; currently we find no possibility to set up this order / priority of routes. Is this intendet?

Advertisement

Answer

It seems that we set the order the wrong way – setting the lower priority route to order 1 and the higher to 0 makes it work.

@spencergibb that would be definitely worth to be mentioned in the documentation.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement