Search code examples
spring-bootnetflix-eurekanetflix-zuul

Delete zuul route dynamically without restarting the gateway


Hi I want to delete the zuul route which has been created dynamically. Im not using cloud server. Im able to add the routes using discoveryclientroutelocator.

But I don't find an option to de-register the route added dynamically. This deletion should happen without restarting the gateway. help.

    ZuulRoute zuulRoute = new ZuulRoute();
    zuulRoute.setId(externalapis.getServiceId());
    zuulRoute.setServiceId(externalapis.getServiceId());
    zuulRoute.setPath(externalapis.getPath());
    zuulRoute.setUrl(externalapis.getUrl());
    zuulRoute.setRetryable(true);
    discoveryClientRouteLocator.addRoute(zuulRoute);

Solution

  • I used below code to add, delete and update.It works without restarting the gateway

    Add Route:

    this.zuulProperties.getRoutes().put(externalapis.getServiceId(), zuulRoute);
    

    Delete Route:

    this.zuulProperties.getRoutes().remove(externalapis.getServiceId());
    

    Update Route:

    this.zuulProperties.getRoutes().remove(oldExternalapis.getServiceId());
    
    this.zuulProperties.getRoutes().put(newExternalapis.getServiceId(), zuulRoute);