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

Comments

Projects
None yet
10 participants
@aivans

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

This comment has been minimized.

Show comment
Hide comment
@aivans

aivans 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();
    }

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

This comment has been minimized.

Show comment
Hide comment
@rohitghatol

rohitghatol Mar 1, 2016

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.

rohitghatol commented Mar 1, 2016

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

This comment has been minimized.

Show comment
Hide comment
@aivans

aivans 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();
    }

}

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

This comment has been minimized.

Show comment
Hide comment
@freedombird9

freedombird9 Sep 20, 2016

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

freedombird9 commented Sep 20, 2016

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

@aivans

This comment has been minimized.

Show comment
Hide comment
@aivans

aivans commented Sep 21, 2016

@freedombird9 welcome

@damozhiying

This comment has been minimized.

Show comment
Hide comment
@damozhiying

damozhiying Sep 28, 2016

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

damozhiying commented Sep 28, 2016

@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

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost 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

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

This comment has been minimized.

Show comment
Hide comment
@spencergibb

spencergibb Nov 2, 2016

Member

@Syy0n that had nothing to do with this issue

Member

spencergibb commented Nov 2, 2016

@Syy0n that had nothing to do with this issue

@reddynr

This comment has been minimized.

Show comment
Hide comment
@reddynr

reddynr 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

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

This comment has been minimized.

Show comment
Hide comment
@thirunar

thirunar Oct 27, 2017

@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?

thirunar commented Oct 27, 2017

@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

This comment has been minimized.

Show comment
Hide comment
@ryanjbaxter

ryanjbaxter Nov 6, 2017

Contributor

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

Contributor

ryanjbaxter commented Nov 6, 2017

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

@ghoddg

This comment has been minimized.

Show comment
Hide comment
@ghoddg

ghoddg 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.

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

This comment has been minimized.

Show comment
Hide comment
@ryanjbaxter

ryanjbaxter Mar 23, 2018

Contributor

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

Contributor

ryanjbaxter commented Mar 23, 2018

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

@marcingrzejszczak

This comment has been minimized.

Show comment
Hide comment
@marcingrzejszczak

marcingrzejszczak Sep 10, 2018

Contributor

Use the workaround suggested by @aivans

Contributor

marcingrzejszczak commented Sep 10, 2018

Use the workaround suggested by @aivans

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment