Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
aivans opened this issue Dec 10, 2015 · 14 comments
Closed

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

aivans opened this issue Dec 10, 2015 · 14 comments

Comments

@aivans
Copy link

aivans commented Dec 10, 2015

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:

  • routed defined:
zuul:
ignored-services: "*"
  routes:
    echo3:
      path: /echo3/**
      url: http://www.aaa.com
  • route shows fine in /admin/routes
  • change route to
zuul:
ignored-services: "*"
  routes:
    echo3:
      path: /echo3/**
      serviceId: echo-service
  • hit /admin/refresh() endpoint. The response mentions that changes were detected about the route
  • Problem: /admin/routes still shows the old route, pointing to url
@aivans
Copy link
Author

aivans commented Dec 11, 2015

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
Copy link

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
Copy link
Author

aivans commented Mar 1, 2016

@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
Copy link

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

@aivans
Copy link
Author

aivans commented Sep 21, 2016

@freedombird9 welcome

@damozhiying
Copy link

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

@spencergibb spencergibb added this to the 1.3.0.M1 milestone Oct 18, 2016
@ghost
Copy link

ghost commented Nov 2, 2016


APPLICATION FAILED TO START


Description:

Field zuulProperties in org.springframework.cloud.netflix.zuul.ZuulConfiguration required a single bean, but 2 were found:
- zuul.CONFIGURATION_PROPERTIES: defined in BeanDefinition defined in class path resource [gateway/ApiGatewayConfiguration.class]
- zuul-org.springframework.cloud.netflix.zuul.filters.ZuulProperties: defined in null

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
Copy link
Member

@Syy0n that had nothing to do with this issue

@reddynr
Copy link

reddynr commented Nov 30, 2016

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

@ryanjbaxter ryanjbaxter modified the milestones: 1.3.0.M1, 1.3.0.RC1 Jan 27, 2017
@ryanjbaxter ryanjbaxter modified the milestones: 1.3.0.RC1, 1.3.0.RC2 Mar 16, 2017
@spencergibb spencergibb modified the milestone: 1.3.1.RELEASE May 20, 2017
@thirunar
Copy link

@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
Copy link
Contributor

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

@ghoddg
Copy link

ghoddg commented Mar 23, 2018

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
Copy link
Contributor

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

@marcingrzejszczak
Copy link
Contributor

Use the workaround suggested by @aivans

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants