Zuul2.1 sample程序启动篇

article/2025/9/22 6:46:23

Zuul2.1 sample程序启动篇

  • 问题
  • UML
  • 解决

问题

不使用AWS环境,Zuul2.1的sample程序是无法启动的。报错如下:

WARN  com.netflix.discovery.internal.util.Archaius1Utils [main] Cannot find the properties specified : eureka-client. This may be okay if there are other environment specific properties or the configuration is installed with a different mechanism.
WARN  com.netflix.discovery.internal.util.Archaius1Utils [main] Cannot find the properties specified : eureka-client. This may be okay if there are other environment specific properties or the configuration is installed with a different mechanism.
WARN  com.netflix.appinfo.AmazonInfo$Builder [main] Skipping the rest of AmazonInfo init as we were not able to load instanceId after the configured number of retries: 3, per fail fast configuration: true
INFO  com.netflix.appinfo.RefreshableAmazonInfoProvider [main] Datacenter is: Amazon

分析一下源码,eureka支持三种数据中心:Netflix、Amazon和MyOwn。
BaseServerStartup类使用google inject实现依赖注入。
BaseServerStartup依赖ServerStatusManager和ApplicationInfoManager。

    @Injectpublic ServerStatusManager(ApplicationInfoManager applicationInfoManager, DiscoveryClient discoveryClient) {}@Injectpublic ApplicationInfoManager(EurekaInstanceConfig config, InstanceInfo instanceInfo, OptionalArgs optionalArgs) {}

ApplicationInfoManager依赖EurekaInstanceConfig接口的实现。

@ImplementedBy(CloudInstanceConfig.class)
public interface EurekaInstanceConfig { }@Singleton
@ProvidedBy(CloudInstanceConfigProvider.class)
public class CloudInstanceConfig extends PropertiesInstanceConfig implements RefreshableInstanceConfig {public CloudInstanceConfig(String namespace) {this(namespace, new Archaius1AmazonInfoConfig(namespace), null, true);}    
}public class RefreshableAmazonInfoProvider implements Provider<AmazonInfo> {private static AmazonInfo init(AmazonInfoConfig amazonInfoConfig, FallbackAddressProvider fallbackAddressProvider) {AmazonInfo info;try {info = AmazonInfo.Builder.newBuilder().withAmazonInfoConfig(amazonInfoConfig).autoBuild(amazonInfoConfig.getNamespace());logger.info("Datacenter is: {}", DataCenterInfo.Name.Amazon);} catch (Throwable e) {logger.error("Cannot initialize amazon info :", e);throw new RuntimeException(e);}......}
}

所以,官方的sample程序,必须使用AWS环境。

没有AWS环境怎么办呢?

UML

Alt

解决

public class LSBootStrap {private static Logger logger = Logger.getLogger(LSBootStrap.class);public static void main(String[] args) {new LSBootStrap().start();}public void start() {logger.info("Leishu Zuul Sample: starting up.");long startTime = System.currentTimeMillis();int exitCode = 0;Server server = null;try {ConfigurationManager.loadCascadedPropertiesFromResources("leishu");Injector injector = InjectorBuilder.fromModule(new LSZuulModule()).createInjector();BaseServerStartup serverStartup = injector.getInstance(BaseServerStartup.class);server = serverStartup.server();long startupDuration = System.currentTimeMillis() - startTime;logger.info("Zuul Sample: finished startup. Duration = " + startupDuration + " ms");server.start(true);} catch (Throwable t) {logger.error("###############");logger.error("Zuul Sample: initialization failed. Forcing shutdown now.", t);logger.error("###############");exitCode = 1;} finally {// server shutdownif (server != null) server.stop();System.exit(exitCode);}}
}public class LSZuulModule extends ZuulSampleModule {@Overrideprotected void configure() {//DataCenterInfobind(EurekaInstanceConfig.class).toProvider(MyDataCenterInstanceConfigProvider.class).in(Scopes.SINGLETON);super.configure();}
}
eureka.registration.enabled = false## configuration related to reaching the eureka servers
eureka.preferSameZone = true
eureka.shouldUseDns = falseeureka.serviceUrl.default = http://localhost:8761/eureka# Loading Filters
zuul.filters.root = src/main/groovy/com/netflix/zuul/sample/filters
zuul.filters.locations = ${zuul.filters.root}/inbound,${zuul.filters.root}/outbound,${zuul.filters.root}/endpoint
zuul.filters.packages = com.netflix.zuul.filters.commonapi.ribbon.NIWSServerListClassName = com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList
api.ribbon.DeploymentContextBasedVipAddresses = 192.168.100.232:7001

这样,就可以使用MyOwn类型的数据中心了。
此时,注入ApplicationInfoManager的时候,config是null,instanceInfo就是MyDataCenterInstanceConfig的实例了。
看日志,启动正常。

INFO  com.netflix.discovery.DiscoveryClient [main] Getting all instance registry info from the eureka server
INFO  com.netflix.discovery.DiscoveryClient [main] The response status is 200WARN  com.netflix.zuul.netty.server.BaseServerStartup [main] Configured port: 7001
INFO  ls.sample.LSBootStrap [main] Zuul Sample: finished startup. Duration = 3475 ms
WARN  com.netflix.zuul.netty.server.Server [main] Proxy listening with TCP transport using NIO
INFO  com.netflix.zuul.netty.server.Server [main] Binding to port: 7001

http://chatgpt.dhexx.cn/article/jbFBUJqv.shtml

相关文章

API Gateways – An Evaluation of Zuul 2

https://www.novatec-gmbh.de/en/blog/api-gateways-an-evaluation-of-zuul-2/ API Gateways – also known as Edge Service – are a fundamental part of a cloud-native microservice architecture. They represent the central access point for all requests for the bac…

Netflix正式开源其API网关Zuul 2--转

微信公众号&#xff1a;聊聊架构 5 月 21 日&#xff0c;Netflix 在其官方博客上宣布正式开源微服务网关组件 Zuul 2。Netflix 公司是微服务界的楷模&#xff0c;他们有大规模生产级微服务的成功应用案例&#xff0c;也开源了相当多的微服务组件&#xff08;详见 GitHub 主页&a…

Netflix正式开源其API网关Zuul 2

5 月 21 日&#xff0c;Netflix 在其官方博客上宣布正式开源微服务网关组件 Zuul 2。Netflix 公司是微服务界的楷模&#xff0c;他们有大规模生产级微服务的成功应用案例&#xff0c;也开源了相当多的微服务组件&#xff08;详见 GitHub 主页&#xff09;&#xff0c;受到了业内…

Zuul 2是如何动态加载Filter的?

Zuul 2沿用了Zuul 1的责任链模式的设计&#xff0c;其网关核心功能还是通过Filter链来实现的。要熟练使用和扩展Zuul 2的功能&#xff0c;必须要了解其Filter的加载和执行机制。另外&#xff0c;Zuul 2使用Guice作为依赖注入工具&#xff0c;因此在开始分析之前&#xff0c;我们…

Zuul2.1文档

Zuul2.1文档 What is Zuul?Why did we build Zuul?How We Use Zuul At NetflixGetting Started 2.0How It Works 2.0Architectural OverviewFilters Server ConfigurationServer ModesHTTPHTTP/2Mutual TLS FiltersIncomingEndpointOutgoingAsyncExtracting Body ContentUsef…

【微服务网关Zuul2】网关Zuul原理与实战

一、参考资料 Spring Cloud Netflix Zuul官方文档翻译 — Jbonehttps://jbone.cn/translate/spring-cloud-netflix-zuul/Spring Cloud Netflixhttps://docs.spring.io/spring-cloud-netflix/docs/2.2.9.RELEASE/reference/html/#router-and-filter-zuul

Zuul2 的 线程模型

Zuul2 的 线程模型 转自&#xff1a;https://www.jianshu.com/p/cb413fec1632 Zuul 2相对zuul 1 由同步改进为异步机制&#xff0c;没有了同步阻塞&#xff0c;全部基于事件驱动模型编程&#xff0c;线程模型也变得简单。 zuul做为一个网关接受客户端的请求–服务端&#xf…

Spring Cloud Gateway VS Netflix Zuul2

最近公司要引入统一网关&#xff0c;自己也参与调研了几种&#xff0c;当在研究Netflix的Zuul2和SpringCloudGateway时被网络上杂七杂八的材料跟震惊了&#xff0c;不客气地说很多国内博客都是在误人子弟&#xff0c;充斥着那些基于SpringCloud全家桶号称自己使用的是zuul2的“…

Zuul1和Zuul2该如何选择?

介绍 在今年5月中&#xff0c;Netflix终于开源了它的支持异步调用模式的Zuul网关2.0版本&#xff0c;真可谓千呼万唤始出来。从Netflix的官方博文[附录1]中&#xff0c;我们获得的信息也比较令人振奋&#xff1a; The Cloud Gateway team at Netflix runs and operates more t…

Zuul 2: Netflix的异步、无阻塞系统之旅

作者: Netflix Technology Blog 译者: java达人 来源: https://medium.com/netflix-techblog/zuul-2-the-netflix-journey-to-asynchronous-non-blocking-systems-45947377fb5c Zuul 2和它的“前辈”做了同样的事情—充当Netflix服务器基础设施的前门&#xff0c;处理来自全…

微服务架构:Zuul 1.0 和 2.0 我们该如何选择?

作者&#xff1a;架构师杨波 来源&#xff1a;波波微课 在今年5月中&#xff0c;Netflix终于开源了它的支持异步调用模式的Zuul网关2.0版本&#xff0c;真可谓千呼万唤始出来。从Netflix的官方博文[附录1]中&#xff0c;我们获得的信息也比较令人振奋&#xff1a; The Cloud Ga…

Zuul2核心架构

Zuul2的核心架构就是就是两大体系&#xff0c;netty体系和filter体系。 1 Netty体系 Zuul2底层采用Netty的事件响应模式&#xff0c;要掌握zuul2就必须先要掌握Netty。 1.1 Channel、Event、EventLoop、EventLoopGroup、ChannelHandler Channel&#xff1a;每一次通信就会启…

【Zuul2】网关Zuul控制台DashBoard

目录 一、需求背景 二、实现方案 一、源码获取 二、源码分析 三、效果展示 三、相关问题 一、需求背景 用JAVA为开发语言的流控网关主要分为以下三种&#xff1a; Netflix Zuul/Zuul2Spring Cloud GateWayAlibaba Sentinel 从定位上来看&#xff0c;Zuul2与SpringClou…

【Zuul2】Zuul2网关介绍及案例(非spring集成)

目录 一.使用缘由 二.项目介绍 1.核心内容 (1)三种过滤器 Inbound、Endpoint 、Outbound (2)配置文件application.properties (3)动态配置application.properties 2.参考文档 一.使用缘由 公司需要在springcloudgateway和zuul2间做一次较为完整的调研对比&#xff0c;…

time_t c语言 2038,什么是2038问题?

什么是2038问题 不知道你有没有听过2038问题?无论你是否听过,本文将带你认识什么是2038问题。 Unix时间戳 定义为从格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数。 而在C语言中,常用time_t来表示。举个例子: #include #in…

MySQL的时间戳2038年问题还有16年,最好在设计上的时候使用datetime就可以了,不要使用时间戳字段了,即使用了也不要用int类型进行映射,使用long类型映射即可

目录 前言1&#xff0c;关于MySQL时间戳的2038年BUG2&#xff0c;使用Docker创建MySQL 模拟下3&#xff0c;总结 前言 本文的原文连接是: https://blog.csdn.net/freewebsys/article/details/127455169 未经博主允许不得转载。 博主CSDN地址是&#xff1a;https://blog.csdn.n…

计算机为什么不用三十二进制,32位进制导致2038年问题

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 在计算机应用上,2038年问题可能会导致某些软件在2038年无法正常工作。所有使用UNIX时 间表示时间的程序都将受其影响,因为它们以自1970年1月1日经过的秒数(忽略闰秒)来表示时间。 这种时间表示法在类Unix(Unix-like)操作系统上是…

2038年问题 linux内核5.6,Linux Kernel 5.6 开发者已率先做好准备 应对 2038 年问题

新十年伊始&#xff0c;Linux Kernel 5.6的开发者已经准备好着手解决将在下一个十年到来的2038年问题(又称“Y2038”或“Unix Y2K”问题)。Linux 5.6也成为第一个为32位系统准备运行到2038年之后的主线内核。 2038年问题与千年虫问题类似&#xff0c;它可能会导致某些软件在203…

mysql 2038年问题_时间戳(UnixTimestamp)与 《2038年问题》

时间戳是从格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数。 现在时间戳的长度是十位(1435113975--2015/6/24 10:46:15)。 要到 2286/11/21 01:46:40 才会变成11位(10000000000)&#xff0c;距离现在还有 271年。 不同时区获取的…

2038年问题 linux内核5.6,Linux Kernel 5.6 开发者已准备好应对 2038 年问题

2038 年问题与千年虫问题类似&#xff0c;它可能会导致某些软件在 2038 年 1 月 19 日 3 时 14 分 07 秒之后无法正常工作。届时&#xff0c;在大部分 32 位操作系统上&#xff0c;依据 “time_t” 标准&#xff0c;时间将会“绕回”且在内部被表示为一个负数&#xff0c;并造成…