spring-cloud / spring-cloud-netflix

Integration with Netflix OSS components
http://cloud.spring.io/spring-cloud-netflix/
Apache License 2.0
4.87k stars 2.44k forks source link

Zuul routes cannot be changed dynamically from "url" to "serviceId" #706

Closed aivans closed 6 years ago

aivans commented 8 years ago

I noticed that it is possible to edit routes via Spring cloud Config (or by changing the yml directly) with the same type url, but it is not possible to change the route to point to a service VIP

Scenario:

zuul:
ignored-services: "*"
  routes:
    echo3:
      path: /echo3/**
      url: http://www.aaa.com
zuul:
ignored-services: "*"
  routes:
    echo3:
      path: /echo3/**
      serviceId: echo-service
aivans commented 8 years ago

It worked when adding this code to a configuration class. The idea is to have the ZuulProperties bean with @RefreshScope

    @Bean(name="zuul.CONFIGURATION_PROPERTIES")
    @RefreshScope
    @ConfigurationProperties("zuul")
    public ZuulProperties zuulProperties() {
        return new ZuulProperties();
    }
rohitghatol commented 8 years ago

Hi

I followed your comment about ZuulProperites. Are you trying to say with the changes you mentioned in the comments the routes gets deleted dynamically?

I tried with the following code but to no effect, by routes are not getting deleted dynamically. I do see the log after I deleted route2

2016-03-01 00:48:12.648 INFO 8900 --- [MOQVri6LhXrwQ-1] o.s.cloud.bus.event.RefreshListener : Received remote refresh request. Keys refreshed [spring.cloud.client.hostname, zuul.routes.route2.url, zuul.routes.route2.path]

Before:


zuul:
  ignoredServices: "*"
  routes:
    route2:
      path: /r2
      url: https://api.github.com/users/rohitghatol/repos
    route3:
      path: /r3
      url: https://api.github.com/users/rohitghatol/repos

After:

zuul:
  ignoredServices: "*"
  routes:
    route3:
      path: /r3
      url: https://api.github.com/users/rohitghatol/repos

Code


@SpringBootApplication
@EnableAutoConfiguration
@EnableZuulProxy
@EnableConfigurationProperties({ZuulProperties.class})
public class ApiGatewayServiceApplication {

  @Bean(name = "zuul.CONFIGURATION_PROPERTIES")
  @RefreshScope
  @ConfigurationProperties("zuul")
  public ZuulProperties zuulProperties() {
    System.out.println("======> Called");
    return new ZuulProperties();
  }

  public static void main(String[] args) {
    SpringApplication.run(ApiGatewayServiceApplication.class, args);
  }
}

Also I don't see ======> Called getting printed, so looks like my ZuulProperties bean is not getting called.

aivans commented 8 years ago

@rohitghatol I have to remember what I did. Too many things happened since I tested.

can you try to initialize zuulProperties() in a different Configuration class?:

@Configuration
public class ApiGatewayConfiguration {

    @Bean(name="zuul.CONFIGURATION_PROPERTIES")
    @RefreshScope
    @ConfigurationProperties("zuul")
    public ZuulProperties zuulProperties() {
        return new ZuulProperties();
    }

}
freedombird9 commented 8 years ago

@aivans The above code worked for me! Thanks for sharing.

aivans commented 8 years ago

@freedombird9 welcome

damozhiying commented 8 years ago

@aivans can you offer a demo in github,my local app can't work

ghost commented 8 years ago

APPLICATION FAILED TO START


Description:

Field zuulProperties in org.springframework.cloud.netflix.zuul.ZuulConfiguration required a single bean, but 2 were found:

Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

spencergibb commented 8 years ago

@Syy0n that had nothing to do with this issue

reddynr commented 7 years ago

Hi All,

I used Zuul to implement gateway for single service is working fine. I want to update some parameter in zuul property dynamically. here is my application.properties .Please advice. Thanks

zuul.routes.Myform.path=/MyApp/form/api/v1/{CountryCode}/forms/** zuul.routes.Myform.url=http://${server.ip}:Prort/MyApp/form/api/v1/{CountryCode}/forms

thirunar commented 7 years ago

@spencergibb zuul.routes.Myform.path=/MyApp/form/api/v1/{CountryCode}/forms/** zuul.routes.Myform.url=http://${server.ip}:Prort/MyApp/form/api/v1/{CountryCode}/forms

Can we do this? Is this feature got implemented?

ryanjbaxter commented 7 years ago

The issue is still open so this feature has not been implemented

ghoddg commented 6 years ago

Can you please share, How we need to configure the routes in spring cloud config to get update it in gateway dynamically? I am using spring cloud config with JDBC backend.

My requirement is, I want to add/update the routes dynamically using spring cloud config. (I have spring cloud config with JDBC backend and API Gateway with zuul) Please help.

ryanjbaxter commented 6 years ago

@ghoddg your question is different please open a separate issue, or post a question on StackOverflow, or reach out to us on Gitter.

marcingrzejszczak commented 6 years ago

Use the workaround suggested by @aivans