Search in sources :

Example 1 with BaseReactorServiceInstanceLoadbalancer

use of com.hummer.doorgod.service.domain.loadbalancer.BaseReactorServiceInstanceLoadbalancer in project hummer-framework by hummer-team.

the class GlobalLoadBalancerFilter method choose.

private Mono<Response<ServiceInstance>> choose(ServerWebExchange exchange) {
    URI uri = Objects.requireNonNull(exchange.getAttribute(ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR));
    String routeId = ((Route) Objects.requireNonNull(exchange.getAttribute(ServerWebExchangeUtils.GATEWAY_ROUTE_ATTR))).getId();
    LoadBalancerConfig loadBalancerConfig = routeRepository.getLoadBalancer(routeId, () -> LoadBalancerConfig.DEFAULT);
    BaseReactorServiceInstanceLoadbalancer loadBalancer = loadbalancerMap.get(loadBalancerConfig.getLoadBalancerName());
    if (loadBalancer == null) {
        loadBalancer = loadbalancerMap.get("roundLb");
        log.debug("this service {} loadBalancerName {} invalid,use default loadBalancer `roundLb`", uri.getHost(), loadBalancerConfig.getLoadBalancerName());
    }
    return loadBalancer.tryChoose(createRequest(exchange, uri.getHost()), uri.getHost(), loadBalancerConfig);
}
Also used : BaseReactorServiceInstanceLoadbalancer(com.hummer.doorgod.service.domain.loadbalancer.BaseReactorServiceInstanceLoadbalancer) LoadBalancerConfig(com.hummer.doorgod.service.domain.configuration.LoadBalancerConfig) URI(java.net.URI) Route(org.springframework.cloud.gateway.route.Route)

Aggregations

LoadBalancerConfig (com.hummer.doorgod.service.domain.configuration.LoadBalancerConfig)1 BaseReactorServiceInstanceLoadbalancer (com.hummer.doorgod.service.domain.loadbalancer.BaseReactorServiceInstanceLoadbalancer)1 URI (java.net.URI)1 Route (org.springframework.cloud.gateway.route.Route)1