springboot 集成 zookeeper 问题记录

springboot 集成 zookeeper 问题记录

环境

springboot - 2.7.8

dubbo - 3.1.11

dubbo-dependencies-zookeeper-curator5 - 3.1.11

模拟真实环境,将 windows 上的 zookeeper 迁移到虚拟机 linux 的 docker 环境

failed to connect to zookeeper server

迁移到 linux 环境,突然出现连不上 zookeeper 的问题,springboot 报错

Caused by: java.lang.IllegalStateException: failed to connect to zookeeper serverat org.apache.dubbo.registry.zookeeper.util.CuratorFrameworkUtils.buildCuratorFramework(CuratorFrameworkUtils.java:100)at org.apache.dubbo.registry.zookeeper.ZookeeperServiceDiscovery.<init>(ZookeeperServiceDiscovery.java:82)... 74 more

猜测一

首先怀疑是 linux 上 docker 环境的 zookeeper 的问题,于是主机使用 zookeeper 的 zkCli.cmd 连接 docker 上的 zookeeper

zkCli.cmd -server 192.168.x.x

结果连接服务端成功,所以 zookeeper 端没有问题

猜测二

那么问题应该出现在配置上了,因为之前都在本机是没有问题的,并且在本机用客户端去连接 docker 上的 zookeeper 时,响应会有一点慢。于是增加了 dubbo 中的配置超时时间,这样应该就万事大吉了

dubbo:registry:address: zookeeper://${zookeeper.address:192.168.61.80}:2181timeout: 60000 # 增加这个超时时间

然而,并没有什么用

猜测三

经验法无法解决,只能老老实实的根据报错堆栈信息定位报错位置

CuratorFramework curatorFramework = builder.build(); # 构造curatorFramework.start(); # 启动
curatorFramework.blockUntilConnected(BLOCK_UNTIL_CONNECTED_WAIT.getParameterValue(connectionURL),BLOCK_UNTIL_CONNECTED_UNIT.getParameterValue(connectionURL)); # 阻塞直至连接if (!curatorFramework.getState().equals(CuratorFrameworkState.STARTED)) {throw new IllegalStateException("zookeeper client initialization failed");
}    
if (!curatorFramework.getZookeeperClient().isConnected()) {throw new IllegalStateException("failed to connect to zookeeper server");
}

CuratorFramework 构造,启动,阻塞直至连接这三步里面肯定有一个有问题,最让人怀疑的是这个阻塞的步骤,于是往下 BLOCK_UNTIL_CONNECTED_WAIT 这个数据从哪里来的

/*** The enumeration for the parameters  of {@link CuratorFramework}** @see CuratorFramework* @since 2.7.5*/
public enum CuratorFrameworkParams {.../*** Wait time to block on connection to Zookeeper.*/BLOCK_UNTIL_CONNECTED_WAIT("blockUntilConnectedWait", 10, Integer::valueOf),/*** The unit of time related to blocking on connection to Zookeeper.*/BLOCK_UNTIL_CONNECTED_UNIT("blockUntilConnectedUnit", TimeUnit.SECONDS, TimeUnit::valueOf),;

明显,这个阻塞时间是 10s,我超时时间是 60 秒,结果这里 10s 就报连不上。但是这个值可以配置还是写死的?于是全局搜索关键字 blockUntilConnectedWait,发现并没有,于是我想着看看 starter 里面会不会有,这个依赖情况如下

  • dubbo-spring-boot-starter
    • dubbo-spring-boot-autoconfigure
      • dubbo-spring-boot-autoconfigure-compatible

根据 springboot 的 starter 的习惯,发现配置类 org.apache.dubbo.spring.boot.autoconfigure.DubboConfigurationProperties

@ConfigurationProperties("dubbo")
public class DubboConfigurationProperties {@NestedConfigurationPropertyprivate Config config = new Config();@NestedConfigurationPropertyprivate Scan scan = new Scan();@NestedConfigurationPropertyprivate ApplicationConfig application = new ApplicationConfig();@NestedConfigurationPropertyprivate ModuleConfig module = new ModuleConfig();@NestedConfigurationPropertyprivate RegistryConfig registry = new RegistryConfig();...
}

zookeeper 属于注册中心部分,所以继续查看 org.apache.dubbo.config.RegistryConfig

/*** RegistryConfig** @export*/
public class RegistryConfig extends AbstractConfig {public static final String NO_AVAILABLE = "N/A";private static final long serialVersionUID = 5508512956753757169L;/*** Register center address*/private String address;/*** Username to login register center*/private String username;/*** Password to login register center*/private String password;/*** Default port for register center*/private Integer port;/*** Protocol for register center*/private String protocol;/*** Network transmission type*/private String transporter;private String server;private String client;/*** Affects how traffic distributes among registries, useful when subscribing multiple registries, available options:* 1. zone-aware, a certain type of traffic always goes to one Registry according to where the traffic is originated.*/private String cluster;/*** The region where the registry belongs, usually used to isolate traffics*/private String zone;/*** The group that services registry in*/private String group;private String version;/*** Connect timeout in milliseconds for register center*/private Integer timeout;/*** Session timeout in milliseconds for register center*/private Integer session;/*** File for saving register center dynamic list*/private String file;/*** Wait time before stop*/private Integer wait;/*** Whether to check if register center is available when boot up*/private Boolean check;/*** Whether to allow dynamic service to register on the register center*/private Boolean dynamic;/*** Whether to allow exporting service on the register center*/private Boolean register;/*** Whether to allow subscribing service on the register center*/private Boolean subscribe;/*** The customized parameters*/private Map<String, String> parameters;/*** Simple the registry. both useful for provider and consumer** @since 2.7.0*/private Boolean simplified;/*** After simplify the registry, should add some parameter individually. just for provider.* <p>* such as: extra-keys = A,b,c,d** @since 2.7.0*/private String extraKeys;/*** the address work as config center or not*/private Boolean useAsConfigCenter;/*** the address work as remote metadata center or not*/private Boolean useAsMetadataCenter;/*** list of rpc protocols accepted by this registry, for example, "dubbo,rest"*/private String accepts;/*** Always use this registry first if set to true, useful when subscribe to multiple registries*/private Boolean preferred;/*** Affects traffic distribution among registries, useful when subscribe to multiple registries* Take effect only when no preferred registry is specified.*/private Integer weight;private String registerMode;private Boolean enableEmptyProtection;...
}

还是没有我们需要找的目标 blockUntilConnectedWait,但是

    /*** The customized parameters*/private Map<String, String> parameters;

这个字段看注释是自定义参数,于是试着修改一下配置

dubbo:registry:address: zookeeper://${zookeeper.address:192.168.61.80}:2181timeout: 60000 # 增加这个超时时间parameters:blockUntilConnectedWait: 60 # 单位为秒,也是可以设置的

终于项目启动成功

总结

遇到这样的问题起初还是很沮丧的,然后百度也给的那种版本不一致什么的答案,但是明显我这个是跑起来过的,于是只能自己摸索,花了大概 6 个多小时,终于成功解决这个问题,所以想着记录一下自己的解决过程

curator 是 zookeeper 的一层封装,可以理解就是 mybatis 和 mysql 的关系

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/103791.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Spring Boot中的Redis自动配置与使用

Spring Boot中的Redis自动配置与使用 Redis是一种高性能的开源内存数据库&#xff0c;常用于缓存、会话管理和消息队列等场景。Spring Boot提供了自动配置来简化在Spring应用程序中使用Redis的过程。本文将介绍Spring Boot中的Redis自动配置是什么以及如何使用它来轻松集成Red…

分权分域有啥内容?

目前的系统有什么问题&#xff1f; 现在我们的系统越来越庞大&#xff0c;可是每一个人进来的查看到的内容完全一样&#xff0c;没有办法灵活的根据不同用户展示不同的数据 例如我们有一个系统&#xff0c;期望不同权限的用户可以看到不同类型的页面&#xff0c;同一个页面不…

动态盘转换为基本盘

问题描述 不小心将磁盘0&#xff08;C和D是基本盘&#xff0c;蓝颜色&#xff09;改成了动态盘&#xff08;C和D是动态盘&#xff0c;橘黄色&#xff09;&#xff1f;如何修改回来呢&#xff1f; 解决方案&#xff1a; 使用DiskGenius将动态磁盘转换为基本磁盘 操作之前一定…

Linux友人帐之系统管理与虚拟机相关

一、虚拟机相关操作 1.1虚拟机克隆 虚拟机克隆是指将一个已经安装好的虚拟机复制出一个或多个完全相同的副本&#xff0c;包括虚拟机的配置、操作系统、应用程序等&#xff0c;从而节省安装和配置的时间和资源。 虚拟机克隆的主要用途有&#xff1a; 创建多个相同或相似的虚拟…

并发编程——1.java内存图及相关内容

这篇文章&#xff0c;我们来讲一下java的内存图及并发编程的预备内容。 首先&#xff0c;我们来看一下下面的这两段代码&#xff1a; 下面&#xff0c;我们给出上面这两段代码在运行时的内存结构图&#xff0c;如下图所示&#xff1a; 下面&#xff0c;我们来具体的讲解一下。…

CubeMX+BabyOS 使用方法

MCU&#xff1a;STM32G030F 编译器&#xff1a;MDK 托管工具&#xff1a;Sourcetree CubeMX创建工程 BabyOS克隆 添加子模块 git submodule add https://gitee.com/notrynohigh/BabyOS.git BabyOS 切换dev 分支 查看当前分支 git branch -a 切换本地分支到dev git che…

关于网络协议的若干问题(一)

1、当网络包到达一个网关的时候&#xff0c;可以通过路由表得到下一个网关的 IP 地址&#xff0c;直接通过 IP 地址找就可以了&#xff0c;为什么还要通过本地的 MAC 地址呢&#xff1f; 答&#xff1a;IP报文端到端的传输过程中&#xff0c;在没有NAT情况下&#xff0c;目的地…

【JVM系列】- 启航·JVM概论学习

启航JVM概论 &#x1f604;生命不息&#xff0c;写作不止 &#x1f525; 继续踏上学习之路&#xff0c;学之分享笔记 &#x1f44a; 总有一天我也能像各位大佬一样 &#x1f3c6; 博客首页 怒放吧德德 To记录领地 &#x1f31d;分享学习心得&#xff0c;欢迎指正&#xff0c…

open麒麟系统安装sql的经验和步骤

麒麟、QT5.9.2、mysql-5.7.37&#xff0c;编译mysql驱动 一、MySQL安装 1. 下载mysql https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz 2. 安装 安装经验&#xff1a; 我使用的qt版本是5.14.&#xff1f;&#xff1f; 忘…

ATF(TF-A)/OPTEE之动态代码分析汇总

安全之安全(security)博客目录导读 1、ASAN(AddressSanitizer)地址消毒动态代码分析 2、ATF(TF-A)之UBSAN动态代码分析 3、OPTEE之KASAN地址消毒动态代码分析

Python中使用IDLE调试程序

在IDLE中&#xff0c;使用菜单栏中的“Debug”对IDLE打开的python程序进行调试。 1 打开调试开关 选择IDLE菜单栏的“Debug->Debugger”&#xff0c;如图1①所示&#xff1b;此时在IDLE中会显示“[DEBUG ON]”&#xff0c;即“调试模式已打开”&#xff0c;如图1②所示&am…

JAVA加密算法

一、AES 高级加密标准(AES,Advanced Encryption Standard)为最常见的对称加密算法(微信小程序加密传输就是用这个加密算法的)。对称加密算法也就是加密和解密用相同的密钥&#xff0c;具体的加密流程如下: 加密&#xff1a;明文P通过AES加密函数和密匙K进行加密&#xff0c;得…

Go HTTP 调用(上)

哈喽大家好&#xff0c;我是陈明勇&#xff0c;今天分享的内容是 Go HTTP 调用。如果本文对你有帮助&#xff0c;不妨点个赞&#xff0c;如果你是 Go 语言初学者&#xff0c;不妨点个关注&#xff0c;一起成长一起进步&#xff0c;如果本文有错误的地方&#xff0c;欢迎指出&am…

数据结构八大排序Java源码

文章目录 [1]. 堆排序[2]. 冒泡排序[3]. 选择排序[4]. &#xff08;直接&#xff09;插入排序[5]. 希尔排序&#xff08;属于插入算法&#xff09;[6]. 快速排序[7]. 归并排序[8]. 基数排序 王道数据结构排序讲解 排序算法最佳时间复杂度最坏时间复杂度平均时间复杂度空间复杂度…

【ftp篇】 vsftp(ftp) 每天生成一个动态密码

这里写目录标题 前言为什么需要动态每日生成一个密码&#xff1f;编写脚本定时任务java对应的代码 前言 社长最近接到一个需求&#xff0c;需要ftp每天动态生成一个密码 为什么需要动态每日生成一个密码&#xff1f; 在软硬件通讯过程中&#xff0c;就以共享单车为例&#xff0…

vsCode 忽略 文件上传

1 无 .gitignore 文件时&#xff0c;在项目文件右键&#xff0c;Git Bash 进入命令行 输入 touch .gitignore 生成gitignore文件 2 、在文件.gitignore里输入 node_modules/ dist/ 来自于&#xff1a;vscode git提交代码忽略node_modules_老妖zZ的博客-CSDN博客

深度学习_1_基本语法

数据结构 代码&#xff1a; import torchx torch.arange(12)##产生长度为12的一维张量print(x)##X x.resize(3, 4)##被弃用##print(X)y torch.reshape(x, (3, 4))##修改向量为矩阵&#xff0c;一维变二维print(y)print(y.size())xx torch.zeros((2, 3, 4))##三维矩阵&…

GEE:基于GLDAS数据集分析土壤湿度的时间序列变化

作者:CSDN @ _养乐多_ 本篇博客将介绍如何使用Google Earth Engine(GEE)进行土壤湿度数据的分析。我们将使用NASA GLDAS(Global Land Data Assimilation System)数据集,其中包括了关于土壤湿度的信息。通过该数据集,我们将了解土壤湿度在特定区域和时间段内的变化,并生…

#力扣:2236. 判断根结点是否等于子结点之和@FDDLC

2236. 判断根结点是否等于子结点之和 一、Java /*** Definition for a binary tree node.* public class TreeNode {* int val;* TreeNode left;* TreeNode right;* TreeNode() {}* TreeNode(int val) { this.val val; }* TreeNode(int val, TreeNo…

Vue、js底层深入理解笔记(二)

1.跨域 跨域原因 > 浏览器的同源策略 属于一种保护机制 如果没有同源策略的保护 一般用来处理登录cookie、服务端验证通过后会在响应头加入Set-Cookie字段、下次再发请求的时候&#xff0c;浏览器会自动将cookie附加在HTTP请求的头字段Cookie中、也就是说跳转到其他网站你也…