Cloud+Consul

Cloud整合Zookeeper代替Eureka-CSDN博客

Consul简介

Consul是一套开源的分布式服务发现和配置管理系统

What is Consul? | Consul | HashiCorp DeveloperConsul is a service networking solution that delivers service discovery, service mesh, and network security capabilities. It supports multi-cloud infrastructure by automating connectivity between cloud providers. Learn how Consul can help you scale operations and provide high availability across your network.icon-default.png?t=N7T8https://www.consul.io/intro/index.html

  由HashiCorp公司用Go语言开发

提供了微服务系统中的服务治理,配置中心,控制总线等功能,这些功能中的每一个都可以根据需要单独使用,也可以一起使用以构建全方位的服务网格,总之Consul提供了一种完整的服务网格解决方案.

如果没有Alibaba的Nacos  那么Consul ..........学话

基于raft(是一种用于实现分布式系统中的一致性算法,它是为了易于理解和实现而设计的)协议,比较简洁,支持健康检查,同时支持HTTP和DNS协议,支持跨数据中心的wan集群,提供图形界面,跨平台,支持Linux,Mac,Window  

Spring Cloud中文网-官方文档中文版

Spring Cloud Consul 中文文档 参考手册 中文版

Consul安装

Install | Consul | HashiCorp Developer

uname -m

打开您的 Linux 终端或控制台,输入以上任何一个命令,然后按下回车键,就可以看到您的系统架构信息。如果您看到的是 x86_64、i686 或 i386,那么您的系统是基于 AMD 或 Intel 的 x86 架构。如果您看到的是 arm、arm64、aarch64 等,那么您的系统是基于 ARM 架构

yum install -y yum-utils
yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
yum -y install consul

which consul


nohup consul agent -dev -ui -node=consul-dev -client=122.22.222.222 &
 

注意后面是内网ip

先这么玩着 

启动后

IP:8500

支付模块(生产者)

 控制器

@RestController
@Slf4j
public class PaymentController {@Value("${server.port}")private String serverPort;@GetMapping(value = "/payment/consul")public String paymentConsul(){return "springcloud with consul: "+serverPort+"\t"+ UUID.randomUUID().toString();}
}

启动类 @EnableDiscoveryClient可以不加

application.yml

server:port: 8086spring:application:name: consul-provider-paymentcloud:consul:host: 2222.222.222.22port: 8500discovery:service-name: ${spring.application.name}# 打开心跳机制 不然前面带红Xheartbeat:enabled: true

pom.xml

<?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"><parent><artifactId>SpringCloud</artifactId><groupId>org.example</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>cloud-provider-payment8086</artifactId><properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target></properties><dependencies><!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-consul-discovery --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-consul-discovery</artifactId></dependency><dependency><groupId>org.example</groupId><artifactId>cloud-api-commons</artifactId><version>1.0-SNAPSHOT</version></dependency><!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-devtools --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><scope>runtime</scope><optional>true</optional></dependency><!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies></project>

订单模块(消费者)

配置类

@Configuration
public class ApplicationContextConfig {@LoadBalanced@Beanpublic RestTemplate getRestTemplate(){return new RestTemplate();}}

业务类

@RestController
@Slf4j
public class OrderConsulController {public static final String INVOME_URL = "http://consul-provider-payment";@Resourceprivate RestTemplate restTemplate;@GetMapping("/consumer/payment/consul")public String payment (){String result = restTemplate.getForObject(INVOME_URL+"/payment/consul",String.class);return result;}}

启动类

@SpringBootApplication
//@EnableDiscoveryClient//老版本需要  新版不用
public class OrderMain80 {public static void main(String[] args) {SpringApplication.run(OrderMain80.class, args);}
}

application.yml

server:port: 80spring:application:name: consul-consumer-ordercloud:consul:host: 222.222.22.2port: 8500discovery:service-name: ${spring.application.name}# 打开心跳机制 不然前面带红Xheartbeat:enabled: true

pom.xml

<?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"><parent><artifactId>SpringCloud</artifactId><groupId>org.example</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>cloud-consumerconsul-order80</artifactId><properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target></properties><dependencies><!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-consul-discovery --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-consul-discovery</artifactId></dependency><dependency><groupId>org.example</groupId><artifactId>cloud-api-commons</artifactId><version>1.0-SNAPSHOT</version></dependency><!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-devtools --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><scope>runtime</scope><optional>true</optional></dependency><!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies></project>

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

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

相关文章

Redis中的RDB和AOF持久化机制(一)

Redis持久化 RDB快照(snapshot). 在默认情况下&#xff0c;Redis将内存数据库快照保存在名字为dump.rdb的二进制文件中.Redis可以进行设置,让它在"N秒内数据集至少有M个改动"这一条件被满足时&#xff0c;自动保存一次数据集。比如说&#xff0c;以下设置会让Redis…

TypeScript常见面试题第一节

题目一&#xff1a;是否了解TypeScript&#xff1f;TypeScript比JavaScript 有哪些优势&#xff1f; 一、讲解视频 CSDN视频&#xff1a; TS面试题一&#xff1a;介绍TS及TS的优势&#xff1f; B站视频&#xff1a; TS面试题一&#xff1a;介绍TS及TS的优势&#xff1f; 二、…

关于Spark中OptimizeShuffleWithLocalRead 中自己的一些理解

背景 本文基于 Spark 3.5 关于ShuffleLocalRead的作用简单的来说&#xff0c;就是会按照一定的规则&#xff0c;从一个 map Task 中连续读取多个 reduce数据 的任务&#xff0c;&#xff08;正常的情况下是读取所有map Task中特定的一个reduce数据任务&#xff09;&#xff0c…

Effective C++ 学习笔记 条款13 以对象管理资源

假设我们使用一个用来塑模投资行为&#xff08;如股票、债券等等&#xff09;的程序库&#xff0c;其中各式各样的投资类型继承自一个root class Investment&#xff1a; class Investment { /* ... */ }; // “投资类型”继承体系中的root class进一步假设&#xff0c;这个…

机器视觉 /从bottle.hdev示例程序开启HalconHDevelop征程

文章目录 概述示例程序bottle.hdev源码Step 0: PreparationsStep 1: Segmentation - 读取并显示图片Step 1: Segmentation - 创建并设置OCR模型Step 1: Segmentation - 文本分割与识别计算结果显示内存释放 导出为C代码导出为C代码配置 VS Halcon 环境VS程序执行结果HTuple hv…

LeetCode刷题---填充每个节点的下一个右侧节点指针

官方题解:LeetCode官方题解 解题思想: 因为是一棵满二叉树&#xff0c;所以除了叶子节点外的其他节点都有两个子节点。 可以根据每一层来依次遍历 从根节点开始&#xff0c;根节点的左子节点的next节点就指向根节点的右子节点 因为根节点的next节点为NULL&#xff0c;开始从根…

centOS7操作系统安装说明

一、安装前准备 在安装CentOS 7之前&#xff0c;确保你已经下载了CentOS 7的ISO镜像文件。你可以从CentOS官网下载&#xff1a;The CentOS Project 1. 安装环境准备 确保你的计算机满足CentOS 7的最低系统要求。CentOS 7支持的最低系统要求如下&#xff1a; x86-64或x86架构…

DR模式下LVS负载均衡聚集部署实验

目录 1、实验准备 2、配置负载调度器&#xff08;ens33&#xff1a;192.168.80.9 VIP:192.168.80.188&#xff09; 2.1 配置虚拟ip地址&#xff08;VIP&#xff1a;192.168.80.188&#xff09; 2.2 调整proc响应参数 2.3 设置负载分配策略 3、部署共享存储&#xff08;NF…

LeetCode1394. Find Lucky Integer in an Array

文章目录 一、题目二、题解 一、题目 Given an array of integers arr, a lucky integer is an integer that has a frequency in the array equal to its value. Return the largest lucky integer in the array. If there is no lucky integer return -1. Example 1: Inp…

【算法可视化】搜索算法专题

运行平台 Algorithm Visualizer 选数 [NOIP2002 普及组] 选数 // 导入可视化库 { const { Tracer, Array1DTracer, LogTracer, Layout, VerticalLayout } require(algorithm-visualizer); // }const N 4, K 3; //从包含4个元素的集合中选出3个数 let ans 0 //方案数 co…

static详解

前言 大家好我是jiantaoyab&#xff0c;这篇文章来谈一谈c中的static&#xff0c;根据对static的使用&#xff0c;我分为类内和类外2种情况 static简介 static是c常用的修饰符&#xff0c;它用来控制变量的存储方式和可见性&#xff0c;在变量前面加上一个static&#xff0c…

代码随想录算法训练营第五十二天 300.最长递增子序列 、674. 最长连续递增序列 、718. 最长重复子数组

代码随想录算法训练营第五十二天 | 300.最长递增子序列 、674. 最长连续递增序列 、718. 最长重复子数组 300.最长递增子序列 题目链接&#xff1a;300. 最长递增子序列 - 力扣&#xff08;LeetCode&#xff09; class Solution {public int lengthOfLIS(int[] nums) {int l…

ECMAScript 语法

ECMAScript 语法 一、ECMAScript1.ECMAScript简介2.ECMAScript历史 二、ECMAScript 语法区分大小写变量是弱类型的每行结尾的分号可有可无注释与 Java、C 和 PHP 语言的注释相同括号表示代码块 一、ECMAScript ECMAScript是一种由Ecma国际&#xff08;前身为欧洲计算机制造商协…

大唐杯学习笔记:Day6

1.1小区选择 一、概述 1.UE在RRC_IDLE和RRC——INACTIVATE状态下进行的过程&#xff1b; 2.UE首先需要完成PLMN的选择,在已选择的PLMN上寻找合适的小区,获取合适的服务,监听控制信道,这个过程即小区选择过程&#xff1b; 3.根据小区重选准则,UE寻找其他更适合的小区进行小区…

论文《Exploring CLIP for Assessing the Look and Feel of Images》阅读

论文《Exploring CLIP for Assessing the Look and Feel of Images》阅读 论文概述Preliminary方法论Experiments结论 论文概述 今天带来的是论文《Exploring CLIP for Assessing the Look and Feel of Images》&#xff0c;论文主要通过 CLIP 模型来完成图像的质量&#xff0…

js五星评价的制作方法

方法有两种&#xff0c;1、jquer插件&#xff1b;2、图片循环&#xff1b; 第一种、效果图 代码 <!DOCTYPE html> <html lang"zh"> <head><meta charset"UTF-8"><meta http-equiv"X-UA-Compatible" content"…

装饰器模式详解

8.9.6 装饰器模式 ​ 装饰器模式是一种结构型模式&#xff0c;主要是给一个类添加更多功能&#xff1b; 示例代码&#xff1a; #include <iostream> #include <string>// 抽象基类&#xff1a;文本修饰器 class TextDecorator { public:virtual std::string dec…

软件中级设计师——计算机系统知识

前言 计算机系统知识点&#xff08;第一章&#xff09;。 文章目录 前言一、计算机系统1、CPU2、运算器3、控制器 一、计算机系统 1、CPU 主要由控制器和运算器组成&#xff1b; 控制器 功能 程序控制&#xff1b;操作控制&#xff1b;时间控制&#xff1b; 运算器 功能 数据…

自定义过滤器实现对请求报文统一解密对响应加密

工作中经常会遇到这样的情况,前端(Android或vue等)跟后台通讯时需要对报文做加密和签名处理,但是后端微服务之间调用是明文,这种情况可以考虑通过自定义过滤器的方式实现。 前端在请求头里增加特定字段表示是前端请求,报文是否需要加密,后端自定义过滤器获取请求时根据请…

一文了解 ArrayList 的扩容机制

了解 ArrayList 在 Java 中常用集合类之间的关系如下图所示&#xff1a; 从图中可以看出 ArrayList 是实现了 List 接口&#xff0c;并是一个可扩容数组&#xff08;动态数组&#xff09;&#xff0c;它的内部是基于数组实现的。它的源码定义如下&#xff1a; public class A…