当前位置: 首页 > news >正文

沈阳网站建设建设公司哪家好岳阳网红打卡地

沈阳网站建设建设公司哪家好,岳阳网红打卡地,wordpress 媒体库 七牛,做微信扫码网站目录 ZooKeeper简单介绍 一、安装zookeeper 二、springboot整合zookeeper ZooKeeper简单介绍 zookeeper是为分布式应用程序提供的高性能协调服务。zookeeper将命名、配置管理、同步和组服务等常用服务公开在一个简单的接口中#xff0c;因此用户无需从头开始编写这些服务。可…目录 ZooKeeper简单介绍 一、安装zookeeper 二、springboot整合zookeeper ZooKeeper简单介绍 zookeeper是为分布式应用程序提供的高性能协调服务。zookeeper将命名、配置管理、同步和组服务等常用服务公开在一个简单的接口中因此用户无需从头开始编写这些服务。可以使用它来实现共识、组管理、领导者选举和存在协议。还可以在此基础上满足自己的特定需求。开始学习zookeeperzookeeper官网 zookeeper和nacos、eureka、consul都是我们常见的微服务注册中心这篇文章就详细地介绍一下springboot整合zookeeper的步骤。 一、安装zookeeper 为了方便使用zookeeper我们在windows系统上安装zookeeper。 首先需要下载zookeeper点击链接打开zookeeper官网Apache ZooKeeper在官网首页点击Getting Started下面的Download进入下载页面 选择下载稳定的版本 下载完成后解压到D盘然后打开刚刚解压的zookeeper安装目录下的config目录复制一份zoo_sample.cfg然后重命名为zoo.cfg修改里面的内容dataLogDir是新增的原来文件里没有 dataDirzookeeper的安装目录\\data dataLogDirzookeeper的安装目录\\log tickTime2000initLimit10syncLimit5clientPort2181dataDirD:\\program\\apache-zookeeper-3.7.1\\datadataLogDirD:\\program\\apache-zookeeper-3.7.1\\log 然后在安装目录下新建两个目录data和log 经过以上的步骤zookeeper就算安装完了。 启动zookeeper双击zookeeper安装目录下的zkServer.bat和zkCli.bat两个文件 二、springboot整合zookeeper 1、在IntelliJ IDEA里新建一个springboot项目命名为zookeeper 2、在项目的pom.xml文件中引入zookeeper和相关依赖 ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion2.5.9/versionrelativePath//parentgroupIdcom.example/groupIdartifactIdzookeeper/artifactIdversion0.0.1-SNAPSHOT/versionpropertiesjava.version1.8/java.version/propertiesdependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependency!--lombok--dependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactIdversion1.18.22/version/dependencydependencygroupIdorg.apache.zookeeper/groupIdartifactIdzookeeper/artifactIdversion3.7.0/version/dependencydependencygroupIdorg.apache.curator/groupIdartifactIdcurator-framework/artifactIdversion5.2.1/version/dependencydependencygroupIdorg.apache.curator/groupIdartifactIdcurator-recipes/artifactIdversion5.2.1/version/dependency/dependenciesbuildpluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactId/plugin/plugins/build /project 3、修改application.xml配置文件只需要指定项目启动端口号和zookeeper的服务器地址 server:port: 8085zookeeper:host: localhost:2181 4、项目根目录下创建config包新建一个zookeeper的配置类 package com.example.zookeeper.config;import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFrameworkFactory; import org.apache.curator.retry.ExponentialBackoffRetry; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;/*** author heyunlin* version 1.0*/ Configuration public class ZookeeperConfig {Value(${zookeeper.host})private String host;Beanpublic CuratorFramework curatorFramework() {CuratorFramework curatorFramework CuratorFrameworkFactory.builder().connectString(host).sessionTimeoutMs(5000).retryPolicy(new ExponentialBackoffRetry(500, 5)).build();curatorFramework.start();return curatorFramework;}} 5、使用zookeeper的API package com.example.zookeeper.controller;import com.example.zookeeper.restful.JsonResult; import org.apache.curator.framework.CuratorFramework; import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.data.Stat; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController;import java.nio.charset.StandardCharsets; import java.util.List;/*** author heyunlin* version 1.0*/ RestController RequestMapping(path /zookeeper, produces application/json;charsetutf-8) public class ZookeeperController {private final CuratorFramework curatorFramework;Autowiredpublic ZookeeperController(CuratorFramework curatorFramework) {this.curatorFramework curatorFramework;}/*** 判断znode是否存在* param node 节点名称*/RequestMapping(value /exist, method RequestMethod.GET)public JsonResultStat exist(String node) throws Exception {Stat stat curatorFramework.checkExists().forPath(node);return JsonResult.success(null, stat);}/*** 创建一个znode* param node 节点名称*/RequestMapping(value /create, method RequestMethod.GET)public JsonResultVoid create(String node) throws Exception {curatorFramework.create().creatingParentContainersIfNeeded()/*创建模式常用的有PERSISTENT持久化节点客户端与zookeeper断开连接后该节点依旧存在只要不手动删除该节点就会永远存在。PERSISTENT_SEQUENTIAL持久化顺序编号目录节点客户端与zookeeper断开连接后该节点依旧存在只是zookeeper给该节点名称进行顺序编号。EPHEMERAL临时目录节点客户端与zookeeper断开连接后该节点被删除。EPHEMERAL_SEQUENTIAL临时顺序编号目录节点客户端与zookeeper断开连接后该节点被删除只是zookeeper给该节点名称进行顺序编号。*/.withMode(CreateMode.EPHEMERAL).forPath(node);return JsonResult.success(创建成功);}/*** 设置znode节点的数据* param node 节点名称* param data 节点的数据*/RequestMapping(value /setData, method RequestMethod.GET)public JsonResultVoid setData(String node, String data) throws Exception {curatorFramework.setData().forPath(node, data.getBytes(StandardCharsets.UTF_8));return JsonResult.success(设置成功);}/*** 删除节点* param node 节点名称*/RequestMapping(value /delete, method RequestMethod.GET)public JsonResultVoid delete(String node) throws Exception {curatorFramework.delete().forPath(node);return JsonResult.success(删除成功);}/*** 删除节点及其子节点的数据* param node 节点名称*/RequestMapping(value /deleteDeeply, method RequestMethod.GET)public JsonResultVoid deleteDeeply(String node) throws Exception {curatorFramework.delete().deletingChildrenIfNeeded().forPath(node);return JsonResult.success(删除成功);}/*** 获取节点的数据* param node 节点名称*/RequestMapping(value /getData, method RequestMethod.GET)public JsonResultString getData(String node) throws Exception {byte[] bytes curatorFramework.getData().forPath(node);return JsonResult.success(null, new String(bytes));}/*** 获取当前节点的子节点数据* param node 节点名称*/RequestMapping(value /getChildren, method RequestMethod.GET)public JsonResultListString getChildren(String node) throws Exception {ListString list curatorFramework.getChildren().forPath(node);return JsonResult.success(null, list);}} 好了文章就分享到这里了~
http://www.pierceye.com/news/54857/

相关文章:

  • 宠物网站的设计与实现让wordpress支持ssl
  • 云南公司网站开发网站维护服务合同
  • 网站怎么访问自己做的网页西安装修公司哪家口碑最好
  • 个人网站怎么建设规划和建设php网站开发环境论文
  • 工业设计灵感网站珠海公众号开发
  • 如何自己制作公司网站网络营销的推广工具
  • 深圳企业建站平台科技公司排名
  • 中国建设银行行号查询网站网络推广属于什么专业
  • 怎么加php网站登陆源码双井做网站的公司
  • 定制网站建设开发搜索引擎推广渠道
  • 聊城制作手机网站湖南省建设工程招标网
  • 怎么弄属于自己的网站小程序代理怎么样
  • 怎么在阿里巴巴网站做公司加强政务网站建设
  • 网站搭建模板素材哪家建设公司网站
  • 上海的招聘网站有哪些广东智唯网站建设公司
  • 企业网站建设重庆软件开发app开发
  • 做外贸在哪个网站比较好网站开发毕业设计开课题目
  • 学校部门网站的建设做资源网站违法吗
  • 做八年级题目的网站免费app制作工具
  • 成都网站开发建设推广网站开发需求统计
  • 网站建设征税标准网站首页index.html
  • 深圳 做公司网站什么网站做电子章做得好
  • 网站开发设计工程师工作前景西安高校定制网站建设
  • 免费网站后台模板下载设计杂志官网
  • 网站运营商查询wordpress案例制作
  • 佛山专业做网站公司哪家好厦门市建设区网站
  • 有个网站可以学做ppt模板如何快速做单页面网站
  • 哪个网站做餐饮推广最好建筑工程网招采
  • 网页制作与网站开发模板广州电玩网站开发
  • 新乡电子商务网站建设移动端网站开发框架