其他分享
首页 > 其他分享> > spring-Zuul代理,可动态发现路线

spring-Zuul代理,可动态发现路线

作者:互联网

我有一个简单的Zuul应用,该应用在application.yml中具有一条路由以路由到我的微服务.工作正常

但是,我正在寻找一种更具动态性的解决方案,在该解决方案中,我可以通过代码或通过在构建期间通过POST到某些Zuul终结点来动态连接路由(可能使用springfox和微服务中的swagger定义).我找不到Zuul的API.

我对Eureka有所了解,这似乎是一种通过发现抽象出路由的解决方案.但是,我很好奇是否有不引入Eureka的解决方案.如果有一种在构建过程中在Zuul中连接这些路由的方法,而不必每次都编辑application.yml.

提前致谢.

解决方法:

如果您去尤里卡,这实际上可以工作.打包在Spring Cloud中的Zuul将使用其名称自动公开每个服务.因此,如果您在尤里卡(Eureka)注册了一个名为用户的服务,Zuul将默认自动创建一条路由/用户转发到实例.那将只允许简单的url结构,但应该可以解决您的问题.

有关详细信息,请参见official documentation

By convention, a service with the ID “users”, will receive requests from the proxy located at /users (with the prefix stripped). The proxy uses Ribbon to locate an instance to forward to via discovery, and all requests are executed in a hystrix command, …

标签:spring-boot,netflix-zuul,swagger,spring
来源: https://codeday.me/bug/20191111/2019705.html