demo(一)eureka----服务注册与提供
下面写一个简单的demo验证下eureka,实现服务注册、服务发现。
一、单节点:
1、api:

封装其他组件需要共用的dto
2、eureka-service服务注册中心:

(1)pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.demo.cloud</groupId><artifactId>myspringcloud-eureka-server</artifactId><version>1.0-SNAPSHOT</version><!-- springBoot --><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.9.RELEASE</version></parent><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version><spring-cloud.version>Edgware.RELEASE</spring-cloud.version></properties><dependencies><!--eureka-server--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-eureka-server</artifactId></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><repositories><repository><id>spring-milestones</id><name>Spring Milestones</name><url>https://repo.spring.io/libs-milestone</url><snapshots><enabled>false</enabled></snapshots></repository></repositories></project>
(2)application.properties:在默认设置下,该服务注册中心也会将自己作为客户端来尝试注册它自己,所以需要禁用它的客户端注册行为
server.port=1111
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false
eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/
(3)启动类:
package com.demo.cloud;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;@SpringBootApplication
@EnableEurekaServer
public class MyEurekaServerApplication {public static void main(String args[]){SpringApplication.run(MyEurekaServerApplication.class,args);}
}
启动后,访问http://localhost:1111/:

就可以从后台监控服务了,(是不是比dubbo搭建zk注册中心方便多了) ,此时还没有服务注册过来,可以看到application下是空的。
3、eureka-client注册服务提供者:将原有的springboot工程改造,注册到eureka注册中心

(1)pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.demo.cloud</groupId><artifactId>myspringcloud-eureka-client</artifactId><version>1.0-SNAPSHOT</version><!-- springBoot --><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.9.RELEASE</version></parent><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version><spring-cloud.version>Edgware.RELEASE</spring-cloud.version></properties><dependencies><!--eureka-server--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-eureka-server</artifactId></dependency><dependency><groupId>com.demo.cloud.api</groupId><artifactId>myspringcloud-api</artifactId><version>1.0-SNAPSHOT</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- mybatis --><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>1.1.1</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.21</version></dependency><dependency><groupId>commons-collections</groupId><artifactId>commons-collections</artifactId><version>3.2.1</version></dependency><dependency><groupId>commons-lang</groupId><artifactId>commons-lang</artifactId><version>2.5</version></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><repositories><repository><id>spring-milestones</id><name>Spring Milestones</name><url>https://repo.spring.io/libs-milestone</url><snapshots><enabled>false</enabled></snapshots></repository></repositories></project>
(2)application.properties:
server.port=2222
server.context-path=/myService
spring.application.name=my-service
eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/#mybatis
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/demo?useUnicode=true&characterEncoding=utf-8&useSSL=false
spring.datasource.username=root
spring.datasource.password=wtyy
mybatis.mapper-locations=classpath*:Mapper/*Mapper.xml
(3)dao、service、Mapper:mybatis持久化部分,此处省略
(4)controller:
package com.demo.cloud.controller;import com.demo.cloud.dto.AuthorityDTO;
import com.demo.cloud.dto.UserDTO;
import com.demo.cloud.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import java.util.List;@RequestMapping("/user")
@RestController
public class UserApiController {@Autowiredprivate UserService userService;@Value("${server.port}")private String port;@RequestMapping("/findByUserName")public UserDTO findByUserName(String username){return userService.findByUserName(username);}@RequestMapping("/getAllUsers")public List<UserDTO> getAllUsers(){System.out.println(port);return userService.getAllUsers();}@RequestMapping("/getAuthortiesByUserId")public List<AuthorityDTO> getAuthortiesByUserId(Integer userId){return userService.getAuthortiesByUserId(userId);}@RequestMapping("/addUser")public void addUser1(@RequestBody UserDTO userDTO){userService.addUser(userDTO);}}
(5)启动类:
package com.demo.cloud;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;@SpringBootApplication
@EnableEurekaClient
@MapperScan("com.demo.cloud.dao")
public class MyEurekaClientApplication {public static void main(String args[]){SpringApplication.run(MyEurekaClientApplication.class,args);}
}
注意:这里使用的是@EnableEurekaClient注解,也可以使用@EnableDiscoveryClient注解,
@EnableEurekaClient是Eureka特有的注解,用于启动Eureka客户端。当使用Eureka作为注册中心时,就推荐使用@EnableEurekaClient注解,应用启动后会自动注册到Eureka Server,并完成服务治理。
@EnableDiscoveryClient是Spring Cloud通用的注解,可以与Eureka、Consul等多种注册中心对接。当我们的微服务同时需要与多个注册中心集成时,就需要使用@EnableDiscoveryClient注解。
可以说,@EnableEurekaClient是@EnableDiscoveryClient的一个具体实现,如果项目中注册中心只使用Eureka,那么使用@EnableEurekaClient更加方便和简单。但如果要切换到其他的注册中心,改动较大。
启动项目,再浏览下http://localhost:1111/:

可以看到注册成功了。
二、高可用部署:
1、先部署eukera-service的高可用
2、再部署eureka-client的高可用:连接注册中心的配置项改为多个,以逗号分隔,然后将该组件部署多个节点即可
eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/,http://xxx.xx.xxx:1111/eureka/
相关文章:
demo(一)eureka----服务注册与提供
下面写一个简单的demo验证下eureka,实现服务注册、服务发现。 一、单节点: 1、api: 封装其他组件需要共用的dto 2、eureka-service服务注册中心: (1)pom: <?xml version"1.0" encoding&q…...
core dump(介绍,status中的core dump标志,应用--调试),ulimit命令
目录 core dump(核心转储) 引入 介绍 core dump标志 引入 介绍 应用 -- gdb调试 注意点 ulimit命令 -a -c 示例 -- core file大小问题 core dump(核心转储) 引入 我们可以看到,不同的signal对应不同的编号和action:其中action主要分为term和coreterm就是终止的意…...
使用键盘管理器更改键盘快捷键,让键盘真正迎合你的使用习惯
如果默认快捷键不适合你,你肯定会想知道如何在Windows 11中更改键盘快捷键。 也许你已经习惯了macOS键盘,或者像我一样在Windows和Mac之间切换工作/游戏——如果是这样的话,重新配置默认的Windows快捷方式,使其与Mac上的快捷方式…...
putty保存登录账号和密码
putty作为一个免费的远程登录连接工具,其功能和性能还是很不错的,但是有一个很明显的缺点,就是无法保存用户名和密码。 在这里就针对这个问题,分享一种能够快速保存用户名和密码的方法。 1,创建一个桌面快捷方式。 …...
GRS认证是什么认证为何如此重要
在全球化日益盛行的今天,环保和可持续性成为了企业发展的关键词。其中,GRS认证作为企业实现可持续生产和全球环境保护的一个重要手段,越来越受到人们的关注。那么,GRS认证究竟是什么认证呢? GRS,全称为Global Rec…...
基于pytest-bdd的项目目录结构和命名规范
pytest-bdd 的文件的命名规范 pytest-bdd 是基于pytest 之上,所以需要遵循pytest 的命名规则才能进行测试,具体有: 测试文件名必须以*test.py或者test*.py命名测试函数必须以 test_开头 在pytest-bdd中存在两类文件: 以 .feat…...
web前端开发网页设计课堂作业/html练习《课程表》
目标图: 代码解析: 代码解析1<table border"3" align"center"><输入内容(的) 边界"3px" 位置"居中">2<tr><td colspan"7" align"center">课程表</td><t…...
用欧拉路径判断图同构推出reverse合法性:1116T4
http://cplusoj.com/d/senior/p/SS231116D 假设我们要把 a a a 变成 b b b,我们在 a i a_i ai 和 a i 1 a_{i1} ai1 之间连边, b b b 同理,则 a a a 能变成 b b b 的充要条件是两图 A , B A,B A,B 同构。 必要性显然࿰…...
高阶数据结构---树状数组
文章目录 楼兰图腾一个简单的整数问题 一个简单的整数问题2谜一样的牛 一、楼兰图腾OJ链接 二、一个简单的整数问题OJ链接 三、一个简单的整数问题2OJ链接 四、谜一样的牛OJ链接...
如何保护PayPal账户安全:防止多个PayPal账号关联?
PayPal是一家全球领先的在线支付平台,已经成为全球最受欢迎的在线支付工具之一,广泛应用于电子商务、跨境交易和个人之间的付款,很多跨境卖家的支付平台都会选择PayPal。PayPal支持全球多个国家和20多种货币在线支付,并且能即时收…...
关于 Spring :松耦合、可配置、IOC、AOP
关于 Spring :松耦合、可配置、IOC、AOP 文章目录 关于 Spring :松耦合、可配置、IOC、AOP一、关于 Spring1、概述2、Spring 的“松耦合”体现在哪3、Spring 的“可配置”体现在哪4、Spring 的 IOC 容器的主要作用5、Spring 的 AOP 容器的主要作用 一、关…...
pytorch tensor数据类型转换为python数据
一、item() input: x torch.tensor([1.0]) x.item()output: 1.0二、tolist() input: a torch.randn(2, 2) a.tolist() a[0,0].tolist()output: [[0.012766935862600803, 0.5415473580360413],[-0.08909505605697632, 0.7729271650314331]]0.012766935862600803...
HarmonyOS开发:动态共享包的依赖问题
一、共享包的依赖方式 在需要依赖的模块包目录下oh-package.json5文件中添加依赖: "dependencies": {"ohos/srpaasUI": "file:../../srpaasUI","ohos/srbusiness": "file:../../feature/srbusiness"} 引入之后…...
中睿天下加入中关村华安关键信息基础设施安全保护联盟
近日,中睿天下正式加入中关村华安关键信息基础设施安全保护联盟,成为其会员单位。 中关村华安关键信息基础设施安全保护联盟是由北京市科学技术委员会、中关村科技园区管理委员会指导支持,经北京市民政局批准,于2023年8月正式注册…...
【c++STL算数仿函数,关系仿函数,逻辑仿函数】
文章目录 C STL中的算数、关系和逻辑仿函数1. 算数仿函数2. 关系仿函数3. 逻辑仿函数 C STL中的算数、关系和逻辑仿函数 STL(Standard Template Library)是C标准库的一部分,提供了许多强大的工具和功能,其中包括仿函数࿰…...
产品经理的能力模型是什么?
一个产品的成功需要团队成员利用自己的技能共同合作完成。作为团队的核心和产品的主导者,产品经理需要具备一定的能力模型,以更好地完成工作。下面从五个方面进行解答。 首先,产品经理需要具备需求分析的能力。需求是用户在特定场景下产生的欲…...
缓存和DB一致性
读操作,一般是先查询缓存,查询不到再查询数据库,最后回写进缓存。 写操作,究竟是先删除(更新)缓存,再更新数据库,还是先更新数据库,再删除(更新)缓存呢? 1、给缓存设置过期时间 适用…...
netty websockt之断连重试
断连重试有以下两点考虑: 1、连接异常,比如网络抖动导致连接失败; 2、连接过程中断开连接重试; 主要用到两个工具类: ChannelFutureListener监听ChannelFuture..isSuccess(); ChannelInboundHandlerAd…...
【Gateway】基于ruoyi-cloud-plus项目,gateway局部过滤器和过滤返回以及集成nacos
1.使用Gateway路由转发 1.1标题引入依赖 <dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-gateway</artifactId></dependency>1.2添加YML配置 spring:cloud:gateway:# 打印请求日志(自定义)…...
mysql -mmm
MMM(Master-Master replication manager for MvSQL,MySQL主主复制管理器) 是一套支持双主故障切换和双主日常管理的脚本程序。MMM 使用 Perl 语言开发,主要用来监控和管理 MySQL Master-Master (双主)复制&…...
线程同步:确保多线程程序的安全与高效!
全文目录: 开篇语前序前言第一部分:线程同步的概念与问题1.1 线程同步的概念1.2 线程同步的问题1.3 线程同步的解决方案 第二部分:synchronized关键字的使用2.1 使用 synchronized修饰方法2.2 使用 synchronized修饰代码块 第三部分ÿ…...
淘宝扭蛋机小程序系统开发:打造互动性强的购物平台
淘宝扭蛋机小程序系统的开发,旨在打造一个互动性强的购物平台,让用户在购物的同时,能够享受到更多的乐趣和惊喜。 淘宝扭蛋机小程序系统拥有丰富的互动功能。用户可以通过虚拟摇杆操作扭蛋机,实现旋转、抽拉等动作,增…...
[论文阅读]TrustRAG: Enhancing Robustness and Trustworthiness in RAG
TrustRAG: Enhancing Robustness and Trustworthiness in RAG [2501.00879] TrustRAG: Enhancing Robustness and Trustworthiness in Retrieval-Augmented Generation 代码:HuichiZhou/TrustRAG: Code for "TrustRAG: Enhancing Robustness and Trustworthin…...
Visual Studio Code 扩展
Visual Studio Code 扩展 change-case 大小写转换EmmyLua for VSCode 调试插件Bookmarks 书签 change-case 大小写转换 https://marketplace.visualstudio.com/items?itemNamewmaurer.change-case 选中单词后,命令 changeCase.commands 可预览转换效果 EmmyLua…...
小智AI+MCP
什么是小智AI和MCP 如果还不清楚的先看往期文章 手搓小智AI聊天机器人 MCP 深度解析:AI 的USB接口 如何使用小智MCP 1.刷支持mcp的小智固件 2.下载官方MCP的示例代码 Github:https://github.com/78/mcp-calculator 安这个步骤执行 其中MCP_ENDPOI…...
【Java多线程从青铜到王者】单例设计模式(八)
wait和sleep的区别 我们的wait也是提供了一个还有超时时间的版本,sleep也是可以指定时间的,也就是说时间一到就会解除阻塞,继续执行 wait和sleep都能被提前唤醒(虽然时间还没有到也可以提前唤醒),wait能被notify提前唤醒…...
HTML中各种标签的作用
一、HTML文件主要标签结构及说明 1. <!DOCTYPE html> 作用:声明文档类型,告知浏览器这是 HTML5 文档。 必须:是。 2. <html lang“zh”>. </html> 作用:包裹整个网页内容,lang"z…...
当下AI智能硬件方案浅谈
背景: 现在大模型出来以后,打破了常规的机械式的对话,人机对话变得更聪明一点。 对话用到的技术主要是实时音视频,简称为RTC。下游硬件厂商一般都不会去自己开发音视频技术,开发自己的大模型。商用方案多见为字节、百…...
二维数组 行列混淆区分 js
二维数组定义 行 row:是“横着的一整行” 列 column:是“竖着的一整列” 在 JavaScript 里访问二维数组 grid[i][j] 表示 第i行第j列的元素 let grid [[1, 2, 3], // 第0行[4, 5, 6], // 第1行[7, 8, 9] // 第2行 ];// grid[i][j] 表示 第i行第j列的…...
【仿生机器人】刀剑神域——爱丽丝苏醒计划,需求文档
仿生机器人"爱丽丝"系统架构设计需求文档 一、硬件基础 已完成头部和颈部硬件搭建 25个舵机驱动表情系统 颈部旋转功能 眼部摄像头(视觉输入) 麦克风阵列(听觉输入) 颈部发声装置(语音输出)…...
