All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alibaba.boot.dubbo.DubboRouteLocator Maven / Gradle / Ivy

There is a newer version: 1.5.33
Show newest version
package com.alibaba.boot.dubbo;

import com.alibaba.boot.dubbo.discovery.DubboDiscoveryClient;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.cloud.netflix.zuul.filters.discovery.DiscoveryClientRouteLocator;

import java.util.LinkedHashMap;
import java.util.List;

/**
 * Created by wuyu on 2017/4/21.
 */
public class DubboRouteLocator extends DiscoveryClientRouteLocator {

    private DubboDiscoveryClient dubboDiscoveryClient;

    private ZuulProperties zuulProperties;

    public DubboRouteLocator(String servletPath, DiscoveryClient discovery, DubboDiscoveryClient dubboDiscoveryClient, ZuulProperties zuulProperties) {
        super(servletPath, discovery, zuulProperties);
        this.dubboDiscoveryClient = dubboDiscoveryClient;
        this.zuulProperties = zuulProperties;
    }

    @Override
    protected LinkedHashMap locateRoutes() {
        LinkedHashMap zuulRouteLinkedHashMap = super.locateRoutes();
        for (String service : dubboDiscoveryClient.getServices()) {
            List instances = dubboDiscoveryClient.getInstances(service);
            for (ServiceInstance instance : instances) {
                ZuulProperties.ZuulRoute route = new ZuulProperties.ZuulRoute(instance.getServiceId(),
                        "/" + instance.getServiceId() + "/**",
                        instance.getServiceId(),
                        instance.getUri().toString(),
                        zuulProperties.isStripPrefix(),
                        zuulProperties.getRetryable(),
                        zuulProperties.getIgnoredHeaders());
                zuulRouteLinkedHashMap.put(instance.getServiceId(), route);
            }
        }
        return zuulRouteLinkedHashMap;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy