Skip to content

Latest commit

 

History

History

springboot-zuul-demo

Spring cloud zuul demo


Dynamic routes

this sample is change to target url by using ZuulFilter.

DynamicZuulPathFilter

    @Override
    public Object run() throws ZuulException {
        logger.info("DynamicZuulPathFilter::run() is called");
        RequestContext context = RequestContext.getCurrentContext();
        displayRequestContext(context);

        if (isDynamicRequest(context)) {
            logger.info("RouteHost : {} --> {}", context.get(ROUTE_HOST), dynamicRouteService.getCurrentUrl());
            // getting current url
            context.put(ROUTE_HOST, dynamicRouteService.getCurrentUrl());
        }

        return null;
    }

for example,

first request & response

$ curl -XGET http://localhost:8081/dynamic
Foo

change target url(DynamicRouteController)

$ curl -XGET http://localhost:8081/dynamic-config/change
http://localhost:8081/dynamic-bar

request again

$ curl -XGET http://localhost:8081/dynamic
Bar