Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When the request comes, how does RouteDefinition convert to Route #1

Open
Maybrittnelson opened this issue Feb 28, 2019 · 3 comments
Open

Comments

@Maybrittnelson
Copy link
Owner

Maybrittnelson commented Feb 28, 2019

	@Override
	public Mono<Void> handle(ServerWebExchange exchange) {
		if (this.handlerMappings == null) {
			return createNotFoundError();
		}
		return Flux.fromIterable(this.handlerMappings)
				.concatMap(mapping -> mapping.getHandler(exchange))//1 
				.next()
				.switchIfEmpty(createNotFoundError())
				.flatMap(handler -> invokeHandler(exchange, handler))//2
				.flatMap(result -> handleResult(exchange, result));
	}
@Maybrittnelson
Copy link
Owner Author

Maybrittnelson commented Mar 5, 2019

getHandler

  1. org.springframework.web.reactive.DispatcherHandler#handle
  2. org.springframework.web.reactive.handler.AbstractHandlerMapping#getHandler
  3. org.springframework.cloud.gateway.handler.RoutePredicateHandlerMapping#getHandlerInternal
  4. org.springframework.cloud.gateway.handler.RoutePredicateHandlerMapping#lookupRoute
exchange.getAttributes().put(GATEWAY_PREDICATE_ROUTE_ATTR, r.getId());
  1. CachingRouteLocator.getRoutes->CachingRouteLocator.delegate.getRoutes
//为什么是CachingRouteLocator  @Primary
	@Bean
	@Primary
	//TODO: property to disable composite?
	public RouteLocator cachedCompositeRouteLocator(List<RouteLocator> routeLocators) {
		return new CachingRouteLocator(new CompositeRouteLocator(Flux.fromIterable(routeLocators)));
	}
	
	@Bean
	public RoutePredicateHandlerMapping routePredicateHandlerMapping(
			FilteringWebHandler webHandler, **RouteLocator routeLocator**,
			GlobalCorsProperties globalCorsProperties, Environment environment) {
		return new RoutePredicateHandlerMapping(webHandler, routeLocator,
				globalCorsProperties, environment);
	}
  1. CompositeRouteLocator.getRoutes
  2. RouteDefinitionRouteLocator.getRoutes->routeDefinitionLocator
  3. DiscoveryClientRouteDefinitionLocator.getRouteDefinitions
  4. PropertiesRouteDefinitionLocator.getRouteDefinitions
  5. RouteDefinitionRepository.getRouteDefinitions(InMemoryRouteDefinitionRepository)

@Maybrittnelson
Copy link
Owner Author

Maybrittnelson commented Mar 5, 2019

invokeHandler

  1. org.springframework.web.reactive.DispatcherHandler#invokeHandler
  2. org.springframework.web.reactive.result.SimpleHandlerAdapter#handle
  3. org.springframework.cloud.gateway.handler.FilteringWebHandler#handle
Route route = exchange.getRequiredAttribute(GATEWAY_ROUTE_ATTR);

@Maybrittnelson
Copy link
Owner Author

Maybrittnelson commented Mar 5, 2019

补充rxjava,predicate的具体过程

  1. concatmap
  2. return r.getPredicate().apply(exchange);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant